I am using Instrumentation tests to check that after a page has loaded in a WebView, certain behaviors work as expected. I currently have 3 tests which all work in this same way, i.e. wait for url to load > check the page title > do thing > check result.
The problem appears to be occur due to multiple functions calling the same onWebView().withElement(findElement(Locator.CLASS_NAME, "my_title")). The test that completes first succeeds as expected, but subsequent tests fail with the following error:
java.lang.RuntimeException: java.lang.RuntimeException: Atom evaluation returned null!
at androidx.test.espresso.web.sugar.Web$WebInteraction$ExceptionPropagator.<init>(Web.java:4)
at androidx.test.espresso.web.sugar.Web$WebInteraction.doEval(Web.java:17)
at androidx.test.espresso.web.sugar.Web$WebInteraction.withElement(Web.java:2)
I am calling reset(), which was originally missing so I assumed was the problem, however adding it has not solved the issue. See the code below:
@get:Rule var activityScenarioRule = ActivityScenarioRule(BrowserActivity::class.java)
@Test
fun page_loads_and_can_navigate_via_footer() {
onWebView()
.withElement(findElement(Locator.CLASS_NAME, "my_title"))
.withNoTimeout()
.check(webMatches(getText(), containsString("title_1")))
.withElement(findElement(Locator.ID, "footer_option_2"))
.perform(webClick())
.withElement(findElement(Locator.CLASS_NAME, "my_title"))
.check(webMatches(getText(), containsString("title_2")))
.reset()
}
@Test
fun can_refresh_cache_in_debug_mode() {
onWebView()
.withElement(findElement(Locator.CLASS_NAME, "my_title"))
.withNoTimeout()
// DO TEST
.reset()
}
@Test
fun can_change_url_in_debug_mode() {
onWebView()
.withElement(findElement(Locator.CLASS_NAME, "my_title"))
.withNoTimeout()
// DO TEST
.reset()
}
Is there anything I am missing here? Or am I perhaps doing these tests wrong somehow?