使用Appium进行iOS的真机自动化测试

  • 环境搭建
    Xcode
    appium

  • 安装依赖工具包

brew install node

brew install npm

brew install --HEAD ideviceinstaller

brew install --HEAD libimobiledevice

brew install ios-deploy

brew install carthage

npm install -g appium-doctor

在终端输入

appium-doctor

验证所有依赖是否安装成功,都是打钩状态就证明环境正常,如图


6C7309F4-4054-463B-85DF-88D4C44DE110.png
  • 更新Appium中的WebDriverAgent
    1.到WebDriverAgent下载最新版本的WebDriverAgent
    2.进入下载后的WebDriverAgent文件路径
cd WebDriverAgent

3.执行

./Scripts/bootstrap.sh

4.直接用Xcode打开WebDriverAgent.xcodeproj文件
5.配置WebDriverAgentLibWebDriverAgentRunner的证书

1F9C4306-5A54-4C1F-9848-726F4C919CB1.png

6.选择目标设备
2581954-4f960a3ed6235a89.png

7.选择 WebDriverAgentRunner
2581954-68186c0e0dbbf26c.png

8.最后运行 Product -> Test:
2581954-3983b907d42edbd9.png

一切正常的话,手机/模拟器上会出现一个无图标的 WebDriverAgent 应用,启动之后,马上又返回到桌面。

此时控制台界面可以看到设备的 IP 地址:


FBBE4F78-E535-4D4E-AF5E-779BABA6DD0D.png

通过上面给出的 IP地址 和端口,加上/status合成一个url地址。例如 [http://192.168.3.26:8100/status],然后浏览器打开。如果出现一串 JSON 输出,说明 WDA 安装成功了。

如果连接的是真机,则有可能会打不开。我们需要做一下端口转发。

iproxy 8100 8100

此时在浏览器中打开链接http://localhost:8100/status查看,显示:

{
  "value" : {
    "message" : "WebDriverAgent is ready to accept commands",
    "state" : "success",
    "os" : {
      "testmanagerdVersion" : 28,
      "name" : "iOS",
      "sdkVersion" : "13.4",
      "version" : "13.4"
    },
    "ios" : {
      "ip" : "192.168.3.26"
    },
    "ready" : true,
    "build" : {
      "time" : "Sep 14 2020 14:26:07",
      "productBundleIdentifier" : "com.facebook.WebDriverAgentRunner"
    }
  },
  "sessionId" : "CD0C278F-B8AB-403B-9094-7A18FF70F9B9"
}
  • 关掉端口转发,不要停止xcode运行,打开appium,做如下配置:


    5F721C5F-0469-41C1-AC72-13F322D4DE81.png
  "udid": "",#设备id
  "platformName": "iOS",
  "deviceName": "iphone11",#手机型号
  "bundleId": "",#APP id 可通过ideviceinstaller -l查看
  "platformVersion": "11.4",#系统版本
  "xcodeOrgId": "",#开发者账号id
  "xcodeSigningId": "iPhone Developer",
  "automationName": "XCUITest"

我已经在手机上装好了被测应用,若还未安装,需通过appName指定安装包路径。点击右下角Start Session,

  • 成功启动后,会出现这个编辑界面,可以开始自动化测试的步骤设置啦


    IMG_4022.JPG

问题汇总

1.报错

WebDriverAgent.xcodeproj Building for iOS, but the embedded framework 'RoutingHTTPServer.framework' was built for iOS + iOS Simulator.

解决:
WebDriverAgent -> Build Settings -> Build Options -> Validate Workspace = Yes.

  • 查看iPhone手机上app的bundleid
ideviceinstaller -l
  • 查看mac上的模拟器或连接的iOS设备
instruments -s devices

遇到的问题

1.执行./Scripts/bootstrap.sh后报错

A shell task (/usr/bin/env git clone --bare --quiet https://github.com/marekcirkos/RoutingHTTPServer.git /Users/galaxy/Library/Caches/org.carthage.CarthageKit/dependencies/RoutingHTTPServer) failed with exit code 128:
fatal: unable to access 'https://github.com/marekcirkos/RoutingHTTPServer.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 

原因不详,已解决

xcode-select --print-path
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

2.xcode运行报错

error: Building for iOS, but the linked and embedded framework 'RoutingHTTPServer.framework' was built for iOS + iOS Simulator. (in target 'WebDriverAgentLib' from project 'WebDriverAgent')

解决

WebDriverAgent 
-> Build Settings 
-> Build Options
 -> Validate Workspace = Yes  for each target of the workspace

你可能感兴趣的:(使用Appium进行iOS的真机自动化测试)