第1步,了解Appium 服务关键字
文档地址:https://github.com/appium/appium/blob/master/docs/cn/writing-running-appium/caps.cn.md
第2步,在python安装相应的模块
1、appium-python-client
2、selenium
第3步,编写脚本
#-*- coding: UTF-8 -*-
from time import sleep
from selenium import webdriver
desired_caps={}
desired_caps[‘automationName‘]=‘XCUITest‘ #Xcode8.2以上无UIAutomation,需使用XCUITest
desired_caps[‘platformName‘]=‘iOS‘
desired_caps[‘platformVersion‘]=‘10.2.1‘
desired_caps[‘deviceName‘]=‘iPhone 5‘
desired_caps[‘app‘]=‘xxx.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()
第4步,运行脚本
1、终端中启动webDriverAgentRunner:xcodebuild -project /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination id=设备udid test
出现以下内容即为成功
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
2、终端中启动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
3、运行python脚本
注意事项:
因 WebDriverAgentRunner app只能在ios9以上安装,所以需使用ios9以上设备做真机测试