首页 > 技术文章 > wda 自动化环境搭建

shanshan-test 2021-08-12 17:03 原文

安装依赖库

  • libimobiledevice
> brew install libimobiledevice

使用本机与苹果iOS设备的服务进行通信的库。

  • ideviceinstaller
brew install ideviceinstaller

获取设备udid、安装app、卸载app、获取bundleid

  • carthage
> brew install carthage

第三方库管理工具。

  • ios-deploy
> brew install ios-deploy
> npm install -g ios-deploy
> 这两个命令都可以

ios-deploy 不依赖于XCODE,进行安装和调试IOS应用程序。

  • node & npm
> brew install node
> brew install npm

安装及编译过程

  • 1,选择一个目录(最好用 appium 的这个,维护的频繁,facebook 的基本不维护了)
>git clone https://github.com/appium/WebDriverAgent
  • 2,进入到下载的 WebDriverAgent 项目下(这里用你下载的 WebDriverAgent 路径)
>cd /Users/mac/Desktop/download/WebDriverAgent_new
  • 3,输入命令./Scripts/bootstrap.sh(安装 WebDriverAgent 的依赖库)
>./Scripts/bootstrap.sh
> shanshan:WebDriverAgent mac$ ./Scripts/bootstrap.sh

配置 WebDriverAgent 的开发者信息

  • 配置 WebDriverAgentLib

  • 配置 WebDriverAgentRunner

  • 配置integrationApp 的开发者信息

  • 修改WebDriverAgentRunner的Build Settings->Packaging->Product Bundle Identifier

  • 修改integrationApp的Build Settings->Packaging->Product Bundle Identifier

  • 连接真机或者模拟器

  • 使用 command+u运行(不是 command+r,或者点击的运行按钮)

    • 运行后会在log 中打印出一个url 地址
    • 在浏览器中打开此地址(http://192.168.2.217:8100/status ),如果显示出一串 json 数据就是正确的连接了
    • 此时会在真机或者模拟器上出现一个应用:WebDriverAgent

    使用 python 运行

    • pip3 install facebook-wda
    • 启动模拟器
      • 注意:platform 和 name 的填写,name 写你要打开模拟器的名称
       > xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'platform=iOS Simulator,name=iPhone 6' test
  # 解锁keychain,以便可以正常的签名应用
security unlock-keychain -p $你的 mac 密码写在这里~/Library/Keychains/login.keychain

# 获取设备的UDID
UDID=$(idevice_id -l | head -n1)

# 运行测试(在 WebDriverAgent 的目录下输入此命令)
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "id=$UDID" test

#-----------------------------------------------

# 解锁keychain,以便可以正常的签名应用,
PASSWORD="replace-with-your-password"
security unlock-keychain -p $PASSWORD ~/Library/Keychains/login.keychain

# 获取设备的UDID
UDID=$(idevice_id -l | head -n1)

# 运行测试
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "id=$UDID" test
  • 设置端口转发(真机一定要设置端口转发,模拟器可以不用)
iproxy <local port> <remote port> [udid]
 # iproxy 8100 8100
 ```
- 编写一个简单的 wda 试试水(看看你的应用是不是能够起来)
![](https://img2020.cnblogs.com/blog/1572116/202108/1572116-20210812170206072-269329492.png)
 
 ```python
 import wda

wda.DEBUG = False  # default False
wda.HTTP_TIMEOUT = 10.0  # default 60.0 seconds

bundle_id = "com.cctv.yangshipin.app.iphone"
c = wda.Client('http://localhost:8100')

# 启动应用
s = c.session(bundle_id)
 ```
 
 
### 命令行运行 wda
- 1)进入webDriverAgent目录,创建start.sh文件:

创建文件

touch start.sh

进入编辑模式

vi start.sh

真机运行测试

# 解锁keychain,以便可以正常的签名应用,
PASSWORD="123"
security unlock-keychain -p $PASSWORD ~/Library/Keychains/login.keychain

# 获取设备的UDID
UDID=$(idevice_id -l | head -n1)

# 运行测试
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination"id=$UDID" test


模拟器运行测试

xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination"platform=iOS Simulator,name=iPhone 11 Pro Max" test

修改文件start.sh 的权限,使用命令:

chmod 777 start.sh # 执行start.sh文件
./start.sh

推荐阅读