Skip to content

How to programmatically switch between ios and android enhanced driver #12

@jerimiah797

Description

@jerimiah797

When I write appium tests, it looks like I can only declare driver as either an EnhancedAndroidDriver type, or an EnhancedIOSDriver type. I want to run a simple test in a single file that will run on both platforms, but it seems I must choose either android or ios for that file to run on. How do I avoid duplicating all my test files? I am using react native and my app is basically identical on both platforms. I have done something similar with the regular AppiumDriver.

Any suggestions to programmatically switch which 'EnhancedIOS/AndroidDriver' the variable driver refers to in Java??

With the regular AppiumDriver, I can do this:

private static AppiumDriver<MobileElement> driver;

public AppiumDriver<MobileElement> getDriver() throws IOException {
    if (PLATFORM_NAME.equals("Android")) {
       driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    } else if (PLATFORM_NAME.equals("iOS")) {
       driver = new IOSDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }
    return driver;
}

But it seems impossible to take this approach with the Enhanced drivers because they don't share a common type. Please advise!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions