我是靠谱客的博主 独特冬天,这篇文章主要介绍iOS Automator参考文档: https://testerhome.com/topics/7220,现在分享给大家,希望可以做个参考。

Mac + XCode + Facebook-WDA + Web-editor 实现iOS UI自动化

准备工作

环境准备

  1. XCode: xcode 11 或以上
  2. MAC控制台安装工具: Homebrew. 注意安装完成后,有一条指令提示将Homebrew添加到profile中
复制代码
1
2
/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"

国内源

复制代码
1
2
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

解决无git仓库/目录的bug

复制代码
1
2
3
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
  1. 向Cocoa应用程序添加框架的工具: Carthage
  2. WDA工具包: git clone https://github.com/appium/WebDriverAgent
    // 近段时间 facebook/WebDriverAgent 已经archived了–也就是不维护了, 目前推荐用appium的fork版
  3. 代理转发工具: brew install libimobiledevice --HEAD
    如遇无法安装等bug, 尝试分步骤安装
复制代码
1
2
3
brew install libimobiledevice brew install ideviceinstaller
  1. 阿里web-editor: git clone https://github.com/alibaba/web-editor
  2. python 3.6+
  3. node.js
    // WDA需要IOS9.3,Xcode8.0+才能正常编译
    // 以上大多数可以使用Homebrew安装

具体步骤

  1. 安装Homebrew(官网https://brew.sh/)

    /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

  2. 下载Carthage
复制代码
1
2
$ brew install carthage
  1. 下载python(或官网下载)
复制代码
1
2
$ brew install python
  1. 下载node.js
复制代码
1
2
$ brew install node
  1. 准备好xcode

  2. 下载安装WebDriverAgent

复制代码
1
2
$ git clone https://github.com/facebook/WebDriverAgent
复制代码
1
2
3
或直接下载zip包解压(需要用到解压工具, 如BetterZip) 下载完毕后, 进入WDA文件夹(cd ./WebDriverAgent/), 执行以下指令会自动打包
复制代码
1
2
$ ./Scripts/bootstrap.sh
  1. 编译WebDriverAgent

    进入WDA目录, 双击WebDriverAgent.xcodeproj或直接使用xcode-file-open打开
    编译WebDriverAgentLib和WebDriverAgent的开发团队, bundleID唯一
    Scheme选择WebDriverAgentRunner
    Destination选择测试机

  2. 执行Build和Test

    Product - Test执行后, 会自动先Build, 再Test.
    编译|测试失败都会给出相应提示(点击XCode右上角, 或⇧+⌘+C显示日志)
    效果: 设备上自动安装一个没有图标的APP,名为WebDriverAgentRunner.
    APP自动启动, 黑屏, 然后退回桌面. 此时控制台界面(日志)可以看到设备的IP
    XCode动作状态栏(关闭/最小化/最大化按钮一栏)显示"Testing WebDriverAgentRunner", 蓝色进度条跑满整个状态栏(黄色叹号基本不用管)
    XCode日志区域展示如下日志:

复制代码
1
2
3
4
5
6
7
... t = 0.00s Start Test at 2020-11-19 14:46:25.908 t = 0.00s Set Up ...
  1. 如果通过手机的IP和端口还不能访问,此时需要将手机的端口转发到Mac上

    使用–HEAD安装最新版本

复制代码
1
2
$ brew install libimobiledevice --HEAD
复制代码
1
2
安装完成后, iproxy将设备8100端口映射到mac的8100端口
复制代码
1
2
$ iproxy 8100 8100
复制代码
1
2
// 多设备后加-u UDID. UDID(40字符长度)使用如下指令获取:
复制代码
1
2
$ idevice_id -l
复制代码
1
2
>>>`ab926d4aba027b9f8e23757f32597664b54946e4`
复制代码
1
2
$ iproxy 8100 8100 -u xxx

// 使用iproxy --help 可以查到更具体的用法
// 浏览器访问 “http://localhost:8100/status” 可以看到一个json串则证明WDA运行成功, 端口转发成功, 设备已连接
// 而inspector的地址是 “http://localhost:8100/inspector”, inspector是用来查看UI的图层,方便写测试脚本用的

  1. 当前inspector已被Facebook废除, 所以现在要查看UI图层, 得用到阿里的Web-editor

// 参考文档: https://github.com/alibaba/web-editorweb-editor
// 依赖: Python3.6+ 和facebook-wda
// 尽量在Safari或Google Chrome上使用

复制代码
1
2
$ pip3 install -U weditor

// 开发者使用如下指令安装

复制代码
1
2
3
$ git clone https://github.com/openatx/weditor $ pip3 install -e weditor

// 使用方式
// windows下创建快捷方式 “weditor --shortcut”
// 点击快捷方式, 或控制台输入weditor开始运行
// 该指令会在17310端口启动一个本地服务, 然后自动打开浏览器
// 更多使用方式, 运行"weditor -h"查看

参考文档: https://testerhome.com/topics/7220

安装libimobiledevice工具包

复制代码
1
2
3
4
5
6
7
8
9
brew uninstall --ignore-dependencies libimobiledevice brew uninstall --ignore-dependencies usbmuxd brew install --HEAD usbmuxd brew unlink usbmuxd brew link usbmuxd brew install --HEAD libimobiledevice brew install ideviceinstaller brew link --overwrite ideviceinstaller

每台设备都需要先用xcode,注册下,能跑起来WDA test,弄完之后接着往下看。

命令行

// export USER_PORT=8100 # WDA监听端口
// export MJPEG_SERVER_PORT=9100 # MJPEG-SERVER端口

// 避免命令行运行出错,运行一次即可
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

// 解锁keychain,防止签名权限不足问题
security unlock-keychain ~/Library/Keychains/login.keychain
// security unlock-keychain -p $PASSWORD ~/Library/Keychains/login.keychain

// test if wda can run?

复制代码
1
2
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'platform=iOS Simulator,name=iPhone 6' test

SERVER_URL=“http://localhost:4000” // 这里修改成atxserver2的地址
WDA_DIRECTORY=“./Appium-WebDriverAgent” // WDA项目地址
python3 main.py -s $SERVER_URL -W $WDA_DIRECTORY

tbc…

最后

以上就是独特冬天最近收集整理的关于iOS Automator参考文档: https://testerhome.com/topics/7220的全部内容,更多相关iOS内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(68)

评论列表共有 0 条评论

立即
投稿
返回
顶部