public class TheMainActivity { @Rule public ActivityTestRule<MainActivity> activityTestRule = new ActivityTestRule<MainActivity>(MainActivity.class,false,false) { @OverrIDe protected voID afteractivityLaunched() { onWebVIEw().forceJavaScriptEnabled(); } }; @Test public voID theIntroductionShouldShow() { activityTestRule.launchActivity(null); onWebVIEw().check(webMatches(getText(),containsstring("SURVIVAL ACTIONS"))); }}
关于这个文档 – 但我得到:
androID.support.test.espresso.NoMatchingVIEwException: No vIEws in hIErarchy found matching: WebVIEw with Js enabledVIEw HIErarchy:+>DecorVIEw{ID=-1,visibility=VISIBLE,wIDth=1080,height=1776,has-focus=true,has-focusable=true,has-window-focus=true,is-clickable=false,is-enabled=true,is-focused=false,is-focusable=false,is-layout-requested=false,is-selected=false,root-is-layout-requested=false,has-input-connection=false,x=0.0,y=0.0,child-count=1}|+->linearLayout{ID=-1,child-count=2}|+-->VIEwStub{ID=16909140,visibility=GONE,wIDth=0,height=0,has-focus=false,has-focusable=false,is-layout-requested=true,y=0.0}|+-->FrameLayout{ID=-1,height=1701,y=75.0,child-count=1}|+--->ActionbarOverlayLayout{ID=2131492956,res-name=decor_content_parent,child-count=2}|+---->ContentFrameLayout{ID=16908290,res-name=content,height=1533,y=168.0,child-count=2}|+----->DrawerLayout{ID=2131492973,res-name=drawer_layout,is-focusable=true,child-count=2}|+------>CoordinatorLayout{ID=-1,child-count=1}|+------->WebVIEw{ID=2131492974,res-name=webVIEw,is-clickable=true,is-focused=true,has-input-connection=true,editor-info=[inputType=0x0 imeOptions=0x0 privateImeOptions=null actionLabel=null actionID=0 initialSelStart=0 initialSelEnd=0 initialCapsMode=0x0 hintText=null label=null packagename=null fIEldID=0 fIEldname=null extras=null ],child-count=0}|+------>NavigationVIEw{ID=2131492975,res-name=navigationVIEw,visibility=INVISIBLE,wIDth=840,x=-840.0,child-count=1}|+------->NavigationMenuVIEw{ID=2131492981,res-name=design_navigation_vIEw,child-count=12}|+-------->linearLayout{ID=2131492980,res-name=navigation_header_container,height=24,child-count=0}|+-------->NavigationMenuItemVIEw{ID=-1,height=144,y=24.0,child-count=2}|+--------->AppCompatCheckedTextVIEw{ID=2131492982,res-name=design_menu_item_text,wIDth=744,x=48.0,text=Introduction,input-type=0,ime-target=false,has-links=false,is-checked=false}|+--------->VIEwStub{ID=2131492983,y=0.0}|+-------->NavigationMenuItemVIEw{ID=-1,text=Psychology,y=312.0,text=Planning and Kits,y=456.0,text=Basic Medicine,y=600.0,text=Shelter,y=744.0,text=Water,y=888.0,text=Fire,y=1032.0,text=Food,y=1176.0,text=Plants,y=1320.0,text=Poisonous Plants,y=1464.0,text=Animals,y=0.0}|+----->SnackbarLayout{ID=-1,y=1400.2982,child-count=2}|+------>AppCompatTextVIEw{ID=2131492978,res-name=snackbar_text,wIDth=826,height=141,x=36.0,y=1.0,text=like?,has-links=false}|+------>AppCompatbutton{ID=2131492979,res-name=snackbar_action,wIDth=182,x=862.0,text=Rate!,has-links=false}|+---->ActionbarContainer{ID=2131492957,res-name=action_bar_container,height=168,child-count=2}|+----->Toolbar{ID=2131492958,res-name=action_bar,child-count=4}|+------>AppCompatTextVIEw{ID=-1,wIDth=431,height=81,x=216.0,y=12.0,text=Survival Manual,has-links=false}|+------>AppCompatimagebutton{ID=-1,desc=open,wIDth=168,y=0.0}|+------>AppCompatTextVIEw{ID=-1,wIDth=259,height=63,y=93.0,has-links=false}|+------>ActionMenuVIEw{ID=-1,wIDth=144,x=936.0,child-count=1}|+------->ActionMenuItemVIEw{ID=2131492999,res-name=menu_help,desc=Introduction,text=,has-links=false}|+----->ActionbarContextVIEw{ID=2131492959,res-name=action_context_bar,child-count=0}|at dalvik.system.VMStack.getThreadStackTrace(Native Method)at java.lang.Thread.getStackTrace(Thread.java:591)at androID.support.test.espresso.base.DefaultFailureHandler.getUserFrIEndlyError(DefaultFailureHandler.java:92)at androID.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56)at androID.support.test.espresso.VIEwInteraction.runSynchronouslyOnUiThread(VIEwInteraction.java:184)at androID.support.test.espresso.VIEwInteraction.doPerform(VIEwInteraction.java:115)at androID.support.test.espresso.VIEwInteraction.perform(VIEwInteraction.java:87)at androID.support.test.espresso.web.sugar.Web$WebInteraction.forceJavaScriptEnabled(Web.java:136)at org.ligi.survivalmanual.TheSurvivalActivity.afteractivityLaunched(TheSurvivalActivity.java:19)at androID.support.test.rule.ActivityTestRule.launchActivity(ActivityTestRule.java:225)at org.ligi.survivalmanual.TheSurvivalActivity.theIntroductionShouldShow(TheSurvivalActivity.java:25)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:511)at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at androID.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)at androID.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)at org.junit.rules.RunRules.evaluate(RunRules.java:20)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.junit.runners.BlockJUnit4ClassRunner.runchild(BlockJUnit4ClassRunner.java:78)at org.junit.runners.BlockJUnit4ClassRunner.runchild(BlockJUnit4ClassRunner.java:57)at org.junit.runners.ParentRunner.run(ParentRunner.java:290)at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runchildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.accessjava.lang.RuntimeException: java.lang.RuntimeException: Error in evaluationEvaluation: status: 13 value: {message=Assertion Failed: Node cannot be null or undefined.} hasMessage: true message: Assertion Failed: Node cannot be null or undefined.at androID.support.test.espresso.web.sugar.Web$WebInteraction$ExceptionPropagator.<init>(Web.java:323)at androID.support.test.espresso.web.sugar.Web$WebInteraction.doEval(Web.java:292)at androID.support.test.espresso.web.sugar.Web$WebInteraction.check(Web.java:273)at org.ligi.survivalmanual.TheSurvivalActivity.theIntroductionShouldShow(TheSurvivalActivity.java:26)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:511)at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at androID.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)at androID.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)at org.junit.rules.RunRules.evaluate(RunRules.java:20)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.junit.runners.BlockJUnit4ClassRunner.runchild(BlockJUnit4ClassRunner.java:78)at org.junit.runners.BlockJUnit4ClassRunner.runchild(BlockJUnit4ClassRunner.java:57)0(ParentRunner.java:58)at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.junit.runners.Suite.runchild(Suite.java:128)at org.junit.runners.Suite.runchild(Suite.java:27)at org.junit.runners.ParentRunner.run(ParentRunner.java:290)at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runchildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access0(ParentRunner.java:58)at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at org.junit.runner.JUnitCore.run(JUnitCore.java:115)at androID.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)at androID.support.test.runner.AndroIDJUnitRunner.onStart(AndroIDJUnitRunner.java:262)at androID.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)Tests ran to completion.
有趣的是,当我在MainActivity中设置启用JavaScript时(尽管我不希望这样,而forceJavaScriptEnabled()应该对文档进行测试)然后我这样做:
…
解决方法 onWebVIEw()方法用作视图匹配器isJavaScriptEnabled(),直到您激活它才能匹配.相反,你可以调用onWebVIEw(myMatcher)然后它应该工作. espresso文档在这里看起来有点不正确.对于您的第二条错误消息,我还没有解释.
总结以上是内存溢出为你收集整理的android – onWebView在层次结构中找不到匹配的视图:启用了JS的WebView全部内容,希望文章能够帮你解决android – onWebView在层次结构中找不到匹配的视图:启用了JS的WebView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)