1. Prerequisites
Xcode installed (with WebDriverAgent setup)
Appium installed and running
iOS devices or simulators connected and available
Maven project with dependencies set up
iOS app (.ipa or .app)
Java 11+ and JUnit 5 recommended
Unique
udidandwdaLocalPortfor each device
Maven Dependencies
<dependencies> <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>8.3.0</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.9.3</version> </dependency> </dependencies>
3. Create a Base Test Class
This handles session setup for each iOS device.
This handles session setup for each iOS device.
public class BaseIOSDriver { protected IOSDriver<MobileElement> driver; public IOSDriver<MobileElement> createDriver(String udid, int port, int wdaPort) { try { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("platformName", "iOS"); caps.setCapability("automationName", "XCUITest"); caps.setCapability("udid", udid); caps.setCapability("deviceName", "iPhone"); caps.setCapability("app", "/path/to/your.app"); caps.setCapability("wdaLocalPort", wdaPort); // Must be unique caps.setCapability("noReset", true); URL appiumServer = new URL("http://localhost:" + port + "/wd/hub"); driver = new IOSDriver<>(appiumServer, caps); return driver; } catch (Exception e) { throw new RuntimeException("Driver creation failed: " + e.getMessage()); } } }
4. Write Test Class for Each Device
You can use threads or
@ParameterizedTest with parallel configuration.public class ParallelIOSTest1 extends BaseIOSDriver { @Test public void testDevice1() { IOSDriver<MobileElement> driver = createDriver("DEVICE_UDID_1", 4723, 8100); // Your test steps System.out.println("Running on Device 1"); driver.quit(); } }
public class ParallelIOSTest2 extends BaseIOSDriver { @Test public void testDevice2() { IOSDriver<MobileElement> driver = createDriver("DEVICE_UDID_2", 4725, 8200); // Your test steps System.out.println("Running on Device 2"); driver.quit(); } }
5. Enable Parallel Execution in Maven
Create a
Create a
junit-platform.properties file inside src/test/resources/:junit.jupiter.execution.parallel.enabled=true junit.jupiter.execution.parallel.mode.default=concurrent
6. Run Tests with Maven
mvn test
Or, run specific classes in parallel:
mvn -Dtest=ParallelIOSTest1,ParallelIOSTest2 test
Things to Remember:
Each device needs its own
wdaLocalPortUse Appium servers on different ports (
4723,4725, etc.)Consider running separate Appium instances for each device:
appium -p 4723 --webdriveragent-port 8100 appium -p 4725 --webdriveragent-port 8200
No comments:
Post a Comment