A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

(回帖有奖)基于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}"

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



5 个回复

倒序浏览
  public static final String STRING_TO_BE_TYPED = "Espresso";
回复 使用道具 举报
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}"
回复 使用道具 举报
默认输入法是中文,所以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}"
回复 使用道具 举报
来踩踩了  虽然看不懂
回复 使用道具 举报
多谢分享
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马