测试开发从入门到放弃

Appium02-切换webview并识别H5

2018-08-15  本文已影响0人  __流云

更新

B站视频版:https://www.bilibili.com/video/av97162233

1. 背景

地址: http://appium.io/docs/cn/advanced-concepts/hybrid/

2. 如何正常切换Webview和原生app的context

1. 开启app webview的debug模式 (https://developer.chrome.com/devtools/docs/remote-debugging#configure-webview)
2. 查看安卓端 Android System WebViewapp的版本号,并使用对应版本的chromdriver驱动它。
版本对应表:https://npm.taobao.org/mirrors/chromedriver
进入淘宝chromdriver源的某个具体版本,然后查看notes.txt
查看安卓端webview的版本号
3. 启动appium时添加参数   --chromedriver-executable /path/to/my/chromedrive
4. 在代码中切换到H5(记得切换回来)
# switch to webview
webview = driver.contexts[-1]
driver.switch_to.context(webview)

# do some webby stuff
driver.find_element(:css, ".green_button").click

# switch back to native view
driver.switch_to.context(driver.contexts.first)

# do more native testing if we want

driver.quit()
```


PS: 我注意到某些国(垃)产(圾)ROM死活都切换不过来
        比如vivo oppo。遇到这种问题不用纠结了,换手机吧。


- 疑问咨询请加QQ群:1084188341
上一篇 下一篇

猜你喜欢

热点阅读