使用流程
- 编写测试文件保存成.py的python文件
from appium import webdriver - 连接手机(需要devicesid)
- 启动appium(打开软件-点击右上角启动按钮)
- 在cmd窗口,正常运行python文件
appium和uiautomator2的区别
- appium支持安卓、ios和web应用,appium是一个跨平台的工具:它允许测试人员在不同的平台(iOS,Android)使用同一套API来写自动化测试脚本,这样大大增加了iOS和Android测试套件间代码的复用性
- uiautomator2只支持安卓,方便简洁
appium功能
详见https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
- 设置安卓基本信息
desired_caps = {}
desired_caps[‘platformName’] = ‘Android’ # 平台名称
desired_caps[‘platformVersion’] = ‘8.1’ # 平台版本
desired_caps[‘automationName’] = ‘uiautomator2’ # 自动化引擎
desired_caps[‘deviceName’] = ‘824f6ab8’ # 设备devices id
desired_caps[‘app’] = PATH(’…/…/…/apps/selendroid-test-app.apk’) # app路径
driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps) # 新建连接
driver.quit() # 退出连接 - 设置ios基本信息
desired_caps = {
desired_caps[‘platformName’] = ‘iOS’
desired_caps[‘platformVersion’] = ‘11.4’
desired_caps[‘automationName’] = ‘xcuitest’
desired_caps[‘deviceName’] = ‘iPhone Simulator’
desired_caps[‘app’] = PATH(’…/…/apps/UICatalog.app.zip’)
}
driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)
driver.quit() - 以上两种方式均可使用