简介
Quamotion是一个可用于原生、hybrid和移动Web端的自动化测试框架,可以自动化安卓、IOS的真机和模拟器。Quamotion具有如下几个优点:
- 支持Windows、Linux、Mac操作系统。
- 不用重新编译和修改APP,可以利用各个平台内置的自动化平台工具实现自动化你的APP。
- 支持多种编程语言实现WebDriver,例如Java、Python、PowerShell、C#等。
- 可以兼容支持这些语言的测试框架。
缺点:
要收费,下载安装包不方便。
官方文档:http://docs.quamotion.mobi/webdriver/
安装
此文是在IMac IOS下:
# 需要openssl
brew update
brew install openssl
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
# 下载驱动
mkdir quamotion-webdriver
cd quamotion-webdriver
wget http://cdn.quamotion.mobi/download/quamotion-webdriver.0.123.3.osx.10.10-x64.tar.gz
tar -xvzf quamotion-webdriver.0.123.3.osx.10.10-x64.tar.gz
# 启动
然后就可以访问Web控制台了:http://localhost:17894
,需要安装license
,点击“Send Request”按钮,填好信息,就会收到一个license
下载地址。下载并上传license
。
连接IOS设备并打开UI自动化:
在IPhone里打开首页,信任设备,然后访问http://localhost:17894/Home/Devices
。
在iPhone 设置里,打开开发设置(Developer setting
),并切换到打开Enable UI Automation
。
永不锁屏
在iPhone设置里,显示与亮度(Display and Brightness),亮度(Auto-Brightness)调到最小,自动锁定(Auto Lock)改为永不(Never)。
安装IOS开发工具XCode
安装最新版本的XCode。
切换到/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
目录,并创建包含这些内容的zip压缩包,把zip压缩包拷贝到Windows PC。
在PC上,切换目录到yourwebdriverfolder
,创建文件夹devimg
,把zip包解压到这个目录下。
测试代码
这里以Python为例,首先要安装依赖:
pip install selenium
pip install
实例代码:
import quamotion
# 创建一个session,参数是设备的UDID。
driver = quamotion.device('72157b76f677f22c98864d62307fdff9d56fa62a')
# 等待
driver.implicitly_wait(60000)
# 进入首屏
driver.home_screen()
# 打开应用
driver.find_element_by_link_text('Safari').click()
# 获取文本框
urlTextField = driver.find_element_by_class_name('XCUIElementTypeTextField')
urlTextField.clear();
# 给文本框填入内容
urlTextField.send_keys('itms-apps://itunes.apple.com/us/app/apple-store/id304878510')
urlTextField.send_keys('\n')
# xpath查找元素
driver.find_element_by_xpath("//XCUIElementTypeButton[@label='GET']").click()
driver.find_element_by_xpath("//XCUIElementTypeButton[@label='INSTALL']").click()
driver.find_element_by_xpath("//XCUIElementTypeButton[@label='OPEN']").click()
# 关闭弹窗
driver.switch_to_alert().accept()
# 退出
driver.quit()
参考
http://docs.quamotion.mobi/webdriver/configuration/ios/https://github.com/quamotion/python