在 Android 设备上,我们可以添加多个用户。但是只有一个管理员用户。当我使用 appium 切换到非管理员用户时,我无法启动任何应用程序。例如
Map<String, Object> argsList = new HashMap<>();
argsList.put("command", "am");
argsList.put("args", Lists.newArrayList("switch-user", userID));
driver.executeScript("mobile: shell", argsList);
Thread.sleep(1000);
new WebDriverWait(driver,10).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[contains(text(),\"Switching to\")]")));
driver.activateApp("com.android.settings");
我们可以使用命令获取用户ID - adb shell pm list users
获取非管理员用户的 ID。是数值
脚本执行时没有任何错误,但不会启动应用程序。像这里我正在尝试启动设置应用程序。当我们为管理员用户使用 userID 时,相同的代码可以正常工作。它启动应用程序