work with IOS and android together in same code

Viewed 164

I'm looking for a way to work with one driver for both android and IOS real devices, for example now if I start with IOS = IOSDriver<MobileElement> driver; and unlock my device for example than my code is driver = new IOSDriver<>(url, dc); and driver.unlockDevice(); for android its the same, but if my driver will be AppiumDriver driver; the code will not work on driver.unlockDevice(); so what are the options to work with android and ios together in one driver?

1 Answers

This is POC - and this isn't handled very well. Just for quick look.
And... I'm not sure about iOS driver - if it can even handle device unlocking - maybe only on simulators...

public static AppiumDriver<MobileElement> driver;
public static DesiredCapabilities iosCaps;
public static DesiredCapabilities androidCaps;

public void caps() {
    iosCaps = new DesiredCapabilities();
    iosCaps.setCapability("deviceName", "iPhone 5");

    androidCaps = new DesiredCapabilities();
    androidCaps.setCapability("deviceName", "Samsung X");
}


protected void startDriver() throws MalformedURLException {
    caps();
    if (device == android) {
        driver = new AndroidDriver<>(new URL("appium url"), androidCaps);
    } else if (device == ios) {
        driver = new IOSDriver<>(new URL("appium url"), iosCaps);
    }
}

public void iosLock() {
    ((IOSDriver) driver).lockDevice();
    ((IOSDriver<MobileElement>) driver).lockDevice();
}

public void androidLock() {
    ((AndroidDriver) driver).lockDevice();
}
Related