Luc*_*tti 7 android webview gui-testing android-espresso auth0
在我们的代码中,我们使用外部 SDK 来登录用户 (Auth0)。此 SDK 使用意图打开 WebView ACTION_VIEW。
我试图重写我们已有的一些自动化测试(在此切换之前我们使用本机登录)。WebView 正确打开,但是当我尝试使用androidx.test.espresso:espresso-web代码与其交互时onWebView().forceJavascriptEnabled()
,出现以下错误:
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)
Run Code Online (Sandbox Code Playgroud)
相反,如果我不使用forceJavascriptEnabled(),并直接尝试使用 访问 WebView onWebView().withElement(),则会收到错误:
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}
Run Code Online (Sandbox Code Playgroud)
我认为,由于它是使用打开的ACTION_VIEW,所以我们超出了我们的测试活动(ActivityRule - composeTestRule),因此框架无法识别我们上面确实有一个活动,包含一个WebView。
有人遇到过类似的问题吗?你是怎么解决这个问题的?
非常感谢!
| 归档时间: |
|
| 查看次数: |
182 次 |
| 最近记录: |