Search code examples
androidseleniumselenium-webdriverappium

How Run Appium for two Android devices connected to windows laptop


I have windows 7 laptop connected to two android devices and I am trying to run my Appium script so that both the devices install the app. Not sure how to do it. Below is the code which runs fine when only Android device is connected. But my target is to run script in both the devices. Can anyone please help. I am starting the Appium server with command prompt -- node appium

@Test
public void installapp() {
    File app = new File("App\\app_US_IT_Ananta.apk");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName","Android Emulator");
    capabilities.setCapability("platformVersion", "4.4");
    capabilities.setCapability("autoAcceptAlerts", true);
    capabilities.setCapability("app", app.getAbsolutePath());
    try {
        driver1 = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    driver1.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
    WebDriverWait wait = new WebDriverWait(driver1, 30);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("com.android.packageinstaller:id/permission_allow_button")));
    driver1.findElement(By.id("com.android.packageinstaller:id/permission_allow_button")).click();
}

Solution

  • You would need to start multiple Appium servers and each of them should have separate Appium port and device id, either from command prompt or from the GUI version. After that you can either use Java Threads or TestNG etc to run parallel tests. The link below provides a basic implementation -

    http://www.automationtestinghub.com/appium-parallel-execution/