ios自动化基础
一、ios自动化
1.1. 基础知识
- 关于Certificate、provisioning profile、app id的介绍及其之间的关系
- appium 从0到1搭建移动App功能自动化测试平台(1):模拟器中运行iOS应用
- iOS appium自动化入门(MAC java)
- 使用真机测试时,被测真机需关联到对应的开发者证书下。
- ios10(xcode8)及以后,不再支持uiautomation自动化工具,改为使用xctest工具。appium低版本里使用的工具为uiautomation来支持ios自动化,后改为facebook的WebDriverAgent(wda)支持自动化。wda最底层使用xctest。
- iOS自动化,可以使用真机,也可使用模拟器。若使用真机,可对普通的app包进行自动化;若使用模拟器,需要在本地使用Xcode编译代码,且编译时选择模拟器类型。
- iOS的app需要有证书签名才可安装。证书分为3种,我们可使用公司的企业证书 或 个人开发者证书来进行自动化。
- 企业证书:$299/年。打出的app包可以装到手机上,但不能提交 app store 。一般用于企业内部软件。
- 收费个人开发者证书:$99/年。未提交 app store 前只能最多安装到 100 台设备上,并且该手机的 udid 号必须登记到此开发者证书上(在苹果的开发者平台上登记)。可以提交到 app store。
- 免费个人开发者证书(personal team):从 XCode 7 开始推出,仅用于开发中的真机调试。可最多安装到5台设备上(这五台设备必须通过连接开发者电脑的方式来登记到证书上),没有提交到 app store 的权限。
- 可使用个人开发者证书进行自动化测试。若需使用企业证书,需要将自己的开发者账户关联到企业证书中。可在https://developer.apple.com 此处申请appleId。关联成功后,在xcode - Prereferences - Accounts里,可看到账户关联的证书情况。若关联了企业证书,通常第一个为企业者账户,第二个为个人开发者证书。
1.2. 相关工具
- ideviceinstaller(可选):appium运行在真机上,需要知道目标app的bundleId。可用此工具查看。安装命令:brew install ideviceinstaller。 也可通过app代码查看得到。
- libimobiledevice:使用ios真机跑自动化,需要安装idevice_id。 安装命令:brew install libimobiledevice --HEAD 。否则,appium服务器会报错:The 'idevice_id' program is not installed. If you are running a real device test it is necessary.
- ios-deploy:若未安装,则appium服务报错:Error: Could not initialize ios-deploy make sure it is installed (npm install -g ios-deploy) and works on your system. ios-depoy使用介绍
- 重签名webdriveragent:appium使用webdriveragent与ios设备进行通信。webdriveragent为facebook的开源项目,https://github.com/facebook/WebDriverAgent,简称wda。使用真机时,若不使用开发者证书给webdriveragent重签名,运行自动化时,appium将提示:[MJSONWP] Encountered internal error running command: Error: Unable to launch WebDriverAgent because of xcodebuild failure: "xcodebuild failed with code 65". Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md. Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device. 重签名步骤总结如下:
- (此步骤不可省,直接使用WebDriverAgent里自带的WebDriverAgent.xcodeproj编译时可能会找不到依赖文件,编译失败。)使用npm的方式安装的appium,可在/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver中找到WebDriverAgent中工程。若使用dmg安装,可以cd /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent。进入目录后,执行命令:sh ./Scripts/bootstrap.sh。
-
- (后来发现WebDriverAgentLib里不需要操作也能成功,只需要操作WebDriverAgentRunner将其bundle改成唯一并编译通过即可)使用xcode打开工程WebDriverAgent.xcodeproj,如图1和图2所示,给WebDriverAgentLib和WebDriverAgentRunner重新签名。若提示bundleId不唯一,可修改bundleId为唯一后则配置完成。bundleId在WebDriverAgentLib-General-Identity-Bundle Identifier 或 WebDriverAgentRunner - BuildSettings - Product Bundle Identifier处。配置好后,分别编译WebDriverAgentLib和WebDriverAgentRunner,得到Build Succeeded。
- 若编译时连着真机,则成功后,真机上成功安装一个名为WebDriverAgentRunner的app。
1.3. 常用命令
命令
|
作用
|
---|---|
idevice_id -l | 查看已连接电脑的iPhone的 udid |
|
指定设备,查看安装的第三方应用 |
ideviceinfo -u [udid] -k DeviceName | 查看设备名 |
|
获取设备操作系统版本号 |