Running test case with multiple devices (Appium + Java)

I’m trying to run a test case with multiple devices. I am attempting to write it using standard Appium + Java approach, but I am constantly running into not finding the Android device. Here is the simplified code I am using:

import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
import io.appium.java_client.android.AndroidDriver;


ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/C", "appium");
logfile = "appiumDevice" + "_" + <deviceName> + ".log";
builder.redirectOutput(new File(logfile));
builder.redirectError(new File(logfile));
Process p = builder.start();
p.waitFor(10, TimeUnit.SECONDS);

DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability("deviceName", <deviceName>);
capability.setCapability("platformVersion", <OS>);
capability.setCapability("platformName", "Android");
capability.setCapability("udid", <udid>);
File file = new File(<Path>);
capability.setCapability("app", file.getAbsolutePath());
capability.setCapability("noReset", true);
capability.setCapability("launch", true);
capability.setCapability("appPackage", <package>);
capability.setCapability("newCommandTimeout", "60000");
capability.setCapability("appWaitActivity", <activity>);

AndroidDriver driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capability);

driver.quit();

The error I get is:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not find a connected Android device. (WARNING: The server did not provide any stacktrace information)

it is hard to say what is wrong since the error message mentioned that there is no devices. Could you double check on the devices setup?

Turns out the issue was due to incorrect path to the ANDROID HOME and missing build-tools (aapt.exe). Changing that fixed the issue, now I can run multiple phones using the same test case!

1 Like