Crossplatform testing on Appium 2.0

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!

Hi,

we have similar. what problem with AppiumDriver?

give examples of your problems.

Hello @Aleksei!

My question is mainly about how to deal with the differences of the drivers. Should I always cast the driver I am using to the base AppiumDriver for methods such as activateApp() with for example ((AndroidDriver) driver).activateApp()?

Also, since the mobile TouchActions class is deprecated, are the the UiAutomator2 and XCUITest APIs the way to go forward, with AppiumDriver.executeScript()?

I’m only asking for native mobile automation for the time being, not web.

Thanks!

1 activateApp ->

    public AppDriver activateApp(String appID) {
        try {
            if (driver instanceof AndroidDriver)
                ((AndroidDriver) driver).activateApp(appID);
            else if (driver instanceof IOSDriver)
                ((IOSDriver) driver).activateApp(appID);
            else
                Assert.fail(createAssertionLog("unknown driver type"));
        } catch (Exception e) {
            Logger.logError(e.getMessage());
        }
        return this;
    }

2 TouchActions -> I moved to https://appium.io/docs/en/commands/interactions/actions/ both Tap, Swipe, Drag, LongTap and all other actions

Use common interfaces:

((InteractsWithApps) driver).activateApp(appId);

Great, I’ll implement those suggestions. Thank you both!

When is it expected to have this type of information in the appium 2.0 documentation?