通过微信打开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替换为相应版本后,即可成功切换。

Appium 测试微信小程序 Webview的更多相关文章

  1. 使用 Appium 测试微信小程序 Webview

    打开调试功能 通过微信打开debugx5.qq.com,或者直接扫下面二维码   勾选[打开TBS内核Inspector调试功能]   Chrome查看页面元素 手机连接电脑,查看是否连接成功.如下展 ...

  2. 使用Appium 测试微信小程序和微信公众号方法

    由于腾讯系QQ.微信等都是基于腾讯自研X5内核,不是google原生webview,需要打开TBS内核Inspector调试功能才能用Chrome浏览器查看页面元素,并实现Appium自动化测试微信小 ...

  3. Appium之测试微信小程序

    坚持原创输出,点击蓝字关注我吧 作者:清菡 博客:Oschina.云+社区.知乎等各大平台都有. 目录 一.往期回顾 二.测试微信小程序 1.准备工作 2.操作步骤 3.注意 4.强制设置安卓的进程 ...

  4. appium+python 微信小程序的自动化

    sudo kill -9 $(lsof -i:8889 -t) mitmweb -p 8889 -s addons.py mitmdump -q  -p 8889 -s addons.py http: ...

  5. 微信小程序web-view实例

    微信小程序web-view实例 index.js //index.js //获取应用实例 const app = getApp() Page({ /** * 页面的初始数据 */ data: { }, ...

  6. 微信小程序web-view之wx.miniProgram.redirectTo

    17年微信小程序官方提供了web-view组件. 官方描述:web-view组件是一个可以用来承载网页的容器,会自动铺满整个小程序页面.个人类型与海外类型的小程序暂不支持使用. 这段时间研究了一下小程 ...

  7. 微信小程序web-view的简单思考和实践

    微信小程序的组件web-view推出有一段时间了,这个组件的推出可以说是微信小程序开发的一个重要事件,让微信小程序不会只束缚在微信圈子里了,打开了一个口子,这个口子或许还比较小,但未来有无限可能. 简 ...

  8. 微信小程序 web-view 的 url 带参问题

    在微信小程序开发过程中,会需要跳转到外部链接,微信提供了 <web-view>组件供我们使用. 为减少重复代码,一般会将这个功能单独抽取为一个页面供大家使用: <template&g ...

  9. 微信小程序web-view(webview) 嵌套H5页面 唤起微信支付的实现方案

    场景:小程序页面有一个web-view组件,组件嵌套的H5页面,要唤起微信支付. 先讲一下我的项目,首先我是自己开发的一个H5触屏版的商城系统,里面含有购物车,订单支付等功能.然后刚开始,我们公众号里 ...

随机推荐

  1. Spring cloud zuul跨域(一)

    项目背景:我们有web和大屏,以及移动端,需要访问微服务接口. 然而大屏时自己打开的网页,在网页中通过js调用我的webapi.出现了跨域情况. 原因:出现这个问题,是由于跨域请求有2次请求. 第一次 ...

  2. ECMA262,JavaScript引擎,浏览器

    相关阅读:https://www.cnblogs.com/970119449blog/p/8080133.html 相关阅读:https://www.jb51.net/article/75888.ht ...

  3. python在windows(双版本)及linux环境下安装

    python下载 下载地址:https://www.python.org/downloads/ 可以下载需要的版本,这里选择2.7.12和3.6.2 下面第一个是linux版本,第二个是windows ...

  4. JDK源码分析(9) LinkedHashMap

    概述 LinkedHashMap是一个关联数组.哈希表,它是线程不安全的,允许key为null,value为null.他继承自HashMap,实现了Map<K,V>接口.其内部还维护了一个 ...

  5. App自动化(1)--Appium-Android环境搭建

    本次笔记记录Appium-Android环境搭建,主要实现在windows上通过python编写脚本来实现模拟器上安装的app自动化测试. 主要步骤:安装node.js,配置JDK环境,配置Andro ...

  6. LeetCode--11_974_Subarray_Sums_Divisible_by_K

    题目链接:点击这里 public static int subarraysDivByK(int[] A, int K) { int ans = 0,sum = 0; int[] B = new int ...

  7. termux

    使用http服务,链接原服务器要挂vpn. apt edit-sources 如果提示 $ apt edit-sources e: Sub-process editor returned a n er ...

  8. 谈谈JavaScript中继承方式

    聊一聊js中的继承 一.简单继承---使用原型赋值的方式继承,将实例化的对象,赋值给子级的原型 父级构造函数 function Parent(param) { this.name = 'parent' ...

  9. CentOS 7 安装docker (图文)

     一定要用root账号登录系统,打开终端/或远程工具(如xshell)登录系统 检查是否已经安装命令  rpm –qa|grep docker 出现如上说明已安装 也可用命令docker -v  (如 ...

  10. 发送邮件,出现异常:服务器响应为: Error: need EHLO and AUTH first !"

    在使用 System.Net.Mail组建发送邮件的时候出现了"命令顺序不正确. 服务器响应为: Error: need EHLO and AUTH first !"异常 解决方法 ...