I am trying to run test methods parallel in Appium+testNG on different devices. It works for me when I run test methods parallel based on classes ie parallel=classes.
But same is not working when I try to run test methods parallel based on methods ie parallel=methods. I am using below code to run parallel.
@BeforeMethod(alwaysRun = true)
public void setdeviceName() throws Exception {
if (ConfigUtil.getConfigDetails().split("::")[1].equalsIgnoreCase(“device”)) {
synchronized (DeviceEmuList) {
deviceName = DeviceEmuList.get(0);
System.out.println("###########This is the device name###############" + deviceName);
DeviceEmuList.remove(0);
port = Integer.parseInt((String) portList.get(0));
portList.remove(0);
System.out.println("inside setup" + deviceName + port);
driver = new DriverManager().getdriver(new Object[] { deviceName, port });
}
}
}
@AfterMethod(alwaysRun = true)
public void takeSS() {
driver.quit();
DeviceEmuList.add(this.deviceName);
portList.add(String.valueOf(this.port));
}
When I use above code, then app launches on first device then on second device and all test methods run only on second device. None of the test methods are running on first device. This looks like i am running test methods serially on second device.
Same logic works fine when I am creating driver in @BeforeClass.