首页 > 解决方案 > 如何实现appium移动端新特性:getContexts for android混合自动化

问题描述

Appium 引入了一项使用移动命令收集 webview 详细信息的功能mobile:getContexts。使用此功能,我想从 webview 中排除分离的窗口,以便我可以切换到实际需要的窗口。我如何在java中做到这一点?我如何过滤响应driver.executeScript("mobile:getContexts")并验证 key 的值attached。谢谢你。

标签: mobileautomationandroid-webviewappiumappium-android

解决方案


请使用以下方法获取最新的 appium v​​1.22+,

//getContext
String currentContext = (String) appiumDriver.execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue();
System.out.println("getContext:"+currentContext);

//SwithToContext (NATIVE_APP)
appiumDriver.execute(DriverCommand.SWITCH_TO_CONTEXT, ImmutableMap.of("name", "NATIVE_APP"));

//SwithToContext (WEBVIEW)
appiumDriver.execute(DriverCommand.SWITCH_TO_CONTEXT, ImmutableMap.of("name", "WEBVIEW"));

推荐阅读