【问题标题】:Espresso testing NestedScrollView - "Error performing 'scroll to' on view 'with id:"Espresso 测试 NestedScrollView - “在视图 ' 上执行 '滚动到 ' 时出错:”
【发布时间】:2016-09-22 15:04:58
【问题描述】:

我需要向下滚动我的 NestedScrollView 才能使用 Espresso 测试我的 xml 文件,但我收到错误消息:“错误执行 'scroll to' on view 'with id:”

似乎有类似问题的其他几个帖子。

我已按照以下说明进行操作:Android espresso NestedScrollView, how to scroll to bottom

现在我得到了前面提到的错误,并找到了这个帖子:Scrolling to view was attempted, but the view is not displayed

我的 NestedScrollView 中没有填充 - 出于测试目的,我什至尝试从 XML 中删除填充,但没有任何区别。

这是我的测试(到目前为止它不应该做任何事情,但向下滚动):

    @Test
    public void testScrollDownAbilityOfDetailsScrollView(){
        goToSpecificItemOnStream(streamItemWithOneImage);

        onView(withId(R.id.end_of_details))
                .perform(ScrollToAction.betterScrollTo());

    }

它使用定制的 Scroll To Action 类:

    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 is already displayed. Returning.");
            return;
        }
        Rect rect = new Rect();
        view.getDrawingRect(rect);
        if (!view.requestRectangleOnScreen(rect, true /* immediate */)) {
            Log.w(TAG, "Scrolling to view was requested, but none of the parents      scrolled.");
        }
        uiController.loopMainThreadUntilIdle();
        if (!isDisplayingAtLeast(80).matches(view)) {
            throw new PerformException.Builder()
                    .withActionDescription(this.getDescription())
                    .withViewDescription(HumanReadables.describe(view))
                    .withCause(new RuntimeException(
                            "Scrolling to view was attempted, but the view is not displayed"))
                    .build();
        }
    }
    public static ViewAction betterScrollTo() {
        return ViewActions.actionWithAssertions(new ScrollToAction());
    }

    @Override
    public String getDescription() {
        return "scroll to";
    }}

自定义的 ScrollToAction 类存在,因为普通的 scrollTo 方法被硬编码为 ScrollView 和 Horizo​​ntalScrollView,而不是 NestedScrollView。

这是我要测试的 XML 文件:

       <?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>

当测试失败时,这是我得到的完整输出:

android.support.test.espresso.PerformException:在视图“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.testScrollDownAbilityOfDetailsS​​crollView(ApplicationTest.java:279) 在 java.lang.reflect.Method.invoke(本机方法) 在 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) 原因:java.lang.RuntimeException:尝试滚动到视图,但视图未显示 在 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(本机方法) 在 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) 测试运行完成。

我可以说我在 ScrollToAction 类的 perform 方法中遇到了运行时异常,但我还没有找到解决它的方法。

在我链接的第一篇文章中,新的 BetterScrollTo 方法似乎很有魅力。

【问题讨论】:

  • 这是其中一篇文章,我已经关注了。但是谢谢你:) 它暗示了两件事。首先,您应该创建自己的 ScrollToAction 类,我已经这样做了,第二,CoordinatorLayout 内的 NestedScrollView 可能会导致问题,但我的 NestedScrollView 不在 CoordinatorLayout 内。不过感谢您的努力!
  • 编辑:查看我的 NestedScrollView 的父母后,我发现它实际上在 CoordinatorLayout 内。不过,它不是 CoordinatorLayout 的直接子代,因此帖子中建议的 getParent() 方法对我不起作用。

标签: java android testing android-espresso nestedscrollview


【解决方案1】:

我这样做了:

onView(withId(R.id.viewToScroll)
                .perform(nestedScrollTo())
                .check(matches(isDisplayed()));

nestedScrollTo() 在哪里:

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 is 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 to 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 i = 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();
}

【讨论】:

  • 这适用于 Espresso,但不适用于 Robolectric。
【解决方案2】:

@Eric 对导入的回答是: 非常感谢埃里克 :)

import android.view.View
import android.widget.HorizontalScrollView
import android.widget.ScrollView
import androidx.core.widget.NestedScrollView
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.ScrollToAction
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.anyOf
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import org.hamcrest.Matcher


// scroll-to action that also works with NestedScrollViews
class BetterScrollToAction:ViewAction by ScrollToAction()
{
    override fun getConstraints(): Matcher<View>
    {
        return allOf(
            withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE),
            isDescendantOfA(
                anyOf(
                    isAssignableFrom(ScrollView::class.java),
                    isAssignableFrom(HorizontalScrollView::class.java),
                    isAssignableFrom(NestedScrollView::class.java)
                )
            )
        )
    }
}

// convenience method
fun betterScrollTo(): ViewAction
{
    return ViewActions.actionWithAssertions(BetterScrollToAction())
}

【讨论】:

    【解决方案3】:

    我使用了这段代码(灵感来自SO answer

    class MainMenuActivityTest
    {
        @Test
        fun textInputDialog_opens_on_button_clicked()
        {
            onView(withId(R.id.text_input_button))
                .perform(betterScrollTo())
                .perform(click())
        }
    }
    
    // scroll-to action that also works with NestedScrollViews
    class BetterScrollToAction:ViewAction by ScrollToAction()
    {
        override fun getConstraints():Matcher<View>
        {
            return allOf(
                    withEffectiveVisibility(Visibility.VISIBLE),
                    isDescendantOfA(anyOf(
                            isAssignableFrom(ScrollView::class.java),
                            isAssignableFrom(HorizontalScrollView::class.java),
                            isAssignableFrom(NestedScrollView::class.java))))
        }
    }
    
    // convenience method
    fun betterScrollTo():ViewAction
    {
        return ViewActions.actionWithAssertions(BetterScrollToAction())
    }
    

    现在可以使用了


    起初,我使用的是this answer here,但在使用以下代码进行测试时:

    class MainMenuActivityTest
    {
        @Test
        fun textInputDialog_opens_on_button_clicked()
        {
            onView(withId(R.id.text_input_button))
                .perform(betterScrollTo())
                .perform(click())
        }
    }
    

    但我遇到了以下异常...

    E/TestRunner: failed: textInputDialog_opens_on_button_clicked(com.github.ericytsang.example.app.android.MainMenuActivityTest)
    ----- begin exception -----
    E/TestRunner: androidx.test.espresso.PerformException: Error performing 'scroll to' on view 'Animations or transitions are enabled on the target device.
    For more info check: https://developer.android.com/training/testing/espresso/setup#set-up-environment
    
    with id: com.github.ericytsang.app.example.android:id/text_input_button'.
    ............
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2196)
    Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
    (view has effective visibility=VISIBLE and is descendant of a: (is assignable from class: class android.widget.ScrollView or is assignable from class: class android.widget.HorizontalScrollView or is assignable from class: class android.widget.ListView))
    Target view: "AppCompatButton{id=2131296521, res-name=text_input_button, visibility=VISIBLE, width=1008, height=107, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=androidx.appcompat.widget.LinearLayoutCompat$LayoutParams@cec11da, tag=null, root-is-layout-requested=false, has-input-connection=false, x=18.0, y=516.0, text=text input dialog, input-type=0, ime-target=false, has-links=false}"
    at androidx.test.espresso.ViewInteraction.doPerform(ViewInterac
    ----- end exception -----
    

    E/TestRunner: failed: textInputDialog_opens_on_button_clicked(com.github.ericytsang.example.app.android.MainMenuActivityTest)
    ----- begin exception -----
    E/TestRunner: androidx.test.espresso.PerformException: Error performing 'scroll to' on view 'with id: com.github.ericytsang.app.example.android:id/text_input_button'.
    ........
    Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
    (view has effective visibility=VISIBLE and is descendant of a: (is assignable from class: class android.widget.ScrollView or is assignable from class: class android.widget.HorizontalScrollView or is assignable from class: class android.widget.ListView))
    Target view: "AppCompatButton{id=2131296521, res-name=text_input_button, visibility=VISIBLE, width=1008, height=107, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=androidx.appcompat.widget.LinearLayoutCompat$LayoutParams@3e84212, tag=null, root-is-layout-requested=false, has-input-connection=false, x=18.0, y=516.0, text=text input dialog, input-type=0, ime-target=false, has-links=false}"
    at androidx.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:252)
    at androidx.test.espresso.ViewInteraction.access$100(ViewInteraction.java:65)
    at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.jav
    ----- end exception -----
    

    【讨论】:

      【解决方案4】:

      您可以使用新的 Espresso 测试记录器将嵌套滚动的代码获取到 - 查看Espresso Test Recorder

      【讨论】:

      • 不错的建议。我试过了,但不幸的是,它没有在 RecyclerView 的行上记录长按。但我可以想象在其他情况下使用您的想法。谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-07
      • 2019-07-01
      相关资源
      最近更新 更多