开启iOS自动化测试之门

开启iOS appium自动化测试之门

Appium介绍

Appium是一个开源、跨平台的测试框架,可以用来测试原生及混合的移动端应用。Appium支持iOS、Android及FirefoxOS平台。Appium使用WebDriver的json wire协议,来驱动Apple系统的UIAutomation库、Android系统的UIAutomator框架。Appium对iOS系统的支持得益于Dan Cuellar’s对于iOS自动化的研究。Appium也集成了Selendroid,来支持老android版本。

Appium进行自动化测试的两个好处

(1) Appium在不同平台中使用了标准的自动化APIs,所以在跨平台时,不需要重新编译或者修改自己的应用。这里,跨平台的意思是指可以在不同的系统上用相同的方式编写测试脚本,而不是指用于Android系统的测试脚本可以完全不用修改的应用于iOS系统上。事实上,Android和IOS应用几乎需要独立的进行编写。

(2)Appium支持Selenium WebDriver支持的所有语言,如java、Object-C、JavaScript、PHP、Python、Ruby、C#、Clojure,或者Perl语言,更可以使用Selenium WebDriver的Api。Appium支持任何一种测试框架。如果只使用Apple的UIAutomation,我们只能用javascript来编写测试用例,而且只能用Instruction来运行测试用例。同样,如果只使用Google的UIAutomation,我们就只能用java来编写测试用例。

Appium的系统需求

Android自动化测试可以在Windows、Mac、Linux上进行,需要安装Android SDK、Node等工具。而iOS的自动化由于需要Xcode的支持,只能在Mac上运行,需要安装Xcode、Node等工具。此外,由于appium ios自动化的底层使用的是UI Automation,因此在使用appium之前必须搭建iOS开发环境。

一、搭建appium环境

目前Appium测试iOS设备,要求Mac操作系统最低版本mac OS 版本10.7,本机使用的开发环境是Xcode 9.4.1, Mac x 10.13.3由于时间有限下文截图可能不太清晰,请谅解。

1. 安装brew

在终端输入命令 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. 安装libimobiledevice

brew install libimobiledevice --HEAD

3. 安装carthage

brew install carthage

4. 安装node.js ,https://nodejs.org/en/download/, 下载.pkg文件安装
5. 安装cnpm https://npm.taobao.org/

npm install -g cnpm --registry=https://registry.npm.taobao.org

6. 安装ios-deploy

sudo cnpm install -g ios deploy

7. 安装xcpretty 

gem install xcpretty

安装版本为xcpretty-0.3.0

8. 安装appium1.10.0

sudo cnpm install -g [email protected]

9. 安装appium-xcuitest-driver依赖 

9.1 安装WebDriverAgent

首先要搭建WebDriverAgent编译环境,首先需要安装如下的软件:

• Homebrew
• carthage
• python
• node.js
• Xcode8.0+(IOS9.3,Xcode8.0+才能正常编译)

安装Homebrew

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

安装WebDriverAgent

使用git clone命令将WebDriverAgent项目克隆到本地

git clonehttps://github.com/facebook/WebDriverAgent

9.2 安装appium-xcuitest-driver依赖进入WebDriverAgent安装目录运行bootstrap

cd/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent

mkdir -p Resources/WebDriverAgent.bundle//执行脚本
sh ./Scripts/bootstrap.sh

如果出现报错,则关闭终端再打开,执行

10. 下载WebDriverAgent-master
10.1 Xcode打开WebDriverAgent.xcodeproj,修改配置:

选择菜单files->open,路径/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent

10.2 双击WebDriverAgentLib设置后进行编译

按如下进行修改

Bundle ID改为com.ming.wda.WebDriverAgentLib

修改配置WebDriverAgentRunner后编译

11. 真机的udid通过iTunes——摘要,点击序列号,出现UDID,右键拷贝即可。

安装appium-python-client

二、运行与测试

12. Xcode菜单栏选择目标设备Scheme选择WebDriverAgentRunner最后运行 Product -> Test一切正常的话,手机上会出现一个无图标的WebDriverAgent应用,启动之后,马上又返回到桌面。这是正常的。

此时控制台界面可以看到设备的IP。如果看不到的话,使用这种方法打开view-debug area-activate console

出现上图表示成功了

13. 安装appium-doctor

确定所有依赖是否安装成功,可通过appium-doctor验证,首先安装appium-doctor(sudo npm install -g appium-doctor),然后在终端运行appium-doctor,如下图,都是打状态就证明环境正常

14. brew install HEAD libimobiledevice

15. 运行appium

终端执行 appium p 4723

三、启动APP

第一步,Xcode打开WebDriverAgentRunner,scheme选择它,菜单Project->Test,build成功后在手机里装上WebDriverAgent;第二步,手机连接Mac电脑第三步,启动Appium desk,start desired session

就可以自动测试App了

猜你喜欢

转载自www.cnblogs.com/fengye151/p/11518415.html