Appium Appium 从 native 切换到 webview 页面

lele · January 16, 2019 · Last by lele replied at January 23, 2019 · 1222 hits

1.前提条件:
chromedriver 的版本
手机端查看 android System WebView 为:68.0.3440.91(注:开发者选项→WebView 实现,查看版本)
C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win
这个目录下面的 chromedriver.exe 的版本需要与手机端的 android System WebView 这个版本一致

app 需要开启远程 debug 模式

打包需要打 debug 包

2.driver 初始化:
// 支持 X5 内核应用自动化配置 (如果没有用,可以不写这个配置)
capabilities.setCapability("recreateChromeDriverSessions", true);
// ChromeOptions 使用来定制启动选项
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("androidProcess", "xxx.xxxx:xxx");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
// 初始化会默认将 chrome 浏览器打开,需要将 Browser 置为空
capabilities.setBrowserName("");

3.代码调用
//获取当前上下文,返回值含 NATIVE_APP 则为原生控件;返回值含 WEBVIEW 则为 web 控件。
driver.getContextHandles();
//切换 WEBVIEW
driver.context("xxx.xxxx:xxx");
//切换 NATIVE_APP
driver.context("NATIVE_APP");

共收到 2 条回复 时间 点赞

请问 iOS 自动化的话,显示不出 webview,如何才能让他显示出来...😭

lele #2 · January 23, 2019 Author

ios 需要被测试的 app 自己打包后直接安装在手机上才能识别 webview

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up