天天看点

Appium -iOS真机运行自动化实践

前提:ios真机环境已安装ok

运行ios自动化的步骤如下:

步骤1、手机端安装WebDriverAgent

1、下载webdriverAgent,从github上下载代码

git clone 

https://github.com/facebook/WebDriverAgent

运行初始化脚本

./Scripts/bootstrap.sh

该脚本会使用

Carthage

下载所有的依赖,使用npm打包响应的js文件

执行完成后,直接双击打开WebDriverAgent.xcodeproj这个文件。

2、配置WebDriverAgent环境

在以下三个文件中都需要进行配置:

 (1). 编译WebDriverAgentLib

注:Bundle identifier:com.xxx.yyyyy   (xxx每个人都要不一样才行)

 (2).编译WebDriverAgentRunner

    

(3)配置 IntegrationApp

(4)

(5).在终终端输入:xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=udid' test,待执行完成后手机端会安装WebDriverAgent。

一切正常的话,手机上会出现一个无图标的WebDriverAgent应用,启动之后,马上又返回到桌面。这是很正常的不要奇怪

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

通过上面给出的IP和端口,加上/status合成一个url地址。例如

http://10.0.0.1:8100/status

,然后浏览器打开。如果出现一串JSON输出,说明WDA安装成功了。

若运行后出现:TEST Fail,如下报错:

解决:卸载手机上的 WebDriverAgentRunner程序,重新执行xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=udid' test,

在进行端口转发:

有些国产的iPhone机器通过手机的IP和端口还不能访问,此时需要将手机的端口转发到Mac上。

$ brew install imobiledevice  这里若出现以下报错,没关系,直接往下走:

$ iproxy 8100 8100

接着使用

iproxy --help

 可以查到更具体的用法。 这时通过访问

http://localhost:8100/status

确认WDA是否运行成功。

步骤二、打开appium-desktop,启动appium server+启动inspector,获取页面元素

1、StartServer

2、创建Inspector session

3、创建好session后,session的参数信息必须和当前链接的设备信息一致,否则会报错误信息,最后start session,就可以看到下图的dom树结构,如果出现图3,则说明需要重新编译运行WebdriverAgent了

步骤三、在原来框架的基础上,写Appdriver驱动

步骤四、写自动化case

ios的元素获取可以通过xpath,name,label,assessbilityid获取,上述通过name获得

步骤五、运行testng

可以看到case运行正常

参考文档:

  1. https://www.jianshu.com/p/2b4236086165
  2. https://blog.csdn.net/weixin_39142498/article/details/78950804
  3. https://testerhome.com/topics/7775
  4. https://testerhome.com/topics/4904
  5. https://testerhome.com/topics/7220
  6. https://www.cnblogs.com/yuhanle/articles/8213675.html

继续阅读