android - Espresso won't find View when included with androidTestCompile -


this darn strange. have activity viewpager hosts couple of of fragments, first 1 has radiobutton id android:id="@+id/backjudgeradionbutton".

i have espresso test looks this:

import android.test.activityinstrumentationtestcase2;  import model.gamesetup; import ui.setupactivity; import weigl.fm.refwatch.r;  import static android.support.test.espresso.espresso.onview; import static android.support.test.espresso.action.viewactions.click; import static android.support.test.espresso.matcher.viewmatchers.withtext;  /**  * created asco on 8/7/15.  */ public class setupactivityespressotest extends activityinstrumentationtestcase2<setupactivity> {       public setupactivityespressotest() {         super(setupactivity.class);     }       @override     protected void setup() throws exception {         super.setup();         getactivity();     }      public void testuserroleisset() {           onview(withid(r.id.backjudgeradionbutton)).perform(click());          assertequals(gamesetup.userrole.backjudge, getactivity().getgamesetup().getuserrole());      }  } 

when espresso imported in build.gradle via

compile('com.android.support.test.espresso:espresso-core:2.2') {     exclude module: 'support-annotations' }  compile('com.android.support.test:runner:0.3') {     exclude module: 'support-annotations' } compile('com.android.support.test.espresso:espresso-contrib:2.2') {     exclude module: 'support-annotations' } 

the test works fine.

when use intended variant of importing dependencies instrumentation tests:

androidtestcompile('com.android.support.test.espresso:espresso-core:2.2') {     exclude module: 'support-annotations' }  androidtestcompile('com.android.support.test:runner:0.3') {     exclude module: 'support-annotations' } androidtestcompile('com.android.support.test.espresso:espresso-contrib:2.2') {     exclude module: 'support-annotations' } 

with androidtestcompile instead of compile test fails because view provided id not found:

running tests test running started android.support.test.espresso.nomatchingviewexception: no views in hierarchy found matching: string resource id: <2131230756>  view hierarchy: +>decorview{id=-1, visibility=visible, width=280, height=280, 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, visibility=visible, width=280, height=280, 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=2} | +-->viewstub{id=16909171, visibility=gone, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0} | +-->framelayout{id=16908290, res-name=content, visibility=visible, width=280, height=280, 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, visibility=visible, width=280, height=280, 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} | +---->viewpager{id=2131558442, res-name=viewpager, visibility=visible, width=280, height=280, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=true, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0} | @ dalvik.system.vmstack.getthreadstacktrace(native method) @ java.lang.thread.getstacktrace(thread.java:580) @ android.support.test.espresso.base.defaultfailurehandler.getuserfriendlyerror(defaultfailurehandler.java:82) @ android.support.test.espresso.base.defaultfailurehandler.handle(defaultfailurehandler.java:53) @ android.support.test.espresso.viewinteraction.runsynchronouslyonuithread(viewinteraction.java:184) @ android.support.test.espresso.viewinteraction.doperform(viewinteraction.java:115) @ android.support.test.espresso.viewinteraction.perform(viewinteraction.java:87) @ setupactivityespressotest.testuserroleisset(setupactivityespressotest.java:30) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) 

it seems espresso checks views in activity's layout, not ones provided viewpager.

a. how comes test works when using compile instead of androidtestcompile?

b. espresso supposed find views within fragments inside viewpager?

edit: second variant of espresso test tried, taken the new android testing template:

@runwith(androidjunit4.class) @largetest public class setupactivitytest {       @rule     public activitytestrule<setupactivity> mactivityrule =             new activitytestrule<>(setupactivity.class);      @test     public void findviewperformactionandcheckassertion() {         // find button , click on         onview(withid(r.id.backjudgeradionbutton)).perform(click());      }  } 

it shows same effect.

this happening inside wear module if matters.

edit2: can have @ whole project on github.

the reason think happening this: 1 of dependencies of espresso library (my bets on 1 of support libraries) dependency on wearable ui library (com.google.android.support:wearable). version of dependency library on espresso newer 1 in wearable. if include espresso 'compile' dependency, newer version of library used , well. when use 'androidtestcompile' dependency, older version used build app.

i'd suggest have see if there's later version of wearable ui library (which should have latest dependencies) or, figure out dependency , latest version (and exclude espresso , wearable ui lib).


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

php - How do you embed a video into a custom theme on WordPress? -