我正在尝试使用espresso框架为Android APP编写一些UI测试.
现在我只是检查启动画面上是否存在所有元素,然后我尝试单击登录按钮.
单击该按钮时,测试失败,因为我似乎无法理解为什么会发生错误.
我的测试代码是
@RunWith(AndroidJUnit4.class)
@SmallTest
public class WelcomeTest {
@Rule
public ActivityTestRule<Welcome> mActivityRule = new ActivityTestRule<>(
Welcome.class);
@Test
public void elements_present() {
// Check login
onView(withId(R.id.wv_login)).check(matches(isDisplayed()));
// Check signup
onView(withId(R.id.wv_signup)).check(matches(isDisplayed()));
// Check video
onView(withId(R.id.videoView)).check(matches(isDisplayed()));
// Check swipe right
onView(withId(R.id.videoView)).perform(swipeRight());
// Check swipe left
onView(withId(R.id.videoView)).perform(swipeLeft());
}
@Test
public void tap_login() {
// Tap login button
onView(withId(R.id.wv_login)).perform(click());
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:
引发者:java.lang.RuntimeException:将不执行操作,因为目标视图与以下一个或多个约束不匹配:至少90%的视图区域显示给用户.
这是什么意思,这是由我的测试方法引起的还是代码中的错误?该应用程序似乎在我的设备上工作得很好.
PS:我已经禁用了espresso文件建议的动画