一、连接手机,安装App
首先要开启一个appium服务
appium --no-reset -p 4724 --session-override,端口号和脚本中的端口号一致
def __init__(self):
desired_caps = {}
desired_caps['app'] = appDir
desired_caps['deviceName'] = "iPhone 7P"
desired_caps['platformName'] = "IOS"
desired_caps['platformVersion'] = '13.5.1'
desired_caps['udid'] = "xxxxxxxxx"
desired_caps['automationName'] = 'XCUITest'
desired_caps['xcodeOrgId'] = "xxxxxx"
desired_caps['xcodeSigningId'] = "iPhone Developer"
desired_caps['noReset'] = False
desired_caps['locationServicesEnabled'] = True
desired_caps['locationServicesAuthorized'] = True
desired_caps['showiOSLog'] = True
self.driver = webdriver.Remote(command_executor="http://127.0.0.1:4724/wd/hub", desired_capabilities=desired_caps)
其中:
appDir app的路径
udid 手机的udid
xcodeOrgId 开发者id
noReset false为每次运行脚本都会重置App,即卸载后重置
二、运行App
1.一般第一次打开会申请一些权限
if self.elementExist(By.NAME, "允许"):
self.driver.find_element_by_name("允许").click()
if self.elementExist(By.NAME, "使用App时允许"):
self.driver.find_element_by_name("使用App时允许").click()
if self.elementExist(By.NAME, "允许"):
self.driver.find_element_by_name("允许").click()
```