2017年12月28日,微信放出了 6.6.1 版本,在微信首页二楼(下拉出现)位置重磅推出了“跳一跳”小程序,瞬间刷爆朋友圈。html
在你们忙于游戏的时候,有人独辟蹊径基于 python + WebDriverAgent 实现了经过 PC 远程操控手机“跳一跳”小程序小人自动跳动,将分数刷到了使人发指的地步,悄悄占领朋友圈第一。python
目前已经有比较火的几篇文章详细讲如何实现上述操做,可是或多或少存在描述不够详细、参数设置只在某些机型上表现较好的问题。这也形成我在根据这些教程实现过程当中踩了几个小坑。本文基于 Macbook + iphone 6s plus 来说一下如何实现上述过程,也将踩过的坑记录下。git
下载并点击安装。下载地址:www.python.org/downloads/m… 在终端 terminal 中输入以下命令,查看是否安装 python3 成功。github
~ python3 -V
Python 3.6.4
复制代码
文档地址:docs.python.org/3/tutorial/… 方法以下:npm
~ python3 -m venv tutorial-env
~ source tutorial-env/bin/activate
(tutorial-env) ➜ ~
复制代码
安装 python 包管理工具 pip。 文档地址:pip.pypa.io/en/latest/i… 方法以下:json
(tutorial-env) ➜ ~ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
(tutorial-env) ➜ ~ python get-pip.py
复制代码
经过 appstore 安装bootstrap
xcode,尽可能新版。尽可能升级Xcode到最新版,保持iPhone的版本大于9.3。小程序
从github上下载代码xcode
git clone https://github.com/facebook/WebDriverAgent
复制代码
安装 carthagebash
brew install carthage
复制代码
运行初始化脚本
./Scripts/bootstrap.sh
复制代码
该脚本会使用Carthage下载全部的依赖,使用npm打包响应的js文件
执行完成后,直接双击打开WebDriverAgent.xcodeproj这个文件。
设置证书签名,Team 一栏勾选我的帐号便可。
Xcode - Product - Scheme 中选择 WebDriverAgentRunner。
运行 Xcode - Product - Test
~ brew install libimobiledevice
~ iproxy 8100 8100
复制代码
使用iproxy --help 能够查到更具体的用法。 这时经过访问http://localhost:8100/status确认WDA是否运行成功。
而inspector的地址是http://localhost:8100/inspector, inspector是用来查看UI的图层,方便写测试脚本用的
获取 python 跳一跳代码
git clone git@github.com:korbinzhao/wechat_jump_game.git
复制代码
安装 facebook-wda
(tutorial-env) ➜ ~ pip3 install --pre facebook-wda
复制代码
安装项目依赖
(tutorial-env) ➜ wechat_jump_game git:(master) ✗ pip3 install -r requirements.txt
复制代码
拷贝 ./config/iPhone 目录下对应的设备配置文件,重命名并替换到 ./config.json
在手机中打开小程序界面,运行 python 脚本
(tutorial-env) ➜ wechat_jump_game git:(master) ✗ python3 wechat_jump_auto_iOS.py
复制代码
最终效果