Appium 切换上下文环境

时间:2023-03-10 02:44:36
Appium 切换上下文环境

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;
}
}
}