To connect an iOS device with Appium for mobile automation testing, you need to set up your environment properly. Here's a step-by-step explanation:
System Requirements
| Requirement | Details |
|---|---|
| OS | macOS (Appium for iOS requires Xcode) |
| iOS Device | Real device with Developer Mode enabled |
| Xcode | Installed from Mac App Store |
| Appium | Install via NPM or App |
| Node.js | Required for Appium |
| Carthage | Required for WebDriverAgent |
| USB Cable | To connect your iOS device |
| Apple Developer ID | For signing WebDriverAgent |
Step-by-Step Setup
1. Install Prerequisites
Open Terminal and install the following:
brew install carthage npm install -g appium npm install -g ios-deploy
2. Enable Developer Mode on iPhone
Plug in the iPhone.
On the phone, tap Trust this computer.
Open Xcode > Devices and Simulators and ensure your device appears.
3. Create and Build WebDriverAgent
WebDriverAgent (WDA) is used by Appium to interact with iOS.
Clone WebDriverAgent or use Appium’s default one located at:
/usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent
- Open
WebDriverAgent.xcodeprojin Xcode. Set Development Team under Signing & Capabilities for both:
WebDriverAgentLibWebDriverAgentRunnerSelect your device as the build target.
Build the project using Xcode (
⌘ + B).
appium
appium --port 4723
{ "platformName": "iOS", "platformVersion": "16.0", "deviceName": "iPhone 13", "udid": "<your_device_udid>", "automationName": "XCUITest", "bundleId": "com.apple.Preferences", // or your app's bundle id "xcodeOrgId": "<your_team_id>", "xcodeSigningId": "iPhone Developer", "updatedWDABundleId": "com.yourcompany.WebDriverAgentRunner" }
idevice_id -l
import io.appium.java_client.ios.IOSDriver; import io.appium.java_client.remote.IOSMobileCapabilityType; import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.URL; public class IOSAppiumTest { public static void main(String[] args) { try { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS"); caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "16.0"); // your iOS version caps.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 13"); // or "iPhone" caps.setCapability(MobileCapabilityType.UDID, "your_device_udid_here"); caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest"); caps.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.Preferences"); // Open Settings app caps.setCapability("xcodeOrgId", "YOUR_TEAM_ID_HERE"); // from Apple Developer account caps.setCapability("xcodeSigningId", "iPhone Developer"); caps.setCapability("updatedWDABundleId", "com.yourcompany.WebDriverAgentRunner"); // Start Appium session IOSDriver driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps); // Example: Interact with the Settings app System.out.println("App launched on iOS device successfully!"); // Always quit the driver after test driver.quit(); } catch (Exception e) { e.printStackTrace(); } } }
<dependencies> <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>8.5.1</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.12.0</version> </dependency> </dependencies>