- Install Node.js v16:
nvm install 16(use NVM) - Install JDK: b
rew install openjdk@11 - Install Appium Server:
npm i -g appium - Install xcuitest driver:
appium driver install xcuitest - Install the Command Line Tools:
xcode-select--install - Install Appium-Doctor:
npm install -g appium-doctor - Run Appium-Doctor to check dependencies:
appium-doctor
- Open Xcode and log in Apple ID
- Clone WebDriverAgent:
git clone https://github.com/appium/WebDriverAgent.git - Build WebDriverAgent App on your real device
- Open
WebDriverAgent.xcodeprojfrom the download folder - Build
WebDriverAgentRunnertarget on your device - Select
WebDriverAgentfile and selectWebDriverAgentRunnertarget - Select your team and modify Bundle identifier(just add some strings should be OK)
- Select
IntergrationApptarget, select your team and modify Bundle identifier(just add some strings should be OK) - Build
IntergrationAppon your device
- Open
- Disable auto-lock on your device: Settings > Display & Brightness > Auto-Lock > Never
- Trust the developer: Settings > General > VPN&Device Management
- In case of any OS upgrade(iOS), the framework gets disturbed as the other apps(Appium version/xcode/mac os) become unsupported.
- We might get errors like
Unable to launch WebDriverAgent because of xcodebuild failure: xcodebuild failed with code 65orA valid provisioning profile for this executable was not found. - Check the signing and capabilities for webdriveragentrunner and webdriveragentlib, it should be signed in using a proper developer account
- Try running the tests again and check if the error isn’t coming anymore. In case the same errors still comes we need to do the next steps mentioned below
- In such cases we can download the latest webdriver agent from
https://github.com/appium/WebDriverAgent/releases - Then delete all files except Build folder from
.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent - From the downloaded folder we can copy all files and paste inside the
.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragentfolder - It should work
- If the test still unable to connect to the device try using ios-webkit-debug-proxy
- Install
brew install ios-webkit-debug-proxy - Run
ios_webkit_debug_proxy -c [Devic udid]:27753 - Run your test
- Enable Web Inspector: Go to Settings > Safari > Advanced > Web Inspector
- Check Safari elements:
- Open Safari app on your phone and connect it with Mac machine
- Open desktop Safari and enable developer mode: Settings > Advanced > Check "Show features for web developers"
- Go to desktop Safari's developer menu, find your device and open the web in Safari
- Check the web elements
- Run
appium -p 4724 --driver-xcuitest-webdriveragent-port=8201 - Run
appium -p 4725 --driver-xcuitest-webdriveragent-port=8200 - Install
pytest-xdist - Add
addopts = -n2inpytest.ini - Update
conftest.py@pytest.fixture(params=["device1", "device2"], scope="function") def appium_driver(request): if request.param == "device1": capabilities = { 'deviceName': 'SDET-iPhone12-red', 'platformName': 'iOS', 'automationName': 'xcuitest', 'platformVersion': '17.1', 'udid': '00008101-000C31160E80001E', 'bundleId': 'com.louis.IntegrationApp' } driver = webdriver.Remote('http://localhost:4724', options=XCUITestOptions().load_capabilities(capabilities)) if request.param == "device2": capabilities = { 'deviceName': 'iPhone 15', 'platformName': 'iOS', 'automationName': 'xcuitest', 'platformVersion': '17.0.1', 'udid': '219F6608-97BB-4A7A-8362-8733D9EE0C8C', 'bundleId': 'com.louis.IntegrationApp' } driver = webdriver.Remote('http://localhost:4725', options=XCUITestOptions().load_capabilities(capabilities)) yield driver time.sleep(2) driver.quit() - Run the test
def test_contacts(appium_driver): driver = appium_driver driver.implicitly_wait(10) driver.find_element(by=AppiumBy.ID, value='Attributes').click()
- Swipe left to find Settings App
action = TouchAction(driver)
i = 0
while not driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Settings').is_displayed():
action.press(x=24, y=172).wait(2000).move_to(x=285, y=172).perform()
i += 1
print(f'Swipe count: {i}')- Toggle Switch
driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Switches').click()
toggle = driver.find_element(by=AppiumBy.IOS_CLASS_CHAIN, value='**/XCUIElementTypeSwitch[`value == "1"`][1]')
if toggle.get_attribute('value') == '1':
toggle.click()- Handle steppers
# increase to 5
driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Steppers').click()
count = driver.find_element(by=AppiumBy.XPATH, value='//XCUIElementTypeStaticText[@name="0"][1]')
stepper = driver.find_element(by=AppiumBy.XPATH, value='(//XCUIElementTypeButton[@name="Increment"])[1]')
while count.get_attribute('value') != '5':
stepper.click()- Adjust slider
driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Sliders').click()
driver.find_element(by=AppiumBy.XPATH, value='//XCUIElementTypeCell[1]/XCUIElementTypeSlider').send_keys('0.6')
print(driver.find_element(by=AppiumBy.XPATH, value='//XCUIElementTypeCell[1]/XCUIElementTypeSlider').get_attribute('value'))