In today’s DevOps era, continuous development and continuous deployment is the key objective of software development environments. The code is continuously developed and continuously tested too. Automation testing tools are the key to continuously deploying applications. Selenium is a popular testing automation tool that helps Selenium developers to integrate continuous testing into development. It supports multiple browsers, platforms, and operating systems.
However, the proliferation of smartphones has brought a wide range of devices, platforms, and OSes into the market. Earlier, mobile screens were small and the design was not user friendly. That has changed with the screens of today. Mobile-first apps are now the new trend. This requires businesses to realign their testing strategies to accommodate mobile app solutions.
Mobile apps are easy to use and more accessible. Today, more people use mobile devices to shop online or subscribe to any service. Now 60% of business resources are accessed by mobile. However, most testers are using Selenium mobile testing when compared with Appium to test automation solutions.
Does Selenium support mobile app testing? While it doesn’t directly support mobile testing, it offers frameworks to test mobile apps. Selendriod is a Selenium-based mobile testing framework that enables businesses to run automated tests on Android devices. However, the options are limited here. This is where Appium comes to the rescue of Selenium mobile testing developers. Appium is a powerful mobile automation testing framework that is based on Selenium and offers cross-platform and cross-technology support. You can write single test code for both Android and iOS here.
Selenium and Appium use the same protocol; JSON Wire protocol. This protocol recently became a standard W3C protocol. Today, many industries, as well as browser providers, are implementing it as a standard protocol.
Selenium allows you to write code in different languages such as Java, PHP, C#, and Python. The code is executed via the JSON Wire protocol. This protocol is a REST API that is used to control the browser. When the code is executed as an HTTP REST request, a new session is created by the Selenium server. It then invokes the browser driver (Chrome driver, Safari driver, and Edge driver) to access the browser. The browser sends the requested information to the Selenium server via the browser driver which is then sent to the client.
Selenium Grid Components
Selenium Grid contains 3 main components. The Selenium Grid Hub is the server machine that distributes the test job to nodes. The server machine will decide which node will receive the test based on the predefined desired capabilities. The Selenium Grid Node is the machine that runs the tests received from the hub. Each server can have multiple nodes. The wd/hub is the URL part that facilitates communication between the hub and the node.
The idea here is to run dummy endless tests on mobile devices. In iOS, it runs the XCUITest. The tests are controlled by the server.
Installing Appium for Android is pretty simple. However, it gets slightly complicated when you are dealing with iOS devices. The main challenge is that you cannot simply take an application and install it on the device. As you are specifically dealing with developer applications, every application should be signed to the device. When you are using emulators, you can bypass certain things. In addition, you need an Apple developer ID, valid development certificate, provisioning profile, signed .ipa file, XCode, and command line developer tools. Moreover, you are required to set up the device for development in XCode.
For instance, if you are using Java, you need to perform the following tasks:
- Configure Java
- Install Homebrew
- Next, Install node.js and npm
- Then, Install Appium
- npm install –g appium
- Finally, install wd
- npm install wd
- configure appium ioS device that will install ilibmobiledevice
- configure XCUITest driver
You can check this tutorial for walkthrough steps to install Appium
To test Android apps, you can use Windows, MAC, Linux machines. However, to test iOS apps, you need a MAC device. The cloud works for both iOS and Android applications.
Mobile Device Vs Browser
Before moving onto mobile testing, it is important to understand the environmental differences between mobile devices and browsers.
- Gestures: Mobile devices use different input options or gestures such as swiping, pinching, two-finger touch, multi-finger touch, etc. which is not available in web browsers.
- Different URL system: Mobile apps are specific to mobile devices wherein you don’t have regular web URLs.
- Real Devices & Emulators: You test on real devices and simulators. For Android, you use the same apks for both options. However, in iOS, you use different technologies for real devices and simulators because simulators run on x64 while real devices use arm processors. So, you’ll have to perform testing on both options.
- Buttons: Mobile devices come with buttons such as Home, power, and volume. You have to consider them while testing.
- Home Screen: Mobile devices have a Home screen with a notification bar. So, interactions on the home screen should be considered.
- Rotating Screen: Mobile screen can be changed to portrait and landscape wherein the screen size changes.
- Different Network Connections: The network conditions such as 2G, 3G, 4G, 5G should be considered. Especially functional testing should be done at different internet speeds.
Mobile Apps Vs Web Apps
When it comes to applications, mobile apps are different from their web counterparts:
- Application Lifecycle: The mobile app lifecycle is different and complex. You can install, uninstall, launch and close apps.
- Stateful navigation: Mobile apps remember your session and respond accordingly when you login the next time. It is more stateful. Navigation is simple too
- DOM UI technologies: are different for iOS and Android
- Debugging tool: (eg: F12 in Chrome) is not available.
For local capabilities, you should specify the following details:
- platformName: Specify the platform (ioS / Android)
- deviceName: Specify the device name ( As you’ll be using multiple devices)
- automationName: Specify the automation technology used (eg: XCUITest for iOS)
- app: To install an application, specify the apk path
- bundleId/appActivity: Specify the bundle ID of the app. When it comes to Android, there are bundle activity and specific activity that you can launch in your application. However, for iOS, you only have bundle activity.
When Selenium Developers use the cloud technology:
- accessKey: Access key gives access to remote testing
- deviceQuery: To find the devices using in the cloud
To overload mobile commands, Selenium developers can use ExecuteScript. Some of the mobile commands related to application:
Some examples of device commands
You can find all the available commands in this Appium page:
How to create a mobile test using Selenium and Appium?
Step 1: Create Gradle File
To start the test, open your IDE. For instance, if you are using Java, you can go to IntelliJ IDE
- Create a new project
- Select Gradle ( You can use other options such as maven)
- Give a name to the Project(eg: Selenium 2)
- Click Finish
Step 2: Add Selenium into Gradle
- To add code for Selenium Gradle, go to Google and search for Selenium Gradle.
- Open the Maven repository link: https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/2.41.0
- Click on the newest version
- When you click the new version, it shows the new version. However, it is now showing the alpha version. Click on Selenium Java.
- Choose the latest version on the next page
- Copy the code from this next page and paste it in the IDE dependencies box. It will download all the required dependencies, in case your device doesn’t have them.
- We will use TestNG for this test. So, import Selenium TestNG and Chrome driver. You can download the chrome driver here: https://chromedriver.chromium.org/
- Create a new package (directory) and name it ( eg: William.demo)
- Create a class (eg: williamSeleniumdemo)
- Now you are ready with all the required elements. Write the code for a Selenium test
- For instance, driver.get() to open a URL and wait for the page to load
- Driver.navigate () to navigate between pages
- driver.quit() to close all browsers
- Execute the test
Testing iOS devices using Appium is slightly complex when compared with Android devices. So, this test guide will use the iOS device for testing.
- Open the IntelliJ IDE.
- Add Appium dependencies into the Gradle (remove Selenium dependencies, if any)
- Install the iOS driver ( WebDriver doesn’t have specific iOS commands)
- Selenium Developers can use the Selenium test as the baseline and make changes to it to make it as the iOS test.
- Define desired capabilities (It will help you set a map of key values to define the way to login to cloud format, application launch etc.)
- You need an access key to access devices. So, go to your cloud environment and create an access key.
- Create a name for the test ( eg: WilliamAppium test)
- Select the application to use and get the bundle ID. You can go to the cloud environment and upload the application to the device too.
- Define the MobileCapabilityType
- Initiate the driver by creating a new iOS driver and provide the wd URL
- Now, run the test from the IDE. It will launch the driver and run the test on mobile devices.
- Go to the cloud page and open the device to see a live view of how the application is installed, launched and closed.
Running the test from Appium App
- Go to Appium
- Create a new session
- There are multiple cloud providers. Choose one cloud provider
- Enter the user name and the access key
- Define the platform name ( eg: iOS)
- Define the DeviceQuery ( eg: os=iOS)
- Click on start session
- The device will be automatically selected. You can use the Appium desktop to identify different elements and the properties of the elements.
- Write the code
- Sendkeys() (username and password)
- Execute the code. Now, it will select a different device
- Go to the cloud and check how the test is running on different devices.
- You can put in a breakpoint for debugging.
That’s it! Now Selenium developers have successfully run the tests using Appium.