Since I’ve encountered known issues with the WebDriverAgentRunner on appium 1.22.x and Xcode 14 I’ve decided to move over to Appium 2.0. I currently have a cross platform setup for Android and iOS, using PageFactory, where the driver is conditionally instantiatied as an AndroidDriver or IOSDriver, depending on the needs of the test. The setup uses the appium Java client.
With that said, all mobile actions I have are executed by the parent AppiumDriver class, however this is no longer possible on Appium 2.0. I would like to ask for advice on what are the best practices to migrate this cross platform testing project to work in the same manner on Appim 2.0 with the new requirements for driver instantiation and mobile actions. This is the code that has been initiating the driver until now:
public void initializeDriver(String browserstackAppIdentifier) throws Exception {
AppiumDriver appiumDriver;
String environment = System.getProperty("ENV");
URL serverUrl;
String platformName = determinePlatformName(environment);
Properties allProperty = PropertyLib.getAllProperty();
if (PropertyLib.isEnvironmentDevelopment(environment)) {
serverUrl = ServerLib.getServer().getUrl();
} else if (PropertyLib.isEnvironmentCi(environment)) {
serverUrl = new URL(String.format("http://%s:%s@%s/wd/hub", allProperty.getProperty("username"), allProperty.getProperty("accessKey"), allProperty.getProperty("browserstackServer")));
} else {
throw new Exception("Unexpected environment");
}
assert platformName != null : "Platform name is not defined";
if (platformName.equals("android")) {
appiumDriver = new AndroidDriver(serverUrl, CapabilityLib.getAllCapability(browserstackAppIdentifier));
driver.set(appiumDriver);
} else if (platformName.equals("ios")) {
appiumDriver = new IOSDriver(serverUrl, CapabilityLib.getAllCapability(browserstackAppIdentifier));
appiumDriver.setSetting("boundElementsByIndex", true);
driver.set(appiumDriver);
} else {
throw new Exception("Unexpected platform.");
}
}
Thanks in advance!