Android: Espresso does not wait until a fragment or activity is shown so that each test fails

I know there are a lot of questions around this, but I can not find anything to help me :(

I tried using Espresso to create a UI test for an Android application. After beating problems with dependencies (because some libraries are included twice in different versions depending on other libraries), I still cannot create working tests ...

I know about IdlingResource, but reading, the espresso waits out of the box until the main thread and AsyncTaskPool are idle before running any tests.

To contact him, I created a simple application containing two activities: a pop-up window and the main action. A popup window contains something like this to wait for three seconds before launching mainActivity

new Handler().postDelayed(new Runnable() { @Override public void run() { finish(); Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); startActivity(intent); } }, 3000); 

I also tried using AsyncTask for this, but nothing works correctly, because each test fails.

The test checks whether a TextView containing specific text is displayed in the form:

 onView(withText("DummyText")).check(matches(notNullValue())); 

I thought it would not be so difficult to create a simple test ...

Because I have to test against api> = 16 I need espresso. Only for me I tested it using uiAutomator (I know this for api> = 18), but there is such clever logic to wait for something to be shown ..... and it works fine ...

+6
source share
1 answer

What is your activity? Because if it is SplashScreenActivity, the test will start immediately and onView will fail if the view is not displayed on the splash screen. Try opening MainActivity directly to test this view. I have been using Espresso for some time, and I know that @Test methods start when an activity defined as an ActivityTestRule ends with a download.

Hope this helps.

Good luck

+5
source

All Articles