Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching #5157

Open
imayank91 opened this issue Jul 1, 2019 · 4 comments

Comments

@imayank91
Copy link

imayank91 commented Jul 1, 2019

Description

This fails

onView(withText(R.string.discard_all_changes)).check(matches(isDisplayed()))

with error

androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with string from resource id: <2131886171>[discard_all_changes] value: Discard all changes?

This is actually a snack bar

Robolectric & Android Version

Robolectric: 4.3-beta-1
Android SDK 28
Android Studio 3.3.2

@zabi90
Copy link

zabi90 commented Jul 22, 2019

Hi imayank91, Did you launch your fragment with FragmentScenario.launchInContainer() method?

@imayank91
Copy link
Author

Yeah I did launch the fragment using FragmentScenario.launchInContainer()

@zabi90
Copy link

zabi90 commented Jul 22, 2019

I was facing same problem but my mistake was using simple launch() method.
My current code is

  val contactListFragment = ContactListFragment()

        FragmentScenario.launchInContainer(ContactListFragment::class.java,null, R.style.AppTheme,object: FragmentFactory(){
            override fun instantiate(classLoader: ClassLoader, className: String): Fragment {
                return contactListFragment.apply {
                    viewModel = ContactViewModel(dataBaseHelper)
                }
            }
        })

@imayank91
Copy link
Author

I am doing this . But no luck

        scenario = launchFragmentInContainer(themeResId = R.style.AppTheme)
        navController = Mockito.mock(NavController::class.java)
        scenario.onFragment {
            Navigation.setViewNavController(it.requireView(),navController)
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants