Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso testing on Webview within ViewPager

I have an Android Application that uses ViewPager and each Fragment in the view pager has its own WebView. I am able to write test case to check navigation on the ViewPager. But how can I test whether the div in the webview which is first child of the view pager asserts the provided string?

onWebView().withElement(findElement(Locator.ID, "desgination")).
                check(webMatches(getText(), containsString("Doctor")));

This one throws

android.support.test.espresso.AmbiguousViewMatcherException: 'WebView with JS enabled' matches multiple views in the hierarchy. Problem views are marked with '****MATCHES****' below.

like image 437
Ads Avatar asked Mar 15 '23 17:03

Ads


1 Answers

Change your code to

onWebView(Matchers.allOf(isDisplayed(), isJavascriptEnabled()))
    .withElement(findElement(Locator.ID, "desgination"))
    .check(webMatches(getText(), containsString("Doctor")));

The isDisplayed() method is needed to automatic select the one that is currently on your screen.

like image 183
Peter Fortuin Avatar answered Mar 24 '23 12:03

Peter Fortuin