Leverage Cross-Platform Mobile Test Automation

Streamline your CI/CD process and ensure optimal app performance with robust Appium scripts, parallel testing, and real-time feedback on real devices.
Cross-Platform Mobile Test Automation Using AppiumCross-Platform Mobile Test Automation Using Appium

A Comprehensive Guide to Cross-Platform Mobile Test Automation Using Appium

March 23, 2023
 by 
 Rohith Ramesh Rohith Ramesh
Rohith Ramesh

Introduction

As smartphones and multi-platform devices continue to surge, traditional manual app testing practices are struggling to keep up with demand. Businesses across industries are experiencing significant product delivery delays and costly product defects. To ensure efficient and cost-effective testing across all platforms, an effective mobile app testing platform is essential. It should be secure, support functional and automated testing, and prioritize speed and quality.

In this current era, businesses must deliver the best possible user experience through their apps. However, achieving this can only be challenging with the right tools. That's where Appium comes in. This powerful mobile app testing solution offers comprehensive features to help businesses optimize their app's performance and provide an unparalleled digital experience. With Appium, businesses can take their app testing capabilities to the next level, ensuring customers receive an exceptional mobile experience every time.

This blog on automated Appium testing provides a comprehensive overview of the framework, covering all the necessary information and benefits to help you harness the power of this fantastic automation testing tool for cross-platform mobile app testing.

What is Appium testing and why is it so popular?

Appium is an open-source automation testing framework widely used for mobile app testing. It offers scalability and flexibility, making mobile app testing much more efficient. Appium is a cross-platform testing framework that allows testers to write test scripts against multiple platforms, including iOS, Windows, and Android, using the same API. With Appium, QAs can write test scripts in different programming languages, such as Java, JavaScript, PHP, Ruby, Python, and C#.

Appium is a mobile automation tool that uses Node.js to operate as an HTTP server. It supports simulators and emulators and processes HTTP requests from Selenium client libraries differently based on the platforms. One of the best things about Appium is that it lets you write in any language supported by Selenium using WebDriver API. Appium translates Selenium Webdriver commands into UIAutomation (iOS), or UIAutomator (Android) commands, making it independent of the mobile operating system. Automation scripts can be run on real Android and iOS devices using the WebDriver JSON Wire protocol. When testing an Android app, Appium automates it with the help of the UIAutomator library, while on iOS, it proxies commands to a UIAutomation script running in instruments.

Overall, Appium testing is widely adopted by modern enterprises to create a comprehensive mobile automation framework due to its growing user base, strong community, and flexibility.

Why should you prefer Appium testing?

  • Appium automation testing facilitates cross-platform mobile testing, allowing the same test to function on multiple platforms.
  • Test automation with Appium does not require any third-party code to compile into your app for automation.
  • Appium automation testing enables a variety of frameworks and programming languages by wrapping the vendor-provided frameworks in the WebDriver API.
  • Appium automation testing enables the execution of multiple tests on multiple platforms without needing management.
  • Appium automation testing offers cross-platform compatibility, allowing the same tests to run on various platforms, thus increasing coverage.
  • Test automation with Appium allows the viewing and sharing of device interactions with colleagues using the built-in collaborative screen-casting feature in real-time.
  • Appium automation testing allows for testing mobile applications on emulators, simulators, or real devices, providing flexibility in choosing the testing environment. However, remember that emulators and simulators are insufficient for final-stage testing as they cannot replicate all device features necessary to optimize the app for real user conditions. Only real device testing can provide conclusive and accurate results.
  • Test automation with Appium allows on-demand testing and leveraging of results directly.
  • Appium automation testing supports automation frameworks like JUnit and TestNG.
  • Test automation with Appium allows parallel execution of test automation scripts on different Android or iOS sessions using UIAutomator, UIAutomation, or Xcode9, speeding up the testing process and ensuring scalability.

How does cross-platform test automation with Appium work?

Appium enables automated interaction with mobile applications by leveraging the behavior of their UI components, such as buttons, text boxes, and links. This allows efficient reuse of tests written for mobile app testing, which can be run repeatedly across multiple sessions.

1. Run tests with Appium on Android devices

Appium is an automation testing tool designed to test Android applications. It leverages the UIAutomator framework or Selendroid to automate user interface testing on Android devices. To achieve this, Appium uses the bootstrap.jar file as a TCP server, which sends test commands to interact with the Android device through the UIAutomator or Selendroid framework.

To test Android applications using Appium, you must install the necessary components on your system. The following steps outline the installation process:

  1. Firstly, download the Appium Jar files for Java, the latest Appium Client Library, and the Appium Server.
  2. You will also need to download and install Java on your system. Be sure to set the environment variables correctly.
  3. Additionally, TestNG, a testing framework for Java, is required to run Appium tests. Make sure to install it as well.
  4. Once all components are downloaded and installed, enable Developer Mode on your Android device and configure it for testing.

Following these steps will enable you to begin testing Android applications using Appium with ease.

Below is an example code that demonstrates how to write Appium test scripts for testing Android applications. The code uses Eclipse IDE to run the tests on Android devices.


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
public class AppiumExample{
WebDriver driver;
WebDriverWait wait;
String AppURL = "https://www.browserstack.com/";
@BeforeTest
public void setup() throws MalformedURLException {
// Create an object for Desired Capabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
// Name of mobile web browser to automate. capabilities.setCapability("browsername", "chrome");
//device name
capabilities.setCapability("GalaxyS4", "WKZLMJLB7L8TR8SW");
// Which mobile OS platform to use - iOS, Android, or FirefoxOS
capabilities.setCapability("platformName", "Android");
// Java package of the Android app you want to run capabilities.setCapability("appPackage", "com.android.chrome");
// Activity name for the Android activity you want to launch from package capabilities.setCapability("appActivity", "com.google.android.apps.chrome.Main");
// Initialize the driver object with the URL to Appium Server passing the capabilities. Server Url may vary
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
wait = new WebDriverWait(driver, 5);
}@Test
public void testSearchAppium() {
driver.get(AppURL);
String homePageTitle = titleElement.getText();
Assert.assertEquals(homePageTitle, Most Reliable App & Cross Browser Testing Platform | Browserstack ");
WebElement LinkElement = driver.findElement(By.xpath("//body[@class='page-template-default page page-id-593 page-parent live persistent-header wpb-js-composer js-comp-ver-6.0.5 vc_responsive']")).click();
wait.until(ExpectedConditions.presenceOfElementLocated(byPageTitle));
String searchPageTitle = driver.findElement(byPageTitle).getText();
Assert.assertEquals(searchPageTitle, "Search");
}@AfterTest
public void tearDown() {
driver.quit();
}
}

When it comes to test automation using Appium, it's crucial to specify the desired capabilities. These capabilities can be defined either in the test code or in appium.txt files. Essentially, the desired capabilities represent a JSON object consisting of keys and values sent from the client to the server. By creating a session for a browser with a specific set of desired capabilities, testers can gain greater control over the server during test automation. This enables them to achieve more efficient and effective Appium testing.

2. Perform Appium testinng on iOS devices

For iOS device testing, Appium employs the JSON wire protocol, just like it does for Android devices. In this case, it utilizes Apple's UIAutomation API to interact with the user interface elements to automate iOS device testing. To achieve this, Appium uses the bootstrap.js file as a TCP server that sends test commands to the iOS device through Apple's UIAutomation API framework. This enables testers to automate iOS device testing in a highly efficient and effective manner.

What made Appium the testing tool of choice for iOS devices?

Appium is an excellent choice for automating iOS app testing due to the following features:

  • Appium is an open-source framework that eliminates the need for costly licensing fees associated with other testing tools and frameworks.
  • With its built-in XCUITest driver, Appium generates detailed information logs with a comprehensive reporting structure. This enhances test result analysis and simplifies debugging efforts.
  • Appium allows for code reusability written for iOS devices on Android devices, saving valuable time and effort for hybrid app testing.
  • Appium enables users to test applications on various versions of iOS devices, ensuring cross-platform compatibility for apps.
  • Appium provides real-time monitoring of tests on real iOS devices, providing a reliable testing environment.

Creating the iOS Appium Test Script

Create a new project in Eclipse and package/class to begin writing the Appium Test Script. 

To open the Google Chrome app on an iPhone for testing, the tester must set the Desired Capabilities and instantiate the Appium Driver in the script.


import io.appium.java_client.ios.IOSDriver;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
 
public class Edition041_iOS_Real_Device {
private IOSDriver driver;
 
@Before
public void setUp() throws MalformedURLException {
//Setting Desired Capabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "12.4.7");
capabilities.setCapability("deviceName", "iPhone 7");
capabilities.setCapability("udid", "");
capabilities.setCapability("bundleId", "com.google.Chrome");
capabilities.setCapability("xcodeOrgId", "");
capabilities.setCapability("xcodeSigningId", "");
capabilities.setCapability("updatedWDABundleId", "com.google.chrome.ios");
 
driver = new IOSDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities);
}
 
@After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
 
@Test
public void testFindingAnElement() {
driver.findElementByAccessibilityId("Login Screen");
}

When writing Appium test scripts for iOS devices, testers must use the UDID of the iPhone, iOS version, and bundle ID details (in this case, for the Google Chrome app) to set the Desired Capabilities as well as instantiate the Appium Driver. Running this script will open the Google Chrome app on the connected iOS device, allowing for automated testing to be carried out.

What are the best practices for conducting Appium iOS tests?

To ensure effective Appium test automation for iOS devices, consider the following:

  • Perform a careful installation process and manage dependencies properly.
  • Utilize real devices instead of simulators or emulators for accurate results.
  • Record functions using Appium and inspect elements using Appium Desktop Inspector for easy debugging.
  • Diligently find the bundle ID of the application under test.
  • Ensure the app is installed on the device before running tests.

How can HeadSpin's Appium-based test automation solution provide global companies a competitive edge?

HeadSpin's AI-driven Platform provides a secure and scalable solution for cross-browser testing and debugging mobile, web, audio, and video apps. Our expert consulting services can help you choose the right mobile automation testing framework for your enterprise.

HeadSpin's Appium automation testing for cross-platform apps can help you:

  • Streamline the entire CI/CD process, create robust Appium scripts with ease, and reduce the complexity of test frameworks.
  • Support parallel testing on multiple mobile devices to ensure optimal app performance across various devices, networks, and global locations.
  • Test apps on real remote devices in real locations, accelerate development up to 10x, and easily identify and resolve critical bugs.
  • Utilize tools for browser compatibility testing and capture real-time feedback.

The Next Steps

Appium is the preferred mobile testing solution for fast and reliable testing across various platforms and devices, providing feasibility, flexibility, and cost-friendliness for delivering optimal user experiences within the continuous delivery approach.

HeadSpin provides a global device infrastructure with cloud-based access to real Android, iOS, and Windows devices, saving testers time and enabling them to meet deadlines faster without additional setup.

Experience the benefits of cross-platform compatibility and user-friendliness by running Appium tests on thousands of real devices with HeadSpin's unique Appium test automation solution. Contact us today to learn more.

Book a trial

Some related posts:

  1. Know all about Appium Inspector
  2. Maximizing Mobile Testing Efficiency with Appium Desktop
  3. Appium Guide for Hybrid App Automation Testing
  4. Automating Mobile Web Browsers with Appium
  5. How to Automate Flutter App Testing Using Appium?

FAQs

Q1. How can I use Appium to connect many devices?

Ans: To use Appium with multiple devices, you must launch an Appium server for each device and connect it to the client using the URL http://<HOST_IP>:<APPIUM_PORT>/wd/hub. If you are working with a single host, the HOST_IP address would be either "localhost" or "127.0.0.1". However, in a multi-machine setup, the IP address would be something like "192.168."

Q2. How does cross-platform automation work?

Ans: To save time and effort in manual testing, developers use various automated cross-platform testing tools to test their products across multiple browsers. These tools are designed to run tests on different versions of browsers and identify any potential software flaws, helping to ensure the quality and reliability of the product.

Q3. How can I define cross-platform API?

Ans: ArcGIS APIs support cross-platform development, allowing developers to write code once using a single API and deploy it across multiple platforms and devices. One such example is the ArcGIS Maps SDK for Java, which enables the creation of a single code base for deployment on Linux, macOS, and Windows operating systems.

Share this

A Comprehensive Guide to Cross-Platform Mobile Test Automation Using Appium

4 Parts