【发布时间】:2013-10-30 11:32:08
【问题描述】:
我在 Android UIAutomator 项目中编写了一个方法并将相应的 jar 文件推送到 Android 设备。我正在使用以下命令从 adb shell 调用该方法“adb shell uiautomator runtest sample.jar -c com.practice.sample.Bluetooth #turnBluetoothOFF”。我遇到的问题是,它只能交替工作。即,第一次尝试它有效,第二次尝试失败,出现异常“无法注册 UiAutomationService”,第三次尝试它再次通过。
注意: 上述内容在其他 Android 设备(三星 Galaxy S3 4.2.2、三星 Galaxy S4)中运行良好。我仅在三星 Galaxy S3 4.1.1 AT&T 手机中遇到此问题。
任何解决方法或解决方案都是必要的。
代码:
// Returns Switch object of passed Text
public UiObject getSwitch(String text) throws UiObjectNotFoundException {
return new UiScrollable(new UiSelector().scrollable(true))
.getChildByText(new UiSelector().className(LinearLayout.class.getName()),text, true).getChild(
new UiSelector().className(android.widget.Switch.class.getName()));
}
public void turnBluetoothOFF() throws UiObjectNotFoundException {
if (bluetoothStatus().matches("ON")) {
getSwitch(getValue("BluetoothText")).click();
}
我觉得与代码无关。因为相同的代码在所有设备中都可以正常工作。 }
【问题讨论】:
-
你能把你的代码贴在这里吗?
标签: android android-ui ui-automation android-uiautomator