Creating test scripts that work for XCUITest and UIAutomator2 frameworks


I’m very curious to hear about possibilities to create a test framework that will be compatible with iOS and Android apps. I’m assuming that the screen models will have to separate, though as far as scripts go, I think it’s possible to unify those.

Has anyone has any success in doing something like that?

I am doing it 5+ years with Java and PageObject Appium annotations. Very convinient.

On page(screen) level you declare elements and actions with it. Flow difference (sometimes it always differ ios and android apps) on test level.

1 Like

Hey Aleksei,

That’s exactly what I’m looking to setup. To clarify, when you say that you declare elements and actions with them on the page object, you mean there is a separate file for iOS and Android?

And test flow is a unified file?

I’m trying to envision the workflow and how to setup and pass down platform specific capabilities when using one test flow. Do you set it up via test configuration or pass it via some variable when executing the test flow?

This is how I imagine it to work. Do I understand the flow correctly?

no. ONE page object for both.

Example below. Here we see also logs lines and Allure annotations for report.

public class StartPage extends BasePage {

    @iOSXCUITFindBy(id = "pricingButton")
    @AndroidFindBy(id = "pricing_text")
    private MobileElement pricingButton;

    @iOSXCUITFindBy(id = "languageButton")
    @AndroidFindBy(id = "language_text")
    private MobileElement languageButton;

    public StartPage(Page page) {

    @Step("Tap 'Login' button")
    public EmailPage tapLoginButton() {
        Assert.assertTrue(tap(loginButton), createAssertionLog("FAILED"));
        return new EmailPage(page);


Ah I see, so in your case you are doing it the other way around?

1 page object file is being used by two different test scripts? And in the script file you set what tag to use (iOSXCUITFindBy or AndroidFindBy)?

ONE test for both!

    @Test(description = "Short test description",
            groups = {"smoke"})
    public void testName() {
        String result;

        // login

        MoreMoneyPage moreMoneyPage = myApp().moreMoneyPage();

        // check default amount
        result = moreMoneyPage.getAmountInputText();
        getSoftAssert().assertEquals(result, "300", "Default 'MoreMoney' input value NOT correct");

        // check MIN amount
        if (isOS()) {
           // do some actions if iOS flow a bit different
        result = moreMoneyPage.getAmountInputText();
        getSoftAssert().assertEquals(result, AMOUNT_MIN, "MIN 'MoreMoney' input value NOT correct");

Annotation I use are from Java! client. Not sure about JavaScript if it has any similar.

Java more examples:

Even the test is the same. That’s really cool and exactly how I would like to set mine up as well.

Okay, I’m currently using mocha as the test runner, and I need to sit down and try to figure out what elements I can utilize to locate objects in iOS and Android scenes.

Did you define @iOSXCUITFindBy tag anywhere yourself or it came with some framework?

iOSXCUITFindBy -> it is inside Appium Java client:

if it absent in Javacript you can change them just for iOS and Android locators. and inside page function have logic:

Locator locator;
if (isIOS)
 locator = iOS_locator;
else if (isAndroid)
 locator = Android_locator;

Yep, that’s exactly what I was thinking about going with, but those @ indicators make it all look very elegant.

Alright, I’m glad that my theory is possible to execute in practice.

Thanks for all the pointers.