The Talent500 Blog
How to Do Test Automation With Appium for iOS 1

How to Do Test Automation With Appium for iOS

How to Do Test Automation With Appium for iOS

 

The rising market for iOS devices has increased the importance of iOS testing in developing mobile applications that serve, delight, and retain customers.

As the market expands at a quicker rate, so do customer expectations. Companies give updated versions of these applications with the most recent upgrades every few weeks to match these expectations. This is where automated testing comes in to assist development and testing teams produce high-quality programs on time.

Appium is most used for testing mobile apps. It facilitates the execution of automated testing of native and hybrid apps for Android and iOS devices, resulting in faster and more reliable results. This post will look at how to automate iOS app testing using Appium.

What is Appium?

Appium is a free and open-source automated testing framework for apps on platforms such as iOS, Android, macOS, and Windows. It, like Selenium, allows the tester to create test scripts in a variety of programming languages, including JavaScript, Java, Ruby, Python, PHP, and C#, and it can be used on both the Android and iOS platforms.

How does Appium iOS work?

Appium uses the RESTful services principle by providing JSON files that automatically interact with an iOS application utilizing UI components such as text labels, buttons, and so on via Apple’s UIAutomation API for automated app testing.

The bootstrap.js code acts as a TCP server, delivering test commands to the iOS device to perform activities using Apple’s UIAutomation API framework.

How to Do Test Automation With Appium for iOS 2

The working of Appium for iOS

 

Reason to use Appium for testing iOS devices

Because of the following features, Appium is an excellent solution for automated testing on iOS devices:

  • It is an open-source framework, which means it saves money on tool and framework license fees.
  • Appium can generate information logs with a thorough reporting structure thanks to an in-built XCUITest driver. This enhances the analysis of test results and the debugging process.
  • It allows for the reusability of code produced for iOS devices for Android smartphones, saving time and effort for hybrid apps.
  • It enables users to test the program on multiple iOS device versions. This guarantees that apps are cross-platform compatible.
  • It allows real-time monitoring of testing on actual devices, which increases dependability.

For Appium testing on iOS devices, the pre-requisites are:

Before delving into how to perform Appium tests on iOS devices, here are the requirements that must be met:

  •     Install Homebrew (Manages missing packages)

bash brew install carthage

  •     Install Carthage (Manages dependencies)

brew install carthage

  •     Install Node & NPM

brew install node

  •     Install Java and setting up the environment variables
  •     Install Eclipse IDE for Java
  •     Install Maven

brew install maven

  •     Install Appium

npm install -g appium

  •     A Mac computer with macOS 10.11 or 10.12, a device with iOS 9.3 or higher version
  •     Install XCode 11 (higher version is required)

npm install -g ios-deploy

  •     Install XCUITest Driver
  •     Install TestNG

Get started with running Appium tests on iOS devices

Starting with the Appium Server

1.To begin, Launch the Appium server

How to Do Test Automation With Appium for iOS 3

2.Get the details of the iOS device

Obtain information about the iOS device used for testing. To enable the necessary features, the device name, iOS version, and bundleId must be specified. Because this example employs the XCUITest driver for iOS testing, the automationName must be set to XCUITest. Note that XCUITest will only operate with iOS 9.3 or higher versions.

For iOS Devices, write the Appium Test Script for iOS Devices

  1.     In Eclipse, Create a new project.
  2.     To start writing the test code, Create the package and class.

 

In this script, the tester needs to set the Desired Capabilities and instantiate the Appium Driver.

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”, “<your iPhone’s udid>”);

capabilities.setCapability(“bundleId”, “com.google.Chrome”);

capabilities.setCapability(“xcodeOrgId”, “<your org id>”);

capabilities.setCapability(“xcodeSigningId”, “<your signing id>”);

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”);

}

}

In the code for establishing Desired Capabilities and instantiating Appium Driver, the UDID of the iPhone, iOS version, and bundle id details (for the Google Chrome app, in this case) acquired in the previous section must be utilised.

  1. Run this script
  2. On the connected iOS device,the Google Chrome App will be opened.

Inspect UI Elements for iOS

Unlike Android, where the UIAutomatorViewer tool is available, iOS does not have a specialized tool for recognizing iOS Elements. Instead, the tester might analyze the UI components for iOS using Appium Desktop Inspector.

Appium testing best practices for iOS devices:

  • Ensure that the installation procedure is followed precisely and that all dependencies are properly maintained.
  • To obtain realistic results, use genuine devices rather than simulators or emulators.
  • For app testing, you may use a real device cloud. BrowserStack provides genuine iOS devices, allowing QAs to do automated app testing on various versions of real iOS devices.
  • For quick and accurate debugging, record functions with Appium and examine items using Appium Desktop Inspector.
  • Carefully locate the bundle ID of the program under test; otherwise, the correct results may not be obtained.
  • Before starting testing, ensure that the app is already installed on the device.

Conclusion

Appium offers accurate and complete automated testing of hybrid, native, and online apps, removing bugs, abnormalities, and other issues that may interfere with user experience. Of course, all Appium testing should be performed on real mobile devices since monitoring apps in real-world user environments yields 100% correct results every time.

 

0
Afreen Khalfe

Afreen Khalfe

A professional writer and graphic design expert. She loves writing about technology trends, web development, coding, and much more. A strong lady who loves to sit around nature and hear nature’s sound.

Add comment