import os
from appium import webdriver
# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(__file__), p))
desired_caps = dict()
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '8.0'
desired_caps['deviceName'] = 'DU3ADH14C40XXXX'
# desired_caps['app'] = PATH('../xx.apk')
desired_caps['appPackage'] = 'com.tencent.mm'
desired_caps['appActivity'] = 'com.tencent.mm.ui.LauncherUI'
desired_caps['dontStopAppOnReset'] = True # 不关闭应用
desired_caps['autoGrantPermissions'] = True # 自动获取权限
desired_caps["noReset"] = True # 不用每次重置
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
更多初始化参数见:
更多?见:https://github.com/appium/appium/tree/master/sample-code/python