第1步,了解Appium 服务关键字
文档地址:https://github.com/appium/appium/blob/master/docs/cn/writing-running-appium/caps.md
第2步,在python安装相应的模块
1、appium-python-client
2、selenium
第3步,编写脚本
- iOS App启动脚本
通过desired_caps字典传递启动的client的信息,具体参数可以参考文档:Appium 服务器初始化参数(Capability)
# -*- coding: UTF-8 -*- from time import sleep from selenium import webdriver import os desired_caps = {} desired_caps['automationName'] = 'XCUITest' # Xcode8.2以上无UIAutomation,需使用XCUITest desired_caps['platformName'] = 'iOS' #系统平台 desired_caps['platformVersion'] = '10.2' #系统版本 desired_caps['deviceName'] = 'iPhone 6' #机型名称 desired_caps['bundleId'] = 'App的bundleID' #App的bundleID desired_caps['wdaLocalPort'] = '8100' #指定不同的端口,如8100,8900 以此参数实现多设备执行,不指定时默认为8100 # desired_caps['app']= os.path.abspath('/XXX/XXX.app') #使用此参数时,无需使用bundleID;会卸载原有的包,安装指定路径的app desired_caps['udid'] = '设备udid' # desired_caps['webDriverAgentUrl']='http://10.1.18.172:8100/' #url为XCTRunner启动后,给出的ServerURLHere->http://10.1.18.172:8100<-ServerURLHere,此行代码可以不写 dr = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) sleep(5) dr.quit()
注:http://127.0.0.1:4723/wd/hub 为appium 服务地址
第4步,运行脚本
1、终端中启动appium: appium -a 127.0.0.1 -p 4723
出下以下内容即为成功
[Appium] Welcome to Appium v1.6.4-beta (REV 70b1c6de0b889aabc86b1990c59994e6acb8d726)
[Appium] Non-default server args:
[Appium] address: '127.0.0.1'
[Appium] Appium REST http interface listener started on 127.0.0.1:4723
2、运行python脚本,启动脚本中的应用为成功
注意事项:
1、因 WebDriverAgentRunner app只能在ios9以上安装,所以需使用ios9以上设备做真机测试
2、可以使用此方法验证WebDriverAgentRunner是否可以正常启用:
终端中启动webDriverAgentRunner:xcodebuild -project /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination id=设备udid test
执行前最好将WebDriverAgentRunner的app在手机上删除,可能会报错
一般第一次安装会报错,可以看一下是否信任了证书后,再次执行命令行,此时可以正确启动WebDriverAgentRunner了
出现以下内容即为成功:
Test Suite 'All tests' started at 2017-02-13 14:31:59.322 Test Suite 'WebDriverAgentRunner.xctest' started at 2017-02-13 14:31:59.329 Test Suite 'UITestingUITests' started at 2017-02-13 14:31:59.333 Test Case '-[UITestingUITests testRunner]' started. t = 0.01s Start Test at 2017-02-13 14:31:59.342 t = 0.01s Set Up