Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 单击SwipeRefreshLayout下的RecyclerView项时,机器人测试中止_Java_Android_Android Recyclerview_Swiperefreshlayout_Android Espresso Recorder - Fatal编程技术网

Java 单击SwipeRefreshLayout下的RecyclerView项时,机器人测试中止

Java 单击SwipeRefreshLayout下的RecyclerView项时,机器人测试中止,java,android,android-recyclerview,swiperefreshlayout,android-espresso-recorder,Java,Android,Android Recyclerview,Swiperefreshlayout,Android Espresso Recorder,每当我单击具有idAndroid:id=“@+id/Primary\u recycler\u”视图的RecyclerView的任何项目时,我的Robo脚本和Android Espresso测试就会中止。我检查了原因,发现这个问题是因为SwipeRefreshLayout,因为如果我删除了该布局并运行脚本,它就会成功 为了纠正这个问题,我在SwipeRefreshLayout下面添加了一个relativeLayout,它的idandroid:id=“@+id/relative。所以现在androi

每当我单击具有id
Android:id=“@+id/Primary\u recycler\u”视图的RecyclerView的任何项目时,我的Robo脚本和Android Espresso测试就会中止。
我检查了原因,发现这个问题是因为SwipeRefreshLayout,因为如果我删除了该布局并运行脚本,它就会成功

为了纠正这个问题,我在SwipeRefreshLayout下面添加了一个relativeLayout,它的id
android:id=“@+id/relative
。所以现在android Espresso测试成功运行,但Robo脚本仍在中止。根据我的应用程序要求,我不能删除SwipeRefreshLayout

XML

Androi EspressoTest(成功)

package com.example.myapplication;
导入android.support.test.espresso.ViewInteraction;
导入android.support.test.filters.LargeTest;
导入android.support.test.rule.ActivityTestRule;
导入android.support.test.runner.AndroidJUnit4;
导入android.view.view;
导入android.view.ViewGroup;
导入android.view.ViewParent;
导入org.hamcrest.Description;
导入org.hamcrest.Matcher;
导入org.hamcrest.TypeSafeMatcher;
导入org.junit.Rule;
导入org.junit.Test;
导入org.junit.runner.RunWith;
导入静态android.support.test.espresso.espresso.onView;
导入静态android.support.test.espresso.action.ViewActions.click;
导入静态android.support.test.espresso.contrib.RecycleServiceActions.ActionItemPosition;
导入静态android.support.test.espresso.matcher.ViewMatchers.withId;
导入静态org.hamcrest.Matchers.allOf;
@最大的
@RunWith(AndroidJUnit4.class)
公共类TAPS3{
@统治
public ActivityTestRule mActivityTestRule=新的ActivityTestRule(MainActivity.class);
@试验
公共无效tapss3(){
ViewInteraction recyclerView=onView(
allOf(带id(R.id.主回收器视图),
儿童体位(
withId(R.id.relative),
0)));
执行(ActionItemPosition(0,click());
ViewInteraction Recyclererview2=onView(
allOf(带id(R.id.主回收器视图),
儿童体位(
withId(R.id.relative),
0)));
recyclerView2.perform(actionOnItemPosition(3,click());
ViewInteraction RecycleServiceW3=onView(
allOf(带id(R.id.主回收器视图),
儿童体位(
withId(R.id.relative),
0)));
perform(actionItemPosition(12,click());
ViewInteraction RecycleServiceW4=onView(
allOf(带id(R.id.主回收器视图),
儿童体位(
withId(R.id.relative),
0)));
执行(ActionItemPosition(27,click());
}
专用静态匹配器子定位(
最终匹配器父匹配器,最终整型位置){
返回新的TypeSafeMatcher(){
@凌驾
公共无效说明(说明){
description.appendText(“父项中的子项位置“+位置+”);
parentMatcher.descripbeto(描述);
}
@凌驾
公共布尔匹配安全(视图){
ViewParent=view.getParent();
返回视图组的父实例(&parentMatcher.matches)(父)
&&view.equals(((视图组)parent.getChildAt(位置));
}
};
}
}

嘿,伙计们,我在XML文件中做了一些更改后找到了解决方案。因此,我在RecyclerView上方又添加了一个RelativeLayout,其id
android:id=“@+id/relative2
,在该更改之后,robo脚本成功运行而未中止

最终更改的XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:id="@+id/myConstraint_layOut"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeId"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

  <RelativeLayout
    android:id="@+id/relative"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/Primary_recycler_view"
        android:scrollbars="vertical"
        android:layout_marginTop="50dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

  </RelativeLayout>

    </android.support.v4.widget.SwipeRefreshLayout>

</RelativeLayout>
[
  {
    "eventType": "VIEW_CLICKED",
    "timestamp": 1560334484260,
    "replacementText": "",
    "actionCode": -1,
    "delayTime": 0,
    "canScrollTo": false,
    "elementDescriptors": [
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": 0,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": -1,
        "resourceId": "com.example.myapplication:id/layoutAccounts",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.support.v7.widget.RecyclerView",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/Primary_recycler_view",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/relative",
        "contentDescription": "",
        "text": ""
      }
    ]
  },
  {
    "eventType": "VIEW_CLICKED",
    "timestamp": 1560334491086,
    "replacementText": "",
    "actionCode": -1,
    "delayTime": 0,
    "canScrollTo": false,
    "elementDescriptors": [
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": 5,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": -1,
        "resourceId": "com.example.myapplication:id/layoutAccounts",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.support.v7.widget.RecyclerView",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/Primary_recycler_view",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/relative",
        "contentDescription": "",
        "text": ""
      }
    ]
  },
  {
    "eventType": "VIEW_CLICKED",
    "timestamp": 1560334500084,
    "replacementText": "",
    "actionCode": -1,
    "delayTime": 0,
    "canScrollTo": false,
    "elementDescriptors": [
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": 14,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": -1,
        "resourceId": "com.example.myapplication:id/layoutAccounts",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.support.v7.widget.RecyclerView",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/Primary_recycler_view",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/relative",
        "contentDescription": "",
        "text": ""
      }
    ]
  },
  {
    "eventType": "VIEW_CLICKED",
    "timestamp": 1560334508008,
    "replacementText": "",
    "actionCode": -1,
    "delayTime": 0,
    "canScrollTo": false,
    "elementDescriptors": [
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": 22,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": -1,
        "resourceId": "com.example.myapplication:id/layoutAccounts",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.support.v7.widget.RecyclerView",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/Primary_recycler_view",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/relative",
        "contentDescription": "",
        "text": ""
      }
    ]
  },
  {
    "eventType": "VIEW_CLICKED",
    "timestamp": 1560334516473,
    "replacementText": "",
    "actionCode": -1,
    "delayTime": 0,
    "canScrollTo": false,
    "elementDescriptors": [
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": 28,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": -1,
        "resourceId": "com.example.myapplication:id/layoutAccounts",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.support.v7.widget.RecyclerView",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/Primary_recycler_view",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/relative",
        "contentDescription": "",
        "text": ""
      }
    ]
  }
]
package com.example.myapplication;


import android.support.test.espresso.ViewInteraction;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.allOf;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class tapss3 {

    @Rule
    public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);

    @Test
    public void tapss3() {
        ViewInteraction recyclerView = onView(
                allOf(withId(R.id.Primary_recycler_view),
                        childAtPosition(
                                withId(R.id.relative),
                                0)));
        recyclerView.perform(actionOnItemAtPosition(0, click()));

        ViewInteraction recyclerView2 = onView(
                allOf(withId(R.id.Primary_recycler_view),
                        childAtPosition(
                                withId(R.id.relative),
                                0)));
        recyclerView2.perform(actionOnItemAtPosition(3, click()));

        ViewInteraction recyclerView3 = onView(
                allOf(withId(R.id.Primary_recycler_view),
                        childAtPosition(
                                withId(R.id.relative),
                                0)));
        recyclerView3.perform(actionOnItemAtPosition(12, click()));

        ViewInteraction recyclerView4 = onView(
                allOf(withId(R.id.Primary_recycler_view),
                        childAtPosition(
                                withId(R.id.relative),
                                0)));
        recyclerView4.perform(actionOnItemAtPosition(27, click()));
    }

    private static Matcher<View> childAtPosition(
            final Matcher<View> parentMatcher, final int position) {

        return new TypeSafeMatcher<View>() {
            @Override
            public void describeTo(Description description) {
                description.appendText("Child at position " + position + " in parent ");
                parentMatcher.describeTo(description);
            }

            @Override
            public boolean matchesSafely(View view) {
                ViewParent parent = view.getParent();
                return parent instanceof ViewGroup && parentMatcher.matches(parent)
                        && view.equals(((ViewGroup) parent).getChildAt(position));
            }
        };
    }
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:id="@+id/myConstraint_layOut"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeId"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:id="@+id/relative"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <RelativeLayout
            android:id="@+id/relative2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/Primary_recycler_view"
            android:scrollbars="vertical"
            android:layout_marginTop="50dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        </RelativeLayout>

     </RelativeLayout>

    </android.support.v4.widget.SwipeRefreshLayout>

</RelativeLayout>
[
  {
    "eventType": "VIEW_CLICKED",
    "timestamp": 1560409968465,
    "replacementText": "",
    "actionCode": -1,
    "delayTime": 0,
    "canScrollTo": false,
    "elementDescriptors": [
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": 2,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": -1,
        "resourceId": "com.example.myapplication:id/layoutAccounts",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.support.v7.widget.RecyclerView",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/Primary_recycler_view",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/relative2",
        "contentDescription": "",
        "text": ""
      }
    ]
  },
  {
    "eventType": "VIEW_CLICKED",
    "timestamp": 1560409976951,
    "replacementText": "",
    "actionCode": -1,
    "delayTime": 0,
    "canScrollTo": false,
    "elementDescriptors": [
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": 15,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": -1,
        "resourceId": "com.example.myapplication:id/layoutAccounts",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.support.v7.widget.RecyclerView",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/Primary_recycler_view",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/relative2",
        "contentDescription": "",
        "text": ""
      }
    ]
  },
  {
    "eventType": "VIEW_CLICKED",
    "timestamp": 1560409984752,
    "replacementText": "",
    "actionCode": -1,
    "delayTime": 0,
    "canScrollTo": false,
    "elementDescriptors": [
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": 25,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": -1,
        "resourceId": "com.example.myapplication:id/layoutAccounts",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.support.v7.widget.RecyclerView",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/Primary_recycler_view",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "android.widget.RelativeLayout",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "com.example.myapplication:id/relative2",
        "contentDescription": "",
        "text": ""
      }
    ]
  }
]