Search code examples
seleniumautomationappiumappium-androidappium-ios

Should I use one repository for iOS and android for mobile automation (Native App)?


Currently I am using Appium, Selenium, Java, TestNG for native app. I am doing automation for iOS and Android and both functionality is same but yes element identifier is different in iOS and android. None of element have same name. Let’s say for login button element identifier is in following way

For Android

@AndroidFindBy(id = "com.abc.bot:id/home_screen_sign_in_btn")
    private MobileElement signinbtn;

For iOS

@FindBy(xpath="//XCUIElementTypeButton[@name='Log In']")
    private WebElement logInButton;

Apart from that we are using CircleCI and for iOS and Android have different pipeline and different branch too. My question is, should I keep iOS and Android in same repo or different branch. Can someone explain pros and cons please?


Solution

  • You could stick to single locator strategy, for instance XPath Selector and use XPath Union operator to combine both locators into one like:

    //XCUIElementTypeButton[@name='Log In'] | //*[@resource-id='com.abc.bot:id/home_screen_sign_in_btn']
    

    A better approach would be putting your locators into a .properties file like:

    android.signin.button=//*[@resource-id='com.abc.bot:id/home_screen_sign_in_btn']
    ios.signin.button=//XCUIElementTypeButton[@name='Log In']
    

    And then query the desired element by combining platformName Desired Capability with the locator from the .properties file

    Properties uiprops = new Properties();
    uiprops.load(new FileInputStream(new File("ui.properties")));
    String locator = uiprops.get(appiumDriver.get().getCapabilities().getCapability("platformName") + ".signin.button").toString();