我尝试使用'espresso'编写简单的测试
@RunWith(AndroidJUnit4.class)
@LargeTest
public class EspressoTest {
@Rule
public ActivityRule<IntroActivity> mActivityRule = new ActivityRule(IntroActivity.class);
public EspressoTest() {
IdlingPolicies.setMasterPolicyTimeout(1000, TimeUnit.SECONDS);
}
@Test
public void testShouldClickEmailButton() {
onView(withText(R.string.in_email)).perform(click());
}
}
但是我收到了一个错误:
PerformException: Error performing 'single click' on view 'with string from resource id: <2131099761>[in.email] value: Login With Email'.
我正在尝试不同的测试框架,robotium
现在对我来说是最好的,但是如果有人可以帮助修复此错误,我将非常感激
UPD 更详细的日志
引起:java.lang.RuntimeException:不会执行操作 因为目标视图与以下一个或多个不匹配 约束:显示至少90%的视图区域 用户。目标视图:“DSeparatedButton {id = 2131427459, res-name = button_login,visibility = VISIBLE,width = 622,height = 120, 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, root-is-layout-requested = false,has-input-connection = false,x = 0.0, y = 333.0,text =使用Email登录,输入类型= 0,ime-target = false, 具有链接= FALSE}“
我也有一点飞溅动画
答案 0 :(得分:3)
onView方法仅用于屏幕上100%可见的视图,因此Espresso可以正确测试它们。 我的建议是使用onData方法来测试视图。 这应该有效:
onData(withText(R.string.in_email)).perform(click());
如果这不是您要搜索的答案,我可以为您提供更多帮助。如果这不起作用,请告诉我。 祝你好运!
答案 1 :(得分:-1)
@RunWith(AndroidJUnit4.class)
@LargeTest
public class EspressoTest {
@Rule
public ActivityTestRule<IntroActivity> mActivityRule = new ActivityTestRule(IntroActivity.class);
@Test
public void testShouldClickEmailButton() {
mActivityRule.launch(new Intent());
onView(withText(R.string.in_email)).perform(click());
}
}