- 使用Appium的“before”钩子将权限重置为用户允许:
from appium import webdriver
desired_cap = {
"platformName": "iOS",
"platformVersion": "14.2",
"deviceName": "iPhone 12 Pro",
"app": "myApp.app",
"automationName": "XCUITest"
}
driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_cap)
def reset_permissions():
driver.execute_script('mobile: terminateApp', {'bundleId': '<Your bundle id here>'})
driver.execute_script('mobile: launchApp', {'bundleId': '<Your bundle id here>'})
allow_access_button = driver.find_element_by_id('<Your allow access button id here>')
allow_access_button.click()
def before_feature(context, feature):
reset_permissions()
- 使用Appium的TouchAction来模拟用户点击“允许”按钮:
from appium.webdriver.common.touch_action import TouchAction
allow_access_button = driver.find_element_by_id('<Your allow access button id here>')
touch_action = TouchAction(driver)
touch_action.tap(allow_access_button).perform()