Python-iOS微信跳一跳
一 、安装WDA https://testerhome.com/topics/7220
原wda不维护了,用appium的fork(直接去git download比较快)
1.1 github上下载代码
git clone https://github.com/appium/WebDriverAgent
1.2 安装 carthage http://blog.csdn.net/Mazy_ma/article/details/70185547
brew install carthage
carthage version
1.3 运行初始化脚本
cd xx/xx/WebDriverAgent
./Scripts/bootstrap.sh
1.4 启动 WDA https://testerhome.com/topics/7220
双击打开WebDriverAgent.xcodeproj这个文件
WebDriverAgentLib和WebDriverAgentRunner配置证书,选择scheme和设备
最后运行 Product -> Test
成功:控制台会打印一个IP地址,这时通过访问http://localhost:8100/status确认WDA是否运行成功。
1.5 如果http://localhost:8100/status没反应,需要安装端口转发工具 。命令为
brew install libimobiledevice
下载太慢,连手机热点。或者换国内源
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs
and run
/usr/local/opt/openssl@1.1/bin/c_rehash
openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.
If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
Warning: Building python@3.9 from source:
The bottle needs the Apple Command Line Tools to be installed.
You can install them, if desired, with:
xcode-select --install
1.6需要安装端口转发之后,转发端口。 iproxy 8100 8100
端口转发之后,就可以看到http://localhost:8100/status的json数据
而inspector的地址是http://localhost:8100/inspector, inspector是用来查看UI的图层,方便写测试脚本用的
二、去github下载脚本 https://github.com/wangshub/wechat_jump_game
pip3 install --pre facebook-wda
pip3 install -r requirements.txt
拷贝 ./config/iPhone 目录下对应的设备配置文件,重命名并替换到 ./config.json
执行脚本文件 python3 wechat_jump_auto_iOS.py
报错了
解决:tap_hold方法-_percent2pos方法的值问题,float默认是百分比,int默认是绝对坐标
,手动更改一下代码即可。
s.tap_hold(int(random.uniform(0, 320)), int(random.uniform(64, 320)), press_time)
def tap_hold(self, x, y, duration=1.0):
"""
Tap and hold for a moment
Args:
- x, y(int, float): float(percent) or int(absolute coordicate)
- duration(float): seconds of hold time
三、后续使用
1、运行初始化脚本
cd xx/xx/WebDriverAgent
./Scripts/bootstrap.sh
2、转发端口。 iproxy 8100 8100
3、启动 WDA https://testerhome.com/topics/7220
双击打开WebDriverAgent.xcodeproj这个文件
WebDriverAgentLib和WebDriverAgentRunner配置证书,选择scheme(注意选WebDriverAgentRunner
)和设备
最后运行 Product -> Test
成功:控制台会打印一个IP地址,这时通过访问http://localhost:8100/status确认WDA是否运行成功。
4、执行脚本文件 python3 wechat_jump_auto_iOS.py
注意:WebDriverAgentRunner的证书设置id在build setting里面
iOS 真机如何安装 WebDriverAgent
UI 自动化框架 (基于 facebook-wda)
四、一些遇到的问题
1、code ERESOLVE
ERESOLVE unable to resolve dependency tree
npm 版本太高,需要降低版本
npm install npm@6.14.7 -g
npm view npm versions
或上github查看tags版本
2、Building for iOS, but the linked and embedded framework 'RoutingHTTPServer.framework' was built for iOS + iOS Simulator.
把runner配置好即可,cmd+u的schme选择runner
3、Error starting Appium server: listen EADDRNOTAVAIL: address not available 192.168.104.118:8100
用127.0.0.1/status
4、python依赖库
pip3 install matplotlib
pip3 install opencv-python