黑马程序员技术交流社区

标题: 【自动化测试】基于Android AndroidJUnit框架的espresso [打印本页]

作者: ⋛⋌⋚JEEP    时间: 2016-10-8 17:30
标题: 【自动化测试】基于Android AndroidJUnit框架的espresso
(回帖有奖)基于Android AndroidJUnit框架的espresso测试,如今卡在
[AppleScript] 纯文本查看 复制代码
 @Test
    public void changeText_sameActivity() {
        // Type text and then press the button.
        onView(withId(R.id.editTextUserInput))
                .perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard());
        onView(withId(R.id.changeTextBt)).perform(click());

        // Check that the text was changed.
        onView(withId(R.id.textToBeChanged)).check(matches(withText(STRING_TO_BE_TYPED)));
    }


执行到onView(withId(R.id.textToBeChanged)).check(matches(withText(STRING_TO_BE_TYPED)));会报错,如下:
[AppleScript] 纯文本查看 复制代码
Caused by: junit.framework.AssertionFailedError: 'with text: is "Espresso"' doesn't match the selected view.
Expected: with text: is "Espresso"
Got: "TextView{id=2131165184, res-name=textToBeChanged, visibility=VISIBLE, width=0, height=59, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=360.0, y=96.0, text=, input-type=0, ime-target=false, has-links=false}"

如果有大神整过,提供点学习帮助。




作者: ⋛⋌⋚JEEP    时间: 2016-10-8 17:32
  public static final String STRING_TO_BE_TYPED = "Espresso";
作者: ⋛⋌⋚JEEP    时间: 2016-10-8 18:07
Caused by: junit.framework.AssertionFailedError: 'with text: is "Espresso"' doesn't match the selected view. Expected: with text: is "Espresso" Got: "TextView{id=2131165184, res-name=textToBeChanged, visibility=VISIBLE, width=213, height=59, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=253.0, y=96.0, text=ESPRESSO, input-type=0, ime-target=false, has-links=false}"
作者: ⋛⋌⋚JEEP    时间: 2016-10-8 18:09
默认输入法是中文,所以text=“”,切换输入法为英文后,text=ESPRESSO
[AppleScript] 纯文本查看 复制代码
Caused by: junit.framework.AssertionFailedError: 'with text: is "Espresso"' doesn't match the selected view. Expected: with text: is "Espresso" Got: "TextView{id=2131165184, res-name=textToBeChanged, visibility=VISIBLE, width=213, height=59, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=253.0, y=96.0, text=ESPRESSO, input-type=0, ime-target=false, has-links=false}"

作者: awakening    时间: 2016-10-8 23:38
来踩踩了  虽然看不懂
作者: baby14    时间: 2019-6-22 10:30
多谢分享




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2