How to run one script on two real devices at same time?

Hi friends,
I was working on creating a framework for our project. Our project is about ridesharing transportation like Ola Uber etc

We have two apps one for user and one for driver to accept ride and both should work with one script.

How do I run it successfully?
Shall I use only one device for both apps or shall I use two separate devices for these apps?

#emulator/simulator or real devices

It is all depends on your tests. If most of your tests include interaction with both apps and you switching between them often -> better use 2 devices = use of 2 drivers with 2 Appium servers.

Otherwise, only few tests with both apps, better use one driver and switch between apps on one device.

Thanks @Aleksei
It looks simple now… Will implement what you have suggested and will post here the update…
Thanks once again…:hugs:

One doubt i had. How can I use two servers here?
Pls help me with a sample script or a link may be …

same as one server. run each server with it unique port. open drivers against appropriate server with right port.

also note that you should have in driver capabilities other unique ports so drivers to work in parallel correctly. see ->

e.g. for android drivers should have unique:

  • chromedriverPort (if you use web)
  • mjpegServerPort (if you use recording test)
  • systemPort

Hi @Aleksei,

We decided to use two diff devices to run both of our apps. I have tried with following code, can you pls suggest me what things are missing here?

import java.time.Duration;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.GeneralServerFlag;

public class BaseClass {

public static AppiumDriverLocalService service;

public static String nodeExePath = "C:\\Program Files\\nodejs\\node.exe";

public static String nodeJsMainPath = "C:\\Users\\ptmco\\AppData\\Roaming\\npm\\node_modules\\appium\\build\\lib\\main.js";

public static String serverAddress = "";

public AndroidDriver driver, driver1;

public String rideOtp = "";

public void startAppiumServer(String portNumber) throws MalformedURLException, InterruptedException {
	service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingDriverExecutable
			(new File(nodeExePath)).withAppiumJS(new File(nodeJsMainPath)).withIPAddress(serverAddress).withArgument(GeneralServerFlag.BASEPATH, "/wd/hub")
			.usingPort(Integer.parseInt(portNumber)).withLogFile(new File("C:\\Users\\ptmco\\Desktop\\AppiumServerLog.txt")));
	System.out.println("Appium Server Started with port "+portNumber);


public void launchApp(String deviceName, String portNumber, String udid, String app) throws MalformedURLException, InterruptedException {
	DesiredCapabilities cap = new DesiredCapabilities();
	cap.setCapability("platformName", "Android" );
	cap.setCapability("deviceName", deviceName);
	cap.setCapability("udid", udid);
	cap.setCapability("automationName", "UIAutomator2");
	cap.setCapability("fullReset", true);
	cap.setCapability("app", app);
	driver = new AndroidDriver(new URL(""+portNumber+"/wd/hub/"), cap);
	DesiredCapabilities cap1 = new DesiredCapabilities();

	cap1.setCapability("platformName", "Android" );
	cap1.setCapability("deviceName", deviceName); cap1.setCapability("udid","15913008960024W"); cap1.setCapability("automationName", "UIAutomator2");
	cap1.setCapability("fullReset", true); //to uninstall the app after testing
	cap1.setCapability("udid", udid);
	cap1.setCapability("automationName", "UIAutomator2");
	driver1 = new AndroidDriver(new URL(""+portNumber+"/wd/hub/"), cap1);

public void tearDown() {
	if(service.isRunning()==true) {
		System.out.println("Appium Server Stopped !");

public void scrollToText(String text) {
	driver.findElement(new AppiumBy.ByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0))"
			+ ".scrollIntoView(new UiSelector()" + ".textMatches(\"" +text+ "\").instance(0))"));


You should have 2 services! Same as 2 drivers.

1 Like

Sure thank you… ill try implementing the same