I have appium 2.0 java project thats works in one thread and everyfing is ok, but when I start to use a few devices all set ups is ok, but tests isnt started, only app started, for test using PageFactory. I set ports and udid
s in my code with methods
`public class Base extends SetDrivers {
@BeforeClass
public void setDriverToApp() throws IOException {
List<Devices> devices = getAllConnectedDevices();
for (Devices device : devices) {
if (device.getPlatformName().equalsIgnoreCase("ios")) {
SetDrivers.setIOSDriver(device);
} else if (device.getPlatformName().equalsIgnoreCase("android")) {
SetDrivers.setAndroidDriver(device);
} else {
System.out.println("No devices connected");
}
}
}
}`
I iterate all connected devices and send it udid to its driver
` public static AppiumDriver getDriver() {
return driver.get();
}
public static void setDriver(AppiumDriver driver) {
SetDrivers.driver.set(driver);
}
public static ThreadLocal<AppiumDriver> driver = new ThreadLocal<>();`
` public static int getFreePort() throws IOException {
ServerSocket socket = new ServerSocket(0);
int port = socket.getLocalPort();
socket.close();
return port;
}
public static void setIOSDriver(Devices device) throws IOException {
var xcuiTestOptions = new XCUITestOptions();
xcuiTestOptions.setPlatformName("IOS");
xcuiTestOptions.setUdid(device.getUdid());
xcuiTestOptions.setFullReset(false);
xcuiTestOptions.setWdaLocalPort(getFreePort());
xcuiTestOptions.setApp(System.getProperty("user.dir") + "app.ipa");
xcuiTestOptions.setCapability("appium:xcodeOrgId", "xxxxx");
xcuiTestOptions.setCapability("appium:xcodeSigningId", "xxxx");
setDriver(new IOSDriver(service.getUrl(), xcuiTestOptions));
setHelpers(getDriver());
}
public static void setAndroidDriver(Devices device) throws IOException {
var uiAutomator2Options = new UiAutomator2Options();
uiAutomator2Options.setPlatformName("Android");
uiAutomator2Options.setApp(System.getProperty("user.dir") + "//app.apk");
uiAutomator2Options.setFullReset(false);
uiAutomator2Options.setUdid(device.getUdid());
uiAutomator2Options.setSystemPort(getFreePort());
uiAutomator2Options.setMjpegServerPort(getFreePort());
uiAutomator2Options.setChromedriverPort(getFreePort());
uiAutomator2Options.setUnlockType("pin");
uiAutomator2Options.setUnlockKey("xxxx");
uiAutomator2Options.setCapability("skipChromeDownload", false);
uiAutomator2Options.setCapability("appium:testTagsAsResourceId", true);
uiAutomator2Options.setCapability("appium:disableIdLocatorAutocompletion", true);
uiAutomator2Options.setCapability("appium:enableMultiWindows", true);
uiAutomator2Options.setCapability("appium:allowInvisibleElements", true);
setDriver(new AndroidDriver(service.getUrl(), uiAutomator2Options));
setHelpers(getDriver());
}`
testng xml sample is:
<test name="Device 1" >
<classes>
<class name="tests.testpackage.Test"/>
</classes>
</test>
<test name="Device 2" >
<classes>
<class name="tests.testpackage.Test"/>
</classes>
</test>
<test name="Device 3" >
<classes>
<class name="tests.testpackage.Test"/>
</classes>
</test>
Get error org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up