我无法执行“click()”跳过屏幕

时间:2017-11-13 16:11:29

标签: android click android-espresso ui-testing

Espresso记录器给我写了下一个代码:

ViewInteraction appCompatTextView2 = onView(allOf(withId(R.id.skipBtnTextView_BirthdayActivity), withText("Skip this step"), childAtPosition(allOf(withId(R.id.skipLayout_BirthdayActivity), childAtPosition(withClassName(is("android.widget.LinearLayout")),4)),1),isDisplayed()));
appCompatTextView2.perform(click());

运行后无效。我把它改为:

onView(withId(R.id.skipBtnTextView_BirthdayActivity)).check(matches(withText("Skip this step")));
onView(withId(R.id.skipBtnTextView_BirthdayActivity)).perform(click());

但它也失败了。

android.support.test.espresso.PerformException: Error performing
'single click - At Coordinates: 539, 1359 and precision: 16, 16' on
view 'with id: com.ingenio.keen:id/skipBtnTextView_BirthdayActivity'.

有人能帮助我吗?

1 个答案:

答案 0 :(得分:-1)

首先你应该像这样定义你的按钮/ textView等:

Button button=(Button)findViewById(R.id.button);

您应该在layout.xml中为您的按钮指定一个id

然后你应该写一个setOnClickListener:

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


          Intent intent=new Intent(YourActivity.this,DestanationActivity.class);
          startactivity(intent);//you will go to home screen activity with this 

        }
    });