iOS 自动化环境搭建-- Appium

我们主要用Appium来进行iOS的自动化环境搭建。在安装Appium 之前需要安装必要的库和依赖库

  • 安装必要的库

1、先安装homebrew

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

但是失败的概率会很大,最终费劲千辛万苦才找到一个一次就成功的命令

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

2、安装node 和npm

brew install node brew install npm

  • 安装依赖库

brew install --HEAD ideviceinstaller brew install --HEAD libimobiledevice brew install ios-deploy brew install carthage

注意:如果没有安装 libimobiledevice,会导致Appium无法连接到iOS的设备,所以必须要安装。

  • 安装appium-doctor

npm install appium-doctor -g

  • 验证依赖

在终端输入 appium-doctor, 验证所有依赖是否安装成功,necessary必须要是打勾状态,我们不需要配置安卓的,所以安卓的报错忽略

appium-doctor

image2021-12-17_13-55-39.png

Appium

Appium可安装桌面版本,也可命令行安装,这里就介绍桌面版本的安装

到这里https://github.com/appium/appium-desktop/releases

下载安装包进行安装

Appium安装成功后,内部有个webdriveragent,路径为:

/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent

WebDriverAgent

打开WebDriverAgent.xcodeproj 工程

1、配置WebDriverAgentLib和WebDriverAgentRunner的证书

image2021-12-17_13-57-58.png

2、Scheme 选择WebDriverAgentRunner,选择安装设备

image2021-12-17_14-3-44.png

3、Product→Test

image2021-12-17_13-59-13.png

4、一切正常的话,手机/模拟器上会出现一个无图标的 WebDriverAgent 应用

image2021-12-17_14-7-38.png

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

image2021-12-17_13-59-30.png

6、此时在浏览器中打开链接http://localhost:8100/status,如果网页上返回一些json格式的数据,说明运行成功,如下图显示:

image2021-12-17_13-59-39.png

运行Appium

1、点击Start Server

image2021-12-17_13-59-48.png

2、点击右上角放大镜(Start Inspector Session)

image2021-12-17_13-59-56.png

注意:在appium 1.22.0版本服务和元素查看器分家了,查看元素信息就必须下载Appium Inspector

appium-inspector下载地址:https://github.com/appium/appium-inspector

image2021-12-22_13-49-51.png

AppiumServer参数填写:

远程主机:需要填写AppiumServer服务的主机地址,默认127.0.0.1

远程端口:需要填写AppiumServer服务的主机端口,默认4723

远程路径:appium服务器的路径,默认填写/wd/hub

假如没有填写远程路径或者远程路径报错会提示Failed to create session. The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource

3、在Desired Capabilities 中输入相关的参数


image2021-12-17_14-0-12.png

注:

当手机上没有安装App时,参数app为项目的安装路径,以此来安装项目。

当手机上已经安装过项目时,参数app可为bundleId 的值,不需要重复安装。

4、点击Start Session

image2021-12-17_14-0-25.png

5、运行成功后,会弹出一个控制界面,在该界面中可以控制手机上正在运行的程序

截屏2021-12-21 下午4.27.08.png

安装必要的库和node,npm时的坑解决方法

可参考:

https://www.jianshu.com/p/b89dd32e4b97

https://www.jianshu.com/p/1a1158ff4d0d

https://www.jianshu.com/p/d36ff3707862

安装WebDriverAgent踩坑记录

https://www.jianshu.com/p/b1fcd59999cf

Inspector踩坑记录

若WDA可正常运行,Appium上的配置项都正确, 点击Start Session 却一直无法弹出控制界面,则很大可能是手机系统版本太高,当前的Appium版本暂不支持。

可尝试使用手机系统不是当前最高的,进行调试。

利用Appium-Python-Client进行iOS的自动化测试

-------待更新-------

你可能感兴趣的:(iOS 自动化环境搭建-- Appium)