使用 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/8487677.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
方案是为解决特定问题或达成特定目标而制定的一系列计划或步骤。它的作用是提供一种系统性的方法,以有效地应对挑战、优化流程或实现目标。以下是方案的主要作用: 问题解决: 方案的核心目标是解决问题。通过系统性的规划和执行,方案能够分析问题的根本原因,提供可行的解决方案,并引导实施过程,确保问题得到合理解决。 目标达成: 方案通常与明确的目标相关联,它提供了一种达成这些目标的计划。无论是企业战略、项目管理还是个人发展,方案的制定都有助于明确目标并提供达成目标的路径。 资源优化: 方案在设计时考虑了可用资源,以最大化其效用。通过明智的资源分配,方案可以在有限的资源条件下实现最大的效益,提高效率并减少浪费。 风险管理: 方案通常会对潜在的风险进行评估,并制定相应的风险管理策略。这有助于减轻潜在问题的影响,提高方案的可行性和可持续性。 决策支持: 方案提供了决策者所需的信息和数据,以便做出明智的决策。这种数据驱动的方法有助于减少不确定性,提高决策的准确性。 团队协作: 复杂的问题通常需要多个人的协同努力。方案提供了一个共同的框架,帮助团队成员理解各自的职责和任务,促进协作并确保整个团队朝着共同的目标努力。 监控与评估: 方案通常包括监控和评估的机制,以确保实施的有效性。通过定期的评估,可以及时调整方案,以适应变化的环境或新的挑战。 总体而言,方案的作用在于提供一种有序、有计划的方法,以解决问题、实现目标,并在实施过程中最大化资源利用和风险管理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值