In our code, we are using an external SDK to log in users (Auth0).
This SDK opens a WebView using intent with ACTION_VIEW
.
I was trying to re-write some automation tests we had in place (we used native login before this switch).
The WebView opens correctly, but when I try to interact with it using androidx.test.espresso:espresso-web
and the code onWebView().forceJavascriptEnabled()
I get the following error:
androidx.test.espresso.NoActivityResumedException: No activities in stage RESUMED. Did you forget to launch the activity. (test.getActivity() or similar)?
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:1841)
at androidx.test.espresso.base.EspressoExceptionHandler.handleSafely(EspressoExceptionHandler.java:2)
at androidx.test.espresso.base.EspressoExceptionHandler.handleSafely(EspressoExceptionHandler.java:1)
at androidx.test.espresso.base.DefaultFailureHandler$TypedFailureHandler.handle(DefaultFailureHandler.java:4)
at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:5)
at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:8)
at androidx.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:11)
at androidx.test.espresso.ViewInteraction.perform(ViewInteraction.java:8)
at androidx.test.espresso.web.sugar.Web$WebInteraction.forceJavascriptEnabled(Web.java:1)
If, instead, I don't use the forceJavascriptEnabled()
, and directly try to access the WebView with onWebView().withElement()
, I get the error:
androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: an instance of android.webkit.WebView and webView.getSettings().getJavaScriptEnabled() is <true>
View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=1080, height=2400, has-focus=false, has-focusable=false, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params={(0,0)(fillxfill) ty=BASE_APPLICATION fmt=TRANSPARENT wanim=0x1030000
fl=LAYOUT_IN_SCREEN LAYOUT_INSET_DECOR SPLIT_TOUCH HARDWARE_ACCELERATED
pfl=NO_MOVE_ANIMATION FORCE_DRAW_STATUS_BAR_BACKGROUND FIT_INSETS_CONTROLLED
bhv=DEFAULT
fitSides=}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3}
I think that, since it's opened using ACTION_VIEW
, we're outside of our testing activity (ActivityRule - composeTestRule
), and so the framework is unable to recognise that there is indeed an activity above ours, containing a WebView.
Has anyone ever faced a similar problem? How did you solve this?
🙏🏼 Many thanks!