厌伴老儒烹瓠叶,强随举子踏槐花。这篇文章主要讲述Appium 测试微信小程序 Webview相关的知识,希望能为你提供帮助。
通过微信打开debugx5.qq.com,或者直接扫下面二维码
文章图片
勾选【打开TBS内核Inspector调试功能】
文章图片
Chrome查看页面元素手机连接电脑,查看是否连接成功。如下展示设备号则为连接成功
文章图片
进入任意小程序,以【X东】为例,在Chrome浏览器访问chrome://inspect/#devices
文章图片
点击inspact,即可查看页面元素
文章图片
小程序的进程微信有很多的进程,每一个小程序都运行在不同的进程中。
进入【X东】后,看下当前运行在哪个进程中
文章图片
我们可以看到,当前的小程序运行在com.tencent.mm:appbrand0中,记住这个进程,记住啦
Appium编写测试用例最关键的一点,需要添加androidProcess这一项,也就是我们上面的com.tencent.mm:appbrand0
我用python写一个简单的demo
desired_caps = {
\'platformName\': \'Android\',
\'fastReset\': \'false\',
\'deviceName\': \'XXXXXX\',
\'appPackage\': \'com.tencent.mm\',
\'appActivity\': \'.ui.LauncherUI\',
\'fullReset\': \'false\',
\'unicodeKeyboard\': \'True\',
\'resetKeyboard\': \'True\',
\'chromeOptions\': {
\'androidProcess\': \'com.tencent.mm:appbrand0\'
}
}
driver = webdriver.Remote(\'http://localhost:4723/wd/hub\', desired_caps)
driver.find_element_by_name("发现").click()
driver.find_element_by_name("小程序").click()
driver.find_element_by_name("X东购物").click()
driver.switch_to.context(\'WEBVIEW_com.tencent.mm:appbrand0\')
time.sleep(5)
print(driver.page_source)
切换Webview失败我遇到过一种切换Webview失败的情况,下面贴上appium的报错日志。
>
info: Chromedriver: Changed state to \'stopped\'
>
error: Chromedriver: Chromedriver exited unexpectedly with code null, signal SIGTERM
>
warn: Chromedriver for context WEBVIEW_com.tencent.mm:appbrand1 stopped unexpectedly
>
warn: Chromedriver quit unexpectedly, but it wasn\'t the active context, ignoring
>
error: Chromedriver: Error: A new session could not be created. (Original error: session not created exception
>
from unknown error: Runtime.executionContextCreated has invalid \'context\': {"auxData":{"frameId":"32496.2","isDefault":true},"id":2,"name":"","origin":"https://servicewechat.com"}
>
(Session info: chrome=57.0.2987.132)
>
(Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 6.1 SP1 x86_64))
>
at JWProxy.command$ (lib/proxy.js:133:15)
>
at tryCatch (D:\\Appium\\node_modules\\appium\\node_modules\\appium-chromedriver\\node_modules\\appium-jsonwp-proxy\\node_modules\\babel-runtime\\regenerator\\runtime.js:67:40)
>
at GeneratorFunctionPrototype.invoke [as _invoke] (D:\\Appium\\node_modules\\appium\\node_modules\\appium-chromedriver\\node_modules\\appium-jsonwp-proxy\\node_modules\\babel-runtime\\regenerator\\runtime.js:315:22)
>
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (D:\\Appium\\node_modules\\appium\\node_modules\\appium-chromedriver\\node_modules\\appium-jsonwp-proxy\\node_modules\\babel-runtime\\regenerator\\runtime.js:100:21)
>
at GeneratorFunctionPrototype.invoke (D:\\Appium\\node_modules\\appium\\node_modules\\appium-chromedriver\\node_modules\\appium-jsonwp-proxy\\node_modules\\babel-runtime\\regenerator\\runtime.js:136:37)
>
at bound (domain.js:284:14)
>
at GeneratorFunctionPrototype.runBound (domain.js:297:12)
>
at run (D:\\Appium\\node_modules\\appium\\node_modules\\appium-chromedriver\\node_modules\\appium-jsonwp-proxy\\node_modules\\babel-runtime\\node_modules\\core-js\\library\\modules\\es6.promise.js:89:39)
>
at D:\\Appium\\node_modules\\appium\\node_modules\\appium-chromedriver\\node_modules\\appium-jsonwp-proxy\\node_modules\\babel-runtime\\node_modules\\core-js\\library\\modules\\es6.promise.js:100:28
>
at flush (D:\\Appium\\node_modules\\appium\\node_modules\\appium-chromedriver\\node_modules\\appium-jsonwp-proxy\\node_modules\\babel-runtime\\node_modules\\core-js\\library\\modules\\$.microtask.js:17:13)
>
at process._tickDomainCallback (node.js:381:11)
>
{ [Error: A new session could not be created. (Original error: session not created exception
>
from unknown error: Runtime.executionContextCreated has invalid \'context\': {"auxData":{"frameId":"32496.2","isDefault":true},"id":2,"name":"","origin":"https://servicewechat.com"}
>
(Session info: chrome=57.0.2987.132)
>
(Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 6.1 SP1 x86_64))]
>
status: 33,
>
value: { message: \'session not created exception\\nfrom unknown error: Runtime.executionContextCreated has invalid \\\'context\\\': {"auxData":{"frameId":"32496.2","isDefault":true},"id":2,"name":"","origin":"https://servicewechat.com"}\\n(Session info: chrome=57.0.2987.132)\\n(Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 6.1 SP1 x86_64)\' },
注意最后那一段的chrome和chromedriver的版本
文章图片
查看对应表可知,两者版本不对应,需要替换chromedriver
文章图片
将Appium的chromedriver替换为相应版本后,即可成功切换。
原文:https://www.cnblogs.com/ai594ai/p/8615835.html
【Appium 测试微信小程序 Webview】原本:https://testerhome.com/topics/12003
推荐阅读
- Spring 梳理-webApplicationContext 与servletContext
- Happy Necklace (矩阵快速幂 + 递推 + 取模)
- Android StudioCould not GET gradle-3.2.0.pom (安卓包配置相关问题)
- 7中置一元赋值结合apply和updateunapply提取器
- Eclipse+ADT+Android SDK 搭建安卓开发环境
- winform app.cpnfig 文件的引用
- org.hibernate.MappingException: class com.itheima.domain.Customer.java not found while looking for p
- 13个最便宜的Android电视盒推荐合集(你最喜欢哪一款())
- Windows 11更新后黑屏怎么办(这是修复方法分步教程)