【问题标题】:UIAutomator testmethod passes in alternate attemptsUIAutomator 测试方法在交替尝试中通过
【发布时间】: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


【解决方案1】:

4.1 是 API 级别 16。 大多数与 UIObject 相关的 UIAutomator 函数(如 match() 等)都使用最低 API 级别 17。

【讨论】:

  • 发布的问题与matches()无关。因为同样的事情在其他 API 级别 16 设备上运行良好。我感觉的问题是UIAutomator服务一旦使用就没有发布。第一次很好,第二次失败,第三次通过,第四次失败。交替通过。
【解决方案2】:

只是一个建议:-

我在 API 16 中尝试了以下代码,效果很好。

    public void disableBT( UiObject btSwitch) throws Exception {

    System.out.println("Disabling BT");
    if (btSwitch.getText().equals("ON"))
        btSwitch.click();       
}

【讨论】:

  • 代码没有问题。(我在问题中也提到了同样的事情)。当我第一次从命令行触发任何方法时会发生什么,UIAutomator 工作正常,但第二次尝试失败并出现异常“无法注册 UiAutomationService”。如果我在此之后尝试,它会正常工作。上述行为仅在 Samsung Galaxy S3 4.1.1 AT&T mobile 中观察到,其余设备运行良好。
  • 尝试adb kill-server或重启设备再试一次。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-31
相关资源
最近更新 更多