I am new to Espresso. That is why this could be more of a "should this even work or am I just doing it wrong" type of question.
But basically I have issues testing my WebView with Espresso. When I arrive to the Activity (actually Fragment) with the WebView, Espresso cannot determine that the view is idle and I get the dreaded AppNotIdleException exception. And I don't know if I am doing something wrong or should this case even work.
Here's my test basically:
@Test
public void testIncludingWebView() {
// Go to the activity we want to test. Note, tests start actually earlier.
onView(allOf(withId(R.id.action_open_activity1), isCompletelyDisplayed()))
.perform(click());
// We arrived at the right Activity.
assertEquals(Activity1.class, Utils.getCurrentActivity().getClass());
// Select an item from a GridView in the Activity that will launch the WebView.
onData(MyMatcher.withName(is("Dummy")))
.perform(click());
// We should arrive to an Activity with a Fragment. The Fragment will
// display a full screen DialogFragment that contains the WebView.
assertEquals(WebViewActivity.class, Utils.getCurrentActivity().getClass()); // <== We never assert this
// Some tests on the WebView. But these are never run.
onWebView().forceJavascriptEnabled();
onWebView().withElement(findElement(Locator.NAME, "name"))
.perform(DriverAtoms.webKeys("some text"))
.withElement(findElement(Locator.XPATH, "//button[contains(text(), 'Submit')]"))
.perform(webClick());
}
To recap: I have some Activities that I navigate to and finally I arrive to an Activity with a Fragment and this Fragment will display a full screen DialogFragment that has the WebView. When I arrive here, Espresso cannot determine the idle state.
Also very important to mention is that when I enable Developer Options -> Show screen updates I can see the screen constantly flickering on the view where I get the timeout exception meaning that the screen is updated constantly. AFAIK one of the things Espresso does for determining if the app is idle or not is to wait for the screen rendering to end. So this could be the issue.
But why would the screen update all the time? And I guess here's the beef of it; is it Chrome / WebView updating the screen all the time because of how I open the WebView or do I have some unknown animation going on that I just need to find? I tried to look for animations in the view that I can stop, but since it's just a WebView I am displaying, I haven't found anything.
So have others been able to test this kind of scenario with Espresso or not?