Mobile Testing with Appium: Ensuring Cross-Platform App Performance

Table of Contents

Introduction

Mobile programs have become a vital element of our everyday lives in the latest fast-paced virtual environment. Consumers need those programs to run seamlessly on many screens, devices, and working systems. Maintaining this stage of dependability is tough for each builder and testers. Mobile app testing services play a crucial role in ensuring consistent performance across platforms. Appium is an open-supply automation device that enables cell trying out. Unlike conventional solutions, Appium gives a customizable manner to automate trying out on each of the iOS and Android platforms, making it a famous desire for organizations trying to expand cross-platform apps rapidly. To assist in guaranteeing cross-platform app performance, this publication seems to be based on Appium's features, nice practices, and the way to get started.

CTA1 (3).png

What is Appium?

Appium is an open-source, cross-platform test automation tool outlined essentially for mobile applications. For Windows, iOS, and Android-based mobile, hybrid, and native web applications, it streamlines the automated testing process.

Key Components of Appium

1. Client-Server Architecture:

  • Appium Server: The server is entirely formed in Node.js and interacts with mobile devices by accepting test instructions in the JSON format.
  • Appium Client Libraries: You may write the scripts in different programming languages such as Java, Python, JavaScript, Ruby, and the list is endless. 

2. Cross-Platform Compatibility: Appium is an application that encourages the development of a given code to be relevant on iOS along with Android applications, thus expanding reusability of the code length and reducing the cost of maintenance, hence also making development affordable and easy to manage.

3. No Need for App Modification:

  • Native apps don’t require SDK modifications. 
  • You can directly test apps without embedding them in specific test frameworks. 

4. Support for Multiple App Types:

  • Native Apps: Native apps are built using platform-specific technologies like Swift and Kotlin.
  • Hybrid Apps: Hybrid apps mix web and native elements, often built using Ionic or Cordova. 
  • Mobile Web Apps: Mobile web apps run in mobile browsers like Safari or Chrome. 

How Appium Works

  • Test Execution: You create test scripts using Appium client libraries. 
  • Command Translation: The Appium format allows mobile automation frameworks such as UIAutomator2(Android) and XCUITest(iOS) to understand your commands.
  • Device Interaction: Commands, like clicking, swiping, or validating UI components, are invoked directly on the mobile device or mobile emulator by these frameworks.

Why Choose Appium for Cross-Platform Testing?

These frameworks replicate clicking, swiping, and validating of user interfaces in direct interaction with a mobile phone or emulator.

1. Single Codebase for Multiple Platforms: Testers may create automation scripts as they were once with Appium, and they will execute immaculately on both iOS and Android devices. As a result, development and maintenance costs are essentially reduced since isolated test suites for each platform are no longer required.

2. Support for Multiple Programming Languages: Writing scripts in C#, Ruby, Python, Java, and JavaScript is the job of testers. Appium's flexibility allows effortless incorporation into existing processes with a minimal learning curve.

3. No App Modification Required: Unlike certain tools that force developers to integrate additional code or SDKs into their apps, Appium works directly with native frameworks such as UIAutomator2 (for Android) and XCUITest (for iOS). Consequently, the app stays in production mode during testing to maintain the sanctity of the application.

4. Broad App Type Coverage: Appium presents a full solution catering to a leading tests platform for diverse apps that technically have mobile web applications, native applications and apps that are hybrids in nature.

5. Integration with CI/CD Pipelines: Because of this great feature, Appium can successfully integrate with the most popular CI/CD technologies like GitHub Actions, Jenkins, CircleCI, and so on. It is very important since defect identification could take place at an early stage and facilitate the automatic testing as part of the deployment process itself.

6. Wide Range of Supported Devices: Appium is consistent with emulators, simulators, and actual devices. With cloud-based device ranches like Perfecto, Sauce Labs, and BrowserStack, a range of device configurations and operating systems may be assessed without the required hardware.

7. Open Source and Active Community: Appium is free to use and contains a flourishing community that continuously includes modern features and gives a ton of help.

Key Features of Appium for Cross-Platform Testing

Appium's extensive feature set makes it a great option for automating mobile testing across platforms. A closer look is as follows:

1. Cross-Platform Execution

Appium allows one single test script to serve well on both iOS and Android. To provide this consistent experience, Appium is built using the corresponding technological stack to both of the platforms - XCUITest for iOS devices and UIAutomator2 for Android devices.

Example: A login test script written in Java for Android can also be executed on iOS by merely tweaking the desired capabilities.

2. Support for Native, Hybrid, and Web Apps

  • Native Apps: Apps built using platform-specific technologies like Swift (iOS) or Kotlin (Android). 
  • Hybrid Apps: Apps combining web technologies (HTML, CSS, JavaScript) wrapped in a native container. 
  • Web Apps: Mobile-optimized websites accessed via browsers like Safari or Chrome. 

Appium’s versatility allows QA teams to test any app type without switching tools.

3. Parallel Testing

Tools such as TestNG or JUnit enable Appium to parallelize test execution across numerous devices or emulators. This greatly decreases the time taken for large test suites' validation.

Example: Running regression tests simultaneously on an iPhone 13 and a Samsung Galaxy S22 ensures compatibility across devices.

4. Device Cloud Integration

Appium works seamlessly with cloud testing systems like BrowserStack, Sauce Labs, and Kobiton, giving you access to real devices with different OS versions so that you do not have to bother with acquiring devices.

5. Robust Locator Strategies

With an emphasis on sustainment and resilience to minor UI changes, tests can thus be performed using Accessibility ID, XPath, Class Name, and CSS Selector locators in Appium accurately to ascertain and interact with GUI components.

6. Advanced Gesture Support

With Appium, testers can recreate actual user behavior as tap, swipe, scroll, pinch, and zoom functions. Ultimately, it acts as essential tools for tests in modern applications with interactive and dynamic interfaces.

7. Open-Source Flexibility

Being open-source, Appium is highly customizable. Developers can contribute to its codebase, add new features, or modify it to suit specific project needs.

Steps to Get Started with Appium for Cross-Platform Testing

Setting up Appium for cross-platform testing involves a few steps. Below is a step-by-step guide to help you begin:

Step 1: Install Prerequisites

Ensure you have the following installed:

  • Java Development Kit (JDK): Required for running Appium and Android tools. 
  • Node.js: Appium server is built on Node.js, so installing it is essential. 
  • Android SDK: For Android app testing. 
  • Xcode (for macOS): For iOS app testing. 
  • Appium Desktop: A GUI-based Appium server to inspect elements and run test cases. 

Commands (Example for macOS/Linux):

# Install Node.js 
brew install node   

# Install Appium globally 
npm install -g appium 

Step 2: Set Up the Appium Server

Start the Appium server using either the Appium Desktop app or via the terminal:

appium

Once started, the server will be ready to accept test commands on a specific port (default is 4723).

Step 3: Configure Desired Capabilities

Desired capabilities are key-value pairs that define the testing environment and app under test.

Example Configuration for Android:

{ 

  "platformName": "Android", 

  "platformVersion": "12.0", 

  "deviceName": "Pixel_4", 

  "app": "/path/to/your/app.apk", 

  "automationName": "UiAutomator2" 

} 

Example Configuration for iOS:

{ 

  "platformName": "iOS", 

  "platformVersion": "16.0", 

  "deviceName": "iPhone 14", 

  "app": "/path/to/your/app.app", 

  "automationName": "XCUITest" 

} 

Step 4: Write Your First Test Case

Use a supported programming language and a test framework like JUnit (Java), Pytest (Python), or Mocha (JavaScript).

Example Test in Java:

import io.appium.java_client.MobileElement; 

import io.appium.java_client.android.AndroidDriver; 

import org.openqa.selenium.remote.DesiredCapabilities; 

import java.net.URL; 

public class FirstAppiumTest { 

    public static void main(String[] args) throws Exception { 

        DesiredCapabilities caps = new DesiredCapabilities(); 

        caps.setCapability("platformName", "Android"); 

        caps.setCapability("deviceName", "Pixel_4"); 

        caps.setCapability("app", "/path/to/your/app.apk"); 

        caps.setCapability("automationName", "UiAutomator2"); 
 
        AndroidDriver<MobileElement> driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), caps); 
 
        MobileElement loginButton = driver.findElementByAccessibilityId("login_button"); 

        loginButton.click(); 

        driver.quit(); 

    } 

} 

Step 5: Execute Tests

Run your test script using the preferred IDE or command line. Verify the test results and debug any failures.

Step 6: Integrate with CI/CD

Thus, Appium could thereby be integrated with CI/CD tools such as Jenkins, CircleCI, and GitHub Actions for automated testing, which would allow tests to run on every code change.

Conclusion

The major advantage of mobile testing automation with Appium, for iOS or Android, is the possibility of validating the behavior of the application on various devices and platforms. Appium in itself is highly flexible. Also an easy-to-use tool, making it a viable resource for multiple platforms. By following Appium's tenets and best practices, organizations can reduce the time-to-market for mobile applications without compromising on quality and usability.

About Author

Rahul PatelStarted his journey as a software tester in 2020, Rahul Patel has progressed to the position of Associate QA Team Lead" at PixelQA a Software Testing Company.

He intends to take on more responsibilities and leadership roles and wants to stay at the forefront by adapting to the latest QA and testing practices.