java - Espresso testing NestedScrollView - "Error performing 'scroll to' on view 'with id:" -


i need scroll down through nestedscrollview in order test xml file espresso, error message: "error performing 'scroll to' on view 'with id:"

several other posts seem have similar problem.

i have followed instructions this: android espresso nestedscrollview, how scroll bottom

now forementioned error, , found post: scrolling view attempted, view not displayed

i have no padding in nestedscrollview - tried removing padding xml alltogether, testing purposes, made no difference.

this test (so far not supposed anything, scroll down):

    @test     public void testscrolldownabilityofdetailsscrollview(){         gotospecificitemonstream(streamitemwithoneimage);          onview(withid(r.id.end_of_details))                 .perform(scrolltoaction.betterscrollto());      } 

it uses custom made scroll action class:

    public final class scrolltoaction implements viewaction {      private static final string tag = scrolltoaction.class.getsimplename();      @suppresswarnings("unchecked")     @override     public matcher<view> getconstraints() {         return allof(witheffectivevisibility(visibility.visible), isdescendantofa(anyof(                 isassignablefrom(scrollview.class),    isassignablefrom(horizontalscrollview.class), isassignablefrom(nestedscrollview.class))));     }      @override     public void perform(uicontroller uicontroller, view view) {         if (isdisplayingatleast(80).matches(view)) {             log.i(tag, "view displayed. returning.");             return;         }         rect rect = new rect();         view.getdrawingrect(rect);         if (!view.requestrectangleonscreen(rect, true /* immediate */)) {             log.w(tag, "scrolling view requested, none of parents      scrolled.");         }         uicontroller.loopmainthreaduntilidle();         if (!isdisplayingatleast(80).matches(view)) {             throw new performexception.builder()                     .withactiondescription(this.getdescription())                     .withviewdescription(humanreadables.describe(view))                     .withcause(new runtimeexception(                             "scrolling view attempted, view not displayed"))                     .build();         }     }     public static viewaction betterscrollto() {         return viewactions.actionwithassertions(new scrolltoaction());     }      @override     public string getdescription() {         return "scroll to";     }} 

the custom made scrolltoaction class there because normal scrollto method hardcoded scrollview , horizontalscrollview, not nestedscrollview.

this xml file trying test:

       <?xml version="1.0" encoding="utf-8"?>        <android.support.v4.widget.nestedscrollview    xmlns:android="http://schemas.android.com/apk/res/android"         xmlns:app="http://schemas.android.com/apk/res-auto"         android:id="@+id/scrollview"         xmlns:tools="http://schemas.android.com/tools"         android:layout_width="match_parent"         android:layout_height="match_parent"         app:layout_behavior="@string/appbar_scrolling_view_behavior">          <relativelayout             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:orientation="horizontal">                <framelayout                 android:id="@+id/fl"                 android:background="#fbfbfb"                 android:layout_margin="0dp"                 android:layout_width="match_parent"                 android:layout_height="350dp">                  <android.support.v4.view.viewpager                     android:id="@+id/container"                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     app:layout_behavior="@string/appbar_scrolling_view_behavior" />                  <imageview                     android:id="@+id/location"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_margin="@dimen/text_margin"                     android:layout_gravity="left|top"                     android:background="@null"                     android:src="@drawable/ic_location_white"                     android:paddingleft="-8dp" />                   <textview                     android:id="@+id/textviewdistance"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_torightof="@id/location"                     android:textappearance="?android:attr/textappearancemedium"                     android:layout_margin="@dimen/text_margin"                     android:layout_gravity="left|top"                     android:shadowcolor="#262424"                     android:shadowdx="1"                     android:shadowdy="1"                     android:shadowradius="2"                     android:textcolor="#fbfbfb"                     android:textsize="22dp"                     android:singleline="false"                     android:paddingleft="24dp" />                   <textview                     android:id="@+id/textviewprice"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:textappearance="?android:attr/textappearancemedium"                     android:layout_margin="@dimen/text_margin"                     android:layout_gravity="right|top"                     android:shadowcolor="#262424"                     android:shadowdx="1"                     android:shadowdy="1"                     android:shadowradius="2"                     android:textcolor="#fbfbfb"                      android:textsize="22dp"/>                  <me.relex.circleindicator.circleindicator                     android:id="@+id/indicator"                     android:layout_width="match_parent"                     android:layout_height="40dp"                     android:layout_gravity="bottom"                     android:shadowcolor="#262424"                     android:shadowdx="1"                     android:shadowdy="1"                     android:shadowradius="1"/>                </framelayout>               <linearlayout                  android:layout_below="@id/fl"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:orientation="vertical"                 >                  <textview                     android:id="@+id/textviewtitle"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:gravity="left"                     android:layout_margin="@dimen/text_margin"                     android:textcolor="@color/colorchecktomblack"                     android:textstyle="bold"                     android:textsize="20dp" />                  <textview                     android:id="@+id/textviewdescription"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_marginleft="@dimen/text_margin"                     android:layout_marginright="@dimen/text_margin"                     android:gravity="left"                     android:textcolor="@color/colorchecktomblack"                     android:textsize="18dp"                     android:layout_weight="0.56" />                  <relativelayout                     android:layout_width="match_parent"                     android:layout_height="65dp"                     android:paddingtop="30dp">                       <imagebutton                         android:id="@+id/buttonwatchlist"                         android:src="@drawable/ic_checktom"                         android:background="@null"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:gravity="left"                         android:layout_marginleft="55dp"                         android:layout_marginstart="55dp"                         android:layout_alignparenttop="true"                         android:layout_alignparentleft="true"                         android:layout_alignparentstart="true"                         android:onclick="launchwatchlistactivity"                         android:paddingtop="2dp"/>                       <imagebutton                         android:id="@+id/buttonmessage"                         android:src="@drawable/ic_messages"                         android:background="@null"                         android:scalex="1.2"                         android:scaley="1.2"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_gravity="center_horizontal"                         android:layout_alignparenttop="true"                         android:layout_centerhorizontal="true"                         android:onclick="launchmessageactivity"                         android:paddingtop="7dp"/>                       <imagebutton                         android:id="@+id/buttonshare"                         android:src="@drawable/ic_share"                         android:background="@null"                         android:scalex="1.5"                         android:scaley="1.5"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_marginright="54dp"                         android:layout_marginend="54dp"                         android:layout_alignparenttop="true"                         android:layout_alignparentright="true"                         android:layout_alignparentend="true"                         android:onclick="launchshareactivity"/>                    </relativelayout>                   <relativelayout                     android:orientation="horizontal"                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:padding="2dp">                       <textview                         android:id="@+id/textviewwatchlist"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:text="watchlist"                         android:layout_marginleft="41dp"                         android:layout_marginstart="41dp"                         android:layout_alignparenttop="true"                         android:layout_alignparentleft="true"                         android:layout_alignparentstart="true" />                       <textview                         android:id="@+id/textviewmessage"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:text="message"                         android:layout_gravity="center_horizontal"                         android:layout_alignparenttop="true"                         android:layout_centerhorizontal="true" />                      <textview                         android:id="@+id/textviewshare"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:text="share"                         android:layout_gravity="center_horizontal"                         android:layout_alignparenttop="true"                         android:layout_alignparentright="true"                         android:layout_alignparentend="true"                         android:layout_marginright="52dp"                         android:layout_marginend="52dp" />                   </relativelayout>                 <linearlayout                     android:orientation="horizontal"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_gravity="center">                   <textview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:text="_________________________________________"                     android:paddingtop="25dp"/>                   </linearlayout>                  <linearlayout                     android:orientation="horizontal"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_gravity="center">                      <de.hdodenhof.circleimageview.circleimageview                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_below="@+id/imageview"                         android:layout_centerhorizontal="true"                         android:id="@+id/circleview"                         android:scalex="0.4"                         android:scaley="0.4"                         android:layout_margintop="-20dp"                         android:layout_marginbottom="-60dp"                         />                         </linearlayout>                  <linearlayout                     android:orientation="vertical"                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:layout_gravity="center">                          <linearlayout                         android:orientation="horizontal"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_gravity="center">                          <textview                         android:id="@+id/textviewsellername"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:textsize="18dp"/>                              </linearlayout>                             <linearlayout                         android:orientation="horizontal"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_gravity="center">                          <textview                         android:id="@+id/textviewsellerdestination"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:paddingbottom="20dp" />                              <textview                             android:id="@+id/end_of_details"                             android:layout_width="match_parent"                             android:layout_height="wrap_content" />                         </linearlayout>                         </linearlayout>             </linearlayout>         </relativelayout>     </android.support.v4.widget.nestedscrollview> 

when test fails, full output get:

android.support.test.espresso.performexception: error performing 'scroll to' on view 'with id: com.checktom.checktom:id/end_of_details'. @ android.support.test.espresso.performexception$builder.build(performexception.java:83) @ android.support.test.espresso.base.defaultfailurehandler.getuserfriendlyerror(defaultfailurehandler.java:80) @ android.support.test.espresso.base.defaultfailurehandler.handle(defaultfailurehandler.java:56) @ 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) @ com.checktom.checktom.applicationtest.testscrolldownabilityofdetailsscrollview(applicationtest.java:279) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:50) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:47) @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:17) @ org.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:26) @ android.support.test.internal.statement.uithreadstatement.evaluate(uithreadstatement.java:55) @ android.support.test.rule.activitytestrule$activitystatement.evaluate(activitytestrule.java:270) @ org.junit.rules.runrules.evaluate(runrules.java:20) @ org.junit.runners.parentrunner.runleaf(parentrunner.java:325) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:78) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:57) @ org.junit.runners.parentrunner$3.run(parentrunner.java:290) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288) @ org.junit.runners.parentrunner.access$000(parentrunner.java:58) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268) @ org.junit.runners.parentrunner.run(parentrunner.java:363) @ org.junit.runners.suite.runchild(suite.java:128) @ org.junit.runners.suite.runchild(suite.java:27) @ org.junit.runners.parentrunner$3.run(parentrunner.java:290) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288) @ org.junit.runners.parentrunner.access$000(parentrunner.java:58) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268) @ org.junit.runners.parentrunner.run(parentrunner.java:363) @ org.junit.runner.junitcore.run(junitcore.java:137) @ org.junit.runner.junitcore.run(junitcore.java:115) @ android.support.test.internal.runner.testexecutor.execute(testexecutor.java:59) @ android.support.test.runner.androidjunitrunner.onstart(androidjunitrunner.java:262) @ android.app.instrumentation$instrumentationthread.run(instrumentation.java:1933) caused by: java.lang.runtimeexception: scrolling view attempted, view not displayed @ com.checktom.checktom.scrolltoaction.perform(scrolltoaction.java:52) @ android.support.test.espresso.viewinteraction$1.run(viewinteraction.java:144) @ java.util.concurrent.executors$runnableadapter.call(executors.java:422) @ java.util.concurrent.futuretask.run(futuretask.java:237) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:145) @ android.app.activitythread.main(activitythread.java:6938) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1404) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1199) tests ran completion.

i can tell run runtime exception in scrolltoaction class's perform method, have yet find way solve it.

in first post linked, new betterscrollto method seemed work charm.

i did this:

onview(withid(r.id.viewtoscroll)                 .perform(nestedscrollto())                 .check(matches(isdisplayed())); 

where nestedscrollto() is:

public static viewaction nestedscrollto() {     return new viewaction() {          @override         public matcher<view> getconstraints() {             return matchers.allof(                     isdescendantofa(isassignablefrom(nestedscrollview.class)),                     witheffectivevisibility(viewmatchers.visibility.visible));         }          @override         public string getdescription() {             return "view not nestedscrollview";         }          @override         public void perform(uicontroller uicontroller, view view) {             try {                 nestedscrollview nestedscrollview = (nestedscrollview)                         findfirstparentlayoutofclass(view, nestedscrollview.class);                 if (nestedscrollview != null) {                     nestedscrollview.scrollto(0, view.gettop());                 } else {                     throw new exception("unable find nestedscrollview parent.");                 }             } catch (exception e) {                 throw new performexception.builder()                         .withactiondescription(this.getdescription())                         .withviewdescription(humanreadables.describe(view))                         .withcause(e)                         .build();             }             uicontroller.loopmainthreaduntilidle();         }      }; }  private static view findfirstparentlayoutofclass(view view, class<? extends view> parentclass) {     viewparent parent = new framelayout(view.getcontext());     viewparent incrementview = null;     int = 0;     while (parent != null && !(parent.getclass() == parentclass)) {         if (i == 0) {             parent = findparent(view);         } else {             parent = findparent(incrementview);         }         incrementview = parent;         i++;     }     return (view) parent; }  private static viewparent findparent(view view) {     return view.getparent(); }  private static viewparent findparent(viewparent view) {     return view.getparent(); } 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -