Skip to main content

Flexible Mobile App Test Automation for Android and iOS

· 5 min read
Santhosh Selladurai
Co-Founder and CTO, DevAssure

Mobile app automation often requires multiple services and libraries to be set up and platform-specific SDKs to be installed. Appium and WebdriverIO provide an interface to build tests that can run in both Android and iOS just by changing capabilities. In spite of the powerful interfaces, often mobile app automation projects are not set up to make use of this to full potential. Let's look at how to setup abstractions and reuse most of the automation scripts for Andorid and iOS app testing.

With mobile app development frameworks like Flutter, React Native, building of mobile apps has become seamless and streamlined. Most apps built with hybrid development frameworks have almost the same UI in Android and iOS. Though the underlying components are OS native, the look and feel of the apps are similar. Hence the use cases or test cases are also the same for both the app platforms.

This gives test engineers the opportunity to design and build mobile app automation tests which are flexible. There are 3 levels of abstraction we can use to design the mobile app automation tests and let’s look at how these are achieved in DevAssure - An Intelligent Test Automation Platform.

1. Locator abstraction

Since the user flows / test cases are going to be the same in both Android and iOS, we can create a single test case with all the actions. The locators used in the actions are stored in multiple page files (following Page Object Model). These locators are exposed to the test cases as interfaces which have 2 overriding implementations for each of the mobile OS platforms.

While building your mobile test framework, you can make sure to declare all the page files as interfaces and have separate implementations for Android and iOS which will have unique locators defined.

Sample code

public interface LoginPage {
String getUsernameFieldLocator();
}

public class AndroidLoginPage implements LoginPage {
@Override
public String getUsernameFieldLocator() {
return "xpath://android.widget.EditText[@content-desc='username']";
}
}

public class iOSLoginPage implements LoginPage {
@Override
public String getUsernameFieldLocator() {
return "xpath://XCUIElementTypeTextField[@name='username']";
}
}

Here, you can initialise the LoginPage object at runtime with one of the implementations based on the mobile OS you pick during test execution.

Locator abstraction in DevAssure

Locator level abstraction is available in-built within DevAssure’s low code test automation platform. We can add 2 flavours of the locators in the same locator table in the page file.

  1. Create a Mobile Page or Mobile Component file
  2. Enable Android and iOS platforms
  3. Add element and provide OS specific locator values
  4. You can add multiple backup locators too. This will improve the test stability.
  5. You can add a single test which will work for mobile app automation of iOS and Android using the locators.

DevAssure Mobile app automation locators DevAssure Mobile app automation test

2. Function abstraction

Although most of the UI looks the same in iOS and Android apps, there might be some user flows that are specific to the OS. In those cases, we need not create separate tests, we can have the same test for the common actions and override only the set of actions that are different between the platforms. The page abstractions can be used for this, where the overriding functions will be a series of UI actions.

Sample code

public interface LoginPage {
void login(String username, String password);
}

public class AndroidLoginPage implements LoginPage {
@Override
public void login(String username, String password) {
driver.findElement(By.xpath("//android.widget.EditText[@content-desc='username']")).click(); driver.findElement(By.xpath("//android.widget.EditText[@content-desc='username']")).sendKeys(username);
driver.findElement(By.xpath("//android.widget.EditText[@content-desc='password']")).sendKeys(password);
driver.findElement(By.xpath("//android.widget.Button[@content-desc='login']")).click();
}
}

public class iOSLoginPage implements LoginPage {
@Override
public void login(String username, String password) {
driver.findElement(By.xpath("//XCUIElementTypeButton[@name='Go to Login']")).click();
driver.findElement(By.xpath("//XCUIElementTypeTextField[@name='username']")).click();
driver.findElement(By.xpath("//XCUIElementTypeTextField[@name='username']")).sendKeys(username);
driver.findElement(By.xpath("//XCUIElementTypeSecureTextField[@name='password']")).click();
driver.findElement(By.xpath("//XCUIElementTypeSecureTextField[@name='password']")).sendKeys(password);
driver.findElement(By.xpath("//XCUIElementTypeButton[@name='Login']")).click();
}
}

Function abstraction in DevAssure

In DevAssure the Mobile Page functions have inbuilt abstraction that can be enabled for functions that need multiple implementations. To make use of the function abstraction in DevAssure,

  1. Create a Mobile Page or Mobile Component file
  2. Enable Android and iOS platforms
  3. Add elements with OS specific locator values
  4. Add a page function and configure to have separate implementation
  5. Add separate implementation for Android and iOS
  6. In the test, call the functions for overriding behaviours and the mobile app automation test runs with function implementation based on the os picked in runtime.

DevAssure Mobile app automation iOS function DevAssure Mobile app automation Android function DevAssure Mobile app automation test with functions

3. Test Case level abstraction

For tests that are applicable only for certain OS platforms, mark the tests with the OS marker, so you can filter the OS specific test cases and execute them in separate workflows.

You can use custom annotations based on the test library you use to mark the applicable mobile os for each test.

Sample code

@Test
@MobileOS("iOS") //MobileOS is a custom annotation
void testiOSFaceId() {
// iOS specific test
}

Test case abstraction in DevAssure

In the DevAssure test, you can pick the OS in each test. And while creating mobile app automation test suites, you can filter the tests based on the OS.

DevAssure Mobile app automation test os picker DevAssure Mobile app automation suite

To experience how DevAssure can leverage Mobile App testing for android and iOS, please click the button to sign up for a free trial.


Furthermore, to have a personalized demo on how the DevAssure test automation platform can leverage your Organization's testing capabilities, please click the button to request a demo session with our team of experts.