Appium 切换上下文环境,代码如下:

    private void switchToContext(String sContext) {
LogManager.getLogger(this.getClass()).info("Swith to Context: " + sContext);
Set<String> contextNames = driver.getContextHandles();
LogManager.getLogger(this.getClass()).info("Exists Contexts: " + contextNames.toString());
for (String contextName : contextNames) {
if (contextName.contains(sContext)) {
driver.context(contextName);
LogManager.getLogger(this.getClass()).info("Swith to Context SUCCESS.");
break;
}
}
}
05-03 23:47