Start automating your tests 10X Faster in Simple English with Testsigma
Try for freeToday’s iOS application market is as competitive as never before. In 2022, active iOS users account for more than 1.2 billion, with 2.2 billion units sold worldwide. For a developer or an organization, that means they have got a market of over 1 billion users if they are planning to upload their application to the App Store. And how important does its quality need to be? In 2021, a study revealed that iPhone users spend more than 39 hours per week operating their phones. On the financial side, these users spent more than $85 billion on in-app purchases in 2021.
These statistics show that we have a lot of users, a lot of applications, and a lot of money when it comes to iOS. In other words, if the iOS application quality is compromised, all the work of all the departments will be wasted. How will the user analyze the features when he is not able to navigate to them? The only way we can look at the quality with evident metrics and in a range of parameters is through iOS app testing before releasing it to the end user. And what would be the best way to do that apart from a framework that is developed and used just for this purpose?
Table Of Contents
- 1 What is Appium?
- 2 How to install Appium to test applications?
- 3 How to install driver setup for Appium?
- 4 Pre-requisites to run iOS tests on Appium
- 5 Running your first iOS test in Appium
- 6 How to automate an iOS app on a real device cloud?
- 7 Best Practices for running Appium tests on iOS devices
- 8 Wrapping up
- 9 Frequently Asked Questions
What is Appium?
“Is native app automation missing from your tool belt? Problem solved.” – is what Appium brands itself on its official website. From bringing open-source culture to application testing to providing a cross-platform environment for writing tests, Appium seems to be one of the best choices when a mobile application needs scrutinizing.
For testers opting for Appium, you do not need to worry about the type of mobile application you are releasing to the end user. Be it a native, hybrid, or mobile web application, Appium’s strong features do not restrict the tester in a single direction. The tester is free to choose the tool he likes and the language he prefers to write test cases that do not even require an SDK.
Along with this, technically, Appium offers a few more advantages.
Why use Appium for app testing?
Apart from being cross-platform and open-source, there are a few more reasons to love Appium and prefer it as a framework of choice.
- Works without SDK – An SDK restricts a tester from testing in a specified set of protocols. Not including an SDK gives more freedom to the tester.
- No recompilation – Appium tests do not need to recompile in Appium-specific or Appium-understandable packages. Testing on the same application that will be shipped to the users feels more reliable and confident.
- Huge list of supported languages – Appium tests can be written in a number of languages that it supports. This includes popular languages like JavaScript and Python.
- Work with WebDriver – When WebDriver is already coming up with useful automation APIs for web applications, why not extend the same for mobile? Appium does just that with extended APIs bringing the same set of rich features to mobile testing.
In addition to these technical advantages, the tester also needs to keep in mind the importance of an “automation testing framework” for their mobile apps. Automation eliminates repetitive tasks that may be repeated just a couple of times a year earlier. But now, with Agile methods adopted, we can witness a release every fifteen days or so in the mobile app department, among which WhatsApp is a prime example.
This makes our preference towards automation testing even stronger, and hence we move in the direction of frameworks that may ease out the pain of automation and manual simultaneously.
How to install Appium to test applications?
To run the tests using Appium, we first need to have the framework installed on the system with all its libraries and capabilities. This can be achieved in one of the following two ways:
- Through NPM.
- Through Appium Desktop.
For your convenience, we will look at both of them. However, NPM being the popular choice among the two, we will carry on with the next steps using the same.
Installing Appium using NPM or NVM
NPM (Node Package Manager) is used for JavaScript-based downloads. It works through the command line interface and fetches libraries and setups from its cloud repository called npm registry. When we execute the NPM command, these packages are fetched, downloaded, and installed from a single command. It is a more powerful, easy, and popular way of installing packages such as Appium.
Since npm requires a JavaScript-based server, we need to download and install Node.js first if we are installing Appium using NPM. This can be either done through their official website or using Homebrew by running the following command:
brew install node
Once NPM is installed, the tester can run the following command to install Appium directly from the command line using the node package manager:
npm install -g appium
Alternatively, you can use nvm (Node Version Manager) from their official repository link. This is a Node-specific manager and therefore a simple command as:
nvm install <version>
will install Node.js version <version> directly. For the LTS version, you can run the command:
nvm install --lts
Install Appium using Appium Desktop
Testers and developers who would like to bypass the CLI and package managers for installing Appium can do so by opting for installation through the Appium desktop.
Appium desktop is the direct installation using binary files and proceeds similarly to how any software will be installed graphically. This can be done by downloading the binary from their official release page. One of these two methods will bring Appium to your local system.
How to install driver setup for Appium?
Once Appium is downloaded and installed, we need to have specific drivers for the specific needs of our projects. This will depend on the type of application we are looking to automate through Appium. For example, do we want to automate an iOS app? Or do we want to automate a macOS app?
Drivers help testers gain access to specific technologies developed by the operating system provider (mostly) that help test the application more efficiently. Since this post is specific to an iOS application, we will be inclined towards a demonstration of XCUITest Driver only. However, you can refer to the following drivers for different automation needs:
- Espresso Driver for Android apps.
- UiAutomator2 Driver for Android apps.
- Windows Driver for Windows Desktop apps.
- Mac Driver for Mac Desktop apps.
Let’s see how we can start testing iOS apps through Appium with XCUITest Driver.
A brief guide to setup XCUITest driver for Appium
XCUITest driver is used for executing tests on iOS devices using Appium. The download can be done from their official repo or through npm by running the following command:
npm i appium-xcuitest-driver
If you are comfortable with XCTest provided by Apple, then the driver will feel just as familiar because it uses XCTest for native testing. Apart from this, there are a few prerequisites that a tester might need to go through before starting the actual testing part.
Pre-requisites for XCUITest Driver setup
The following pre-requisite will help set things up quickly for a tester.
- To communicate with real iOS devices, you will need Appium APIs installed in your system to leverage them on the code.
- Make sure that iOS testing is done on a macOS device only, as it is compatible with XCUITest Driver.
- To use the XCUITest driver, XCode and developer tools need to be installed on the system beforehand.
- Real devices connected to your developer profile must be configured properly with WebDriverAgent signing.
- xcpretty tool can be installed for better readability of the output. You can use the gem install xcpretty command for the same.
- XCode version 7 or higher is required.
- Please check the compatibility of Xcode with the XCUITest driver.
Minimum XCUITest driver version | Minimum required Xcode version |
2.96.0 | Xcode 9 |
3.0.0 | Xcode 10 |
3.32.0 | Xcode 10.2 |
3.56.0 | Xcode 11 |
4.2.0 | Xcode 12 |
Keeping all these things in mind and installing the software mentioned above will construct a good infrastructure on the local system to commence testing.
How to start the Appium server?
After setting up, you can start the Appium server by just typing “appium” in the command line. However, if your installation was not through npm but through Appium desktop, you may need to open the application from the shortcut created on the desktop or from the menu list.
Pre-requisites to run iOS tests on Appium
To run your iOS tests on Appium, we need to download a few extra modules to help us build and execute the tests. The modules defined here are necessary for testing, but these specific modules need not be downloaded. If the work done by module A can be done by module B and you find it suitable, you can move ahead with that. Also, just so you know, these modules are specific to iOS-based tests. If you are looking to test Android applications, you may need a different set.
First, we need carthage to manage dependencies. This can be installed as:
brew install carthage
Next, we need software that can talk to iOS devices and native protocols. This can be achieved through libimobiledevice. The module can be installed as:
brew install libimobiledevice
libimobiledevice is a popular library and does not require jailbreaking to manage communication.To install and debug iOS applications from the command line, we need ios-deploy library. Similar to libimobiledevice, this library is also popular and does not require jailbreak.
brew install ios-deploy
Please note that these installations are demonstrated using Homebrew. However, you can do the same using npm also. Once everything is installed, we are ready to create and execute our first iOS application test.
Running your first iOS test in Appium
A basic iOS test is very easy to construct and run in Appium. Before that, first, we need to declare the desired capabilities as follows:
@BeforeTest
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "16.2");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 13");
capabilities.setCapability(MobileCapabilityType.APP, myApp);
Then, we need to make sure that webDriver is connected, initialize its instance, and set the remote session to connect capabilities on port 4723.
driver = new IOSDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities);
Port 4723 is the default for Appium. The tester can change it by passing the -p flag with the port number while initializing the Appium server.
Next, we write the code to delete the driver that will be called after @Test is executed.
@AfterTest
public void quitDriver() {
driver.quit();
}
The @Test code to locate an element can be written as follows:
public void testLocateAnElement() {
driver.findElementById("Index Element");
}
}
In this section, you can write the test logic as per your requirement and execute tests accordingly.
Once you get hold of this, the test can be executed on the same port on which the server was started.
How to automate an iOS app on a real device cloud?
While Appium is one of the most popular mobile test automation frameworks for iOS as well as Android, a tester still needs to download and install the iOS devices. Not only that, the devices available through the Appium library are not real devices but simulators and emulators. While they have their own advantages, testing should be performed on real devices even if done partially so.
For this, manually acquiring iOS real devices could prove to be extremely expensive and not feasible when it comes to maintenance. A better way is to use a real device cloud where tests are yours, but infrastructure and devices are theirs.
Testsigma is one such cloud platform that lets you access real iOS devices for testing. As a tester, all we need to do is sign up on the platform and execute our tests directly. But do we really need Appium when we have Testsigma?
Appium demands two primary things – expertise in programming language and expertise in third-party modules. In this post, we downloaded four-five modules even though the tests were so simple. Besides, it can take a lot of time and may filter out suitable candidates who might be good at testing but not in programming.
The solution to this is Testsigma. The platform executes the tests in a codeless testing paradigm, meaning it just requires the testers to write tests in English rather than any language. Along with it, Testsigma comes with a lot of integrations and a mobile recorder that can convert actions into test cases. So if a tester presses Log In button, it is converted to “click Log In” automatically.
These tests are reusable and can be worked on any device any number of times. To know more about this, you can refer to Testsigma vs Appium guide and let us know any feedback here.
Best Practices for running Appium tests on iOS devices
What things can we keep in mind before and while running Appium tests on iOS devices?
- Using real iOS devices is an added advantage and should always be preferred if within your budget.
- Make a list of all the modules you would require during the testing. Verify their compatibility in the working and versions.
- Keep apps installed before starting the testing part.
- Adopt a cloud infrastructure if possible. It will help you lighten the load of resources.
Wrapping up
Appium is a cross-platform application testing framework that is open-source and powerful enough to execute all types of tests a tester wants. And shouldn’t it be as commanding as it portrays? Given that the iOS application market is always rising with billions depending on in-app purchases, applications should not only solve a good problem but also work swiftly without any glitches.
Appium seems to solve this problem by offering things such as testing the same app which is shipped etc. In this post, we highlighted the need for Appium and how it can be installed on the local system. Later, we executed a simple test to demonstrate the working and what things a tester might need before starting the testing part.
Wrapping this post with best practices to follow, I hope this post serves you well in your iOS app testing projects using Appium or real device cloud. For any suggestions and queries, let us know in the comment section. Thank you for giving this post your valuable time.
Frequently Asked Questions
How to use Appium for iOS on Windows?
Appium can be used by Windows users to test iOS by installing it either through a package manager or through Appium Desktop. Popular package managers such as npm and brew will install Appium to the CLI. On the other side, Appium desktop provides a graphical interface for the same.
What are the disadvantages of Appium?
As popular as Appium has been in the past decade, comparing it with the latest testing trends, we can uncover a few disadvantages:
- Need for programming language: Appium supports a ton of programming languages. However, the testing trend has recently started to shift towards codeless testing, which may make learning programming a bit exhaustive and added work for the tester.
- Maintenance: With scripted testing comes the heavy cost of maintaining it, that sometimes practically takes more time than scripting itself.
- A bit slower: Appium can be said to be a bit slower than cloud-based alternatives.
What platforms does Appium support?
Appium is a cross-platform testing framework with support for iOS, Android, macOS as well as Windows.