Professional Documents
Culture Documents
学习目标:
1. 能够搭建 iOS 自动化测试所需要的环境
2. 能够使用模拟器进行 iOS 自动化测试
3. 能够使用真机进行 iOS 自动化测试
一. 环境搭建
应用场景
需要的环境
员
macOS 系统电脑
10.13.6
序
Xcode
10.1
打开 app store 搜索 Xcode 并下载
程
马
待测试的 iOS 项目
找开发人员
-黑
appium Desktop
1.10
客
https://github.com/appium/appium-desktop/releases/download/v1.10.0/Appium-1.10.
0.dmg
播
python
3.6.1
智
https://www.python.org/ftp/python/3.6.1/python-3.6.1-macosx10.6.pkg
传
pycharm
Professional 2018.2.2
https://www.jetbrains.com/pycharm/download
node.js
10.5.0
https://npm.taobao.org/mirrors/node/v10.15.0/node-v10.15.0.pkg
cnpm
5.2.0
ios-deploy 依赖库
brew
黑马程序员-软件测试
1.9.1
libimobiledevice 依赖库
可能出现的问题
解决方法:
brew update
brew uninstall --ignore-dependencies libimobiledevice
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
员
brew unlink usbmuxd
brew link usbmuxd
序
brew install --HEAD libimobiledevice
carthage 依赖库
程
马
brew install carthage
-黑
iOS 系统手机
iOS 12.1.2
Apple ID
客
https://appleid.apple.com/account#!&page=create
播
WebDriverAgent
https://github.com/facebook/WebDriverAgent
智
点击 download zip
配置 WebDriverAgent 的内容会在真机自动化是进行讲解
传
二. 使用模拟器进行自动化测试
2.1 运行 iOS 程序到模拟器
步骤
1. 使用 Xcode 打开要运行的程序
2. 选择将要运行的 程序 和 模拟器设备
3. 快捷键 command + r 运行
步骤
1. 打开 appium
2. 启动 appium
3. 左上角菜单栏选择 appium - new session window
黑马程序员-软件测试
员
序
程
马
-黑
4. 填写对应的启动参数,并启动
客
播
智
传
2.3 编写和运行自动化脚本
前置代码
黑马程序员-软件测试
from appium import webdriver
desired_caps = dict()
desired_caps['platformName'] = 'iOS'
desired_caps['platformVersion'] = '12.1'
desired_caps['deviceName'] = 'iPhone 8'
desired_caps['app'] = 'com.itcast.HMiOSTest'
需求
1. 点击按钮 进入列表
2. 获取所有列表的文字内容并输入
3. 滑动一次
4. 点击 20
5. 清空文本框内容
员
6. 在文本框中输入 “hello”
7. 单击返回按钮
序
核心代码
time.sleep(1) 程
马
driver.find_element_by_id("进入列表").click()
-黑
time.sleep(1)
eles = driver.find_elements_by_class_name("XCUIElementTypeStaticText")
for i in eles:
客
print(i.text)
播
time.sleep(1)
# 无法使用
智
time.sleep(1)
driver.find_element_by_xpath("//*[@name='20']").click()
time.sleep(1)
text_view = driver.find_element_by_class_name("XCUIElementTypeTextField")
text_view.clear()
time.sleep(1)
text_view.send_keys("hello!!!")
time.sleep(1)
driver.find_element_by_xpath("//XCUIElementTypeButton[@name='Back']").click()
黑马程序员-软件测试
time.sleep(1)
注意点
2. 在模拟器中可以连接电脑的键盘进行输入,但是如果连接,appium 将无法工作,所以需要
消选 Connect Hardware Keyboard
员
序
程
马
-黑
客
播
智
传
三. 使用真机进行自动化测试
3.1 运行 iOS 程序到真机
步骤
3.2 配置 WebDriverAgent
步骤
黑马程序员-软件测试
1. 进入到下载的 WebDriverAgent 项目下
2. 输入命令 ./Scripts/bootstrap.sh
3. 启动 WebDriverAgent.xcodeproj
4. 配置 WebDriverAgentLib 的开发者信息
员
序
5. 配置 WebDriverAgentRunner 的开发者信息
6. 配置 IntegrationApp 的开发者信息
程
7. 修改 WebDriverAgentRunner 的 Product Bundle Identifier
马
-黑
客
播
智
传
11. 使用 command + u 运行
稍等之后会在log中出来一个 url 地址
在浏览器中打开这个地址,如果显示一串 json 数据即为正确连接手机
并且,真机会多一个程序
12. 将配置好的 WebDriverAgent 项目替换到 appium 的 WebDriverAgent 项目
打开 finder
快捷键 command + shift + g
黑马程序员-软件测试
输入路径 /Applications/Appium.app/Contents/Resources/app/node_modules/appium-
xcuitest-driver
回车
将旧项目换个名字,当做备份
将配置好的项目放在这个目录下
3.3 运行自动化脚本
步骤
1. 修改对应的 platformVersion、deviceName
2. 查看 udid 并增加为启动参数
3. 运行即可
附录. 参考资料
https://gochannel.org/links/link/snapshot/4307
员
https://testerhome.com/topics/6962
https://blog.csdn.net/weixin_35825766/article/details/80655296
序
https://blog.csdn.net/yjs_13597468160/article/details/80635761
https://testerhome.com/topics/14911
https://www.jianshu.com/p/1ec36db7d551
程
马
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/touch-actions.
-黑
md#bugs-and-workarounds
客
播
智
传
黑马程序员-软件测试