【发布时间】:2016-01-07 11:59:42
【问题描述】:
我正在尝试测试我的应用程序google signup / login feature、particularly 用户尝试添加未在对话框中列出的新帐户的情况。
使用的设置对应于默认的谷歌“添加帐户”设置。
我遇到的问题是,当应用程序要求时,我似乎无法键入电子邮件,然后按“下一步”按钮
这是我的代码
// Find add account button using uiautomator
UiObject addButton = mDevice.findObject(new UiSelector().resourceId("android:id/button2"));
assertEquals(true, addButton.exists());
// Click the button
// Fill email text box
UiObject emailBox = mDevice.findObject(new UiSelector().resourceId("identifierId"));
emailBox.waitForExists(TIMEOUT);
assertEquals(true, emailBox.exists());
emailBox.legacySetText(googleEmail);
// Find 'NEXT' Button
UiObject nextButton = mDevice.findObject(new UiSelector().resourceId("identifierNext"));
assertEquals(true, nextButton.exists());
nextButton.click();
// Fill password
UiObject passwordBox = mDevice.findObject(new UiSelector().resourceId("password"));
passwordBox.waitForExists(TIMEOUT);
assertEquals(true, passwordBox.exists());
emailBox.clearTextField();
emailBox.setText(googlePassword);
// Find 'NEXT' Button
nextButton = mDevice.findObject(new UiSelector().resourceId("next"));
assertEquals(true, nextButton.exists());
nextButton.click();
// Find 'ACCEPT' Button
nextButton = mDevice.findObject(new UiSelector().resourceId("next"));
nextButton.waitForExists(TIMEOUT);
assertEquals(true, nextButton.exists());
nextButton.click();
应用程序进入应该输入电子邮件的屏幕,并且在"assertEquals(true, emailBox.exists());" 上没有失败,所以我相信应用程序正确检测到它。
我也尝试过使用"setText" 而不是"legacySetText" 并注入了字符串,但随后“下一步”按钮未启用。
此外,有时会弹出键盘并输入文本,但这似乎是随机的,我无法随意复制。
我在这里做错了什么?
编辑:
我已对其余代码进行了注释并更改了按钮声明,但正如预期的那样,“下一步”按钮未启用,因为没有输入任何文本。
// Find add account button using uiautomator
UiObject addButton = mDevice.findObject(new UiSelector().resourceId("android:id/button2"));
assertEquals(true, addButton.exists());
// Click the button
addButton.click();
// Fill email text box
UiObject emailBox = mDevice.findObject(new UiSelector().resourceId("identifierId").descriptionContains("Enter your email "));
emailBox.waitForExists(TIMEOUT);
assertEquals(true, emailBox.exists());
emailBox.legacySetText(googleEmail);
// Find 'NEXT' Button
UiObject nextButton = mDevice.findObject(new UiSelector().resourceId("identifierNext"));
assertEquals(true, nextButton.isEnabled());
nextButton.click();
错误表明它预期为真,但在“assertEquals(true, nextButton.isEnabled());”处结果为假线
编辑 2: 我发现问题出在谷歌登录页面解释文本的方式上。
使用 uiautomatorviewer,我抓取了视图的屏幕截图并检查了我手动编写了一些文本的 EditText 字段。我发现我写的文本没有填充 text 属性,而是填充到了 content-description 属性。
我现在的问题是我只找到了一种使用框架中的 setText 方法编辑文本的方法。我试过点击视图然后设置文本但没有成功。有什么方法可以用 uiautomator 改变内容描述?
【问题讨论】:
-
您可以通过
adb shell input text your_text输入您的文字吗?
标签: android coded-ui-tests android-uiautomator ui-testing