webview.setWebContentsDebuggingEnabled(true);
进入设置
->应用
,点击显示系统进程
显示系统进程
找到Android System WebView
,它的版本也就是75.0.3770.143
Android System WebView
在chromedriver中找到对应的版本 https://npm.taobao.org/mirrors/chromedriver/?utm_source=testingpai.com
https://dev.ucweb.com/docs/pwa/docs-zh/xy3whu
设置
查看Home
@Test
public void test() {
androidDriver.findElement(MobileBy.xpath("//*[@text='柠檬社区']")).click();
System.out.println(androidDriver.getContextHandles());//[NATIVE_APP, WEBVIEW_com.lemon.lemonban]
//切换到WEBVIEW_com.lemon.lemonban
androidDriver.context("WEBVIEW_com.lemon.lemonban");
//进入web页面点击注册按钮
androidDriver.findElement(MobileBy.xpath("//span[contains(text(),'注册')]")).click();
}
由于腾讯系QQ/微信是基于腾讯自研的X5内核,不是谷歌原生webview,所以调试会有差异
微信小程序只能够支持手机,模拟器是不行的。
https://debugx5.qq.com/ http://debugmm.qq.com/?forcex5=true
// 支持X5内核应用自动化配置
desiredCapabilities.setCapability("recreateChromeDriverSession", true);
// ChromeOptions 使用来定制启动选项,因为在appium中切换context识别webview的时候,
// 把com.tencent.mm:toolsmp的webview识别成com.tencent.mm的webview
// 为了规避这个问题,加上androidProcess: com.tencent.mm:toolsmp
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("androidProcess","com.tencent.mm:appbrand0");
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY,options);
// 初始化会默认将chrome浏览器打开,需要将Browser置为空
desiredCapabilities.setBrowserName("");
注意:不清除微信的数据的方法
capabilities.setCapability("noReset", true);