エスプレッソでxmlファイルをテストするためにNestedScrollViewをスクロールダウンする必要がありますが、エラーメッセージ ' id: "エスプレッソテストNestedScrollView - id: "
他にも同様の問題があると思われる記事をスクロールして表示します。
私はこれからの指示に従っている:Android espresso NestedScrollView, how to scroll to bottom
は、今私はforementionedエラーを取得し、この記事を見つけました:Scrolling to view was attempted, but the view is not displayed
私は私のNestedScrollViewにはパディングを持っていない - 私もalltogether XMLからのパディングを削除しようとしましたテスト目的のために、しかしそれは違いをもたらさなかった。
これは私のテスト(これまでのところ、何かを行うことになってますが、スクロールダウンしていない)である。
@Test
public void testScrollDownAbilityOfDetailsScrollView(){
goToSpecificItemOnStream(streamItemWithOneImage);
onView(withId(R.id.end_of_details))
.perform(ScrollToAction.betterScrollTo());
}
これは、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";
}}
カスタム通常のscrollToメソッドはScrollViewおよびHorizontalScrollViewにハードコードされていますが、NestedScrollViewにはハードコードされていないため、作成されたScrollToActionクラスがあります。
android.support.test.espresso:テストが失敗したとき
<?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>
が、これは私が手にフル出力されます:
これは、私がテストしようとしているXMLファイルです。 PerformException:ID:com.checktom.checktom:id/end_of_details 'を使用して'ビュー '上の' scroll to 'を実行しているときにエラーが発生しました。 android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:80) (android.support.test.espresso.PerformException)の は、android.supportの にあります。 (android.support.test.espresso.ViewInteraction.doPerform()) com.checktom.checktom.ApplicationTest.testScrollDownAbilityOfDetailsScrollView(ApplicationTest.java:279)されるjava.langにおける でandroid.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87) でViewInteraction.java:115) 。インボークメソッド(ネイティブメソッド) java.lang.reflect.Method.invoke(Method.java:372) at org.junit.runners.model.FrameworkMethod $ 1.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 org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) (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) 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) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58) at org .junit.runners.ParentRunner $ 2.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 $ 3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access $ 000 ParentRunner.java:58) at org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner android.support.test.internal.runner.TestExecutor.executeでorg.junit.runner.JUnitCore.run(JUnitCore.java:115) で.JUnitCore.run(JUnitCore.java:137) (TestExecutor.java:59 ) android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262) android.app.Instrumentation $ InstrumentationThread.run(Instrumentation.ja) va:1933) 原因:java.lang.RuntimeException:ビューへのスクロールが試みられましたが、ビューが表示されません。 at 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)) at android.os.Looper.loop(Looper.java:145) ) android.app.ActivityThread.main(ActivityThread.java:6938) at 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メソッドが魅力的なように見えました。
試み:
nestedScrollTo()
があるをこれはhttp://stackoverflow.com/questions/35272953/espresso-scrolling-not-working-when-nestedscrollview-or-recyclerview-is-in-coor –
その私がすでに従っている投稿の1つです。しかし、ありがとう:) それは2つのことを示唆しています。まず、独自のScrollToActionクラスを作成する必要があります.2つは、CoordinatorLayout内のNestedScrollViewが問題を引き起こす可能性がありますが、NestedScrollViewはCoordinatorLayout内にありません。 ご協力いただきありがとうございます。 – Silas
編集: 私のNestedScrollViewの親を調べた後、実際にはCoordinatorLayout内にあることが分かりました。しかし、CoordinatorLayoutの直接の子ではないので、ポストで提案されているgetParent()メソッドは私のためには機能しません。 – Silas