Author

AUTHOR

Jathin M Jaishur

Software testing has long been an essential part of the software development process. Today with the increased use of mobile and smartphone devices, mobile app testing has emerged as the most significant component in software testing. That time has passed when mobile versions were simply scaled-down versions of the web browser. Leading companies are attempting to deliver their services and solutions via mobile devices. As a result, any app needs to be compatible across the different versions of iOS and Android devices.

The article explores automation testing for iOS apps without having a physical device or simulator.

For iOS applications, the simulator requires a .app file while the real device needs a .ipa file. Before automating iOS applications, you may need to ask the developer for these file types.

So, now let’s dive into automation testing for iOS app. So, you wish to run your automation scripts on an iOS device. All you have is a Linux or Windows machine, and you know executing automation scripts of an iOS app is not possible. You may also be well aware that iOS apps cannot be executed or inspected without macOS. Unlike Android devices, iOS devices require Xcode, Homebrew, Carthage and many others along with Appium to operate on macOS.

Don’t worry! In such situations, there are plenty of solutions, such as:

  • First and the foremost thing will be to have a Mac device itself
  • Use VirtualBox or Virtual Machine where macOS is installed
  • Tools like TestProject, TestSigma, etc., can be used to record and run the test. Tools like these require an Apple developer account to automate on a local iOS device
  • Use a remote machine where macOS is available
  • Use a cloud provider like BrowserStack, Saucelabs, Experitests, etc.

IOS Automation Testing Using
Appium

The initial setup of Appium for an iOS device is challenging, even if you have macOS. One needs to set up Xcode and other necessary software.

In my opinion for iOS app testing using Appium, a cloud provider is a better choice because the setup is hassle-free and the sessions are recorded for future reference. Cloud providers can automate both iOS and Android.

Here, I will be discussing Browserstack’s very own App Automate which is used to run mobile automation scripts.

Prerequisites for setting up browserstack

We will need a BrowserStack username and access key. To obtain access credentials, we need to sign up for a free trial or purchase a plan. We need to upload the app (for android .apk or .abb and for iOS .ipa) to Browserstack servers using Rest API or curl.

Here is an example cURL request to upload the app:

curl -u “<username>:<access_key>” \
-X POST “https://api-cloud.browserstack.com/app-automate/upload” \
-F “file=@/path/to/app/file/application.apk”

After the upload is complete, we will get a response having app_url. This value will be used later to set the app capability to specify applications under test in Appium test scripts.

Are any configurations required?

To test remotely on BrowserStack’s real device cloud, we must configure it utilizing the desired capabilities. The following modifications must be made to your Java test script:

    1. Specify the application under test using the app capability. Use the app_url value returned at the time of app upload to set this capability.
    2. Specify the real Android or iOS device name to perform the test using the device capability. Here, I will be using Google Pixel 4.
    3. Specify the OS version using the os_version capability. Here, I will be using 10.
    4. We can incorporate additional capabilities using BrowserStack – Capabilities for running mobile app tests on BrowserStack

        DesiredCapabilities caps = new DesiredCapabilities();

        caps.setCapability(“device”, “Google Pixel 4”);

        caps.setCapability(“os_version”, “10.0”);

        caps.setCapability(“browserstack.appium_version”, “1.22.0”);

        caps.setCapability(“app”, “<app_url>”);

                 5. In order to initialize an Appium driver, use a remote BrowserStack URL along with BrowserStack access credentials as shown below:

  https://<username>:<access_key>@hub-cloud.browserstack.com/wd/hub

What does the script look like?

Sample Appium test script will look like this once all the capabilities are included.

import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;

public class bs {

public static String userName = “<username>”;
public static String accessKey = “<access_key>”;

public static void main(String[] args) throws MalformedURLException, InterruptedException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(“device”, “Google Pixel 4”);
caps.setCapability(“os_version”, “10.0”);
caps.setCapability(“browserstack.appium_version”, “1.22.0”);
caps.setCapability(“app”, “<app_url>”);
AndroidDriver driver = new AndroidDriver(new URL(“https://”+userName+”:”+accessKey+”@hub-cloud.browserstack.com/wd/hub”), caps);

WebElement searchElement = new WebDriverWait(driver, Duration.ofSeconds(30)).until(
ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId(“Search Wikipedia”)));
searchElement.click();
WebElement insertTextElement = new WebDriverWait(driver, Duration.ofSeconds(30)).until(
ExpectedConditions.elementToBeClickable(AppiumBy.id(“org.wikipedia.alpha:id/search_src_text”)));
insertTextElement.sendKeys(“BrowserStack”);
Thread.sleep(5000);
driver.quit();
}
}

Despite the above code being for an Android environment, similar lines of code are applied in an iOS environment with the exception of a few naming convention changes.

How to view the results?

The App Automate dashboard provides access to the test session outcomes and execution data. We can inspect the execution details and debugging information for a specific test session, including video recordings, network logs, and device logs.

This solution allows us to perform Appium tests for iOS applications without an actual device or emulator, and it is also OS-independent. You only need to configure a few capabilities to connect to the cloud service provider.

And there you have it, iOS application automation testing without a Mac. A similar setup is also applicable to other cloud service providers. All of them have extensive instructions on installation and execution.

You can also explore our Test Automation Services at TA.

Viola!