How to Automate Mobile Application Testing Using Selenium

Selenium is an open-source testing tool that is primarily used for regression testing and functional testing. Identified as a collection of software testing tools, the Selenium suite can be used to automate web browser testing. Speaking of mobile application testing, it is a well-known fact that you as a tester must have heard about Selenium. And if you are curious to know whether Selenium can be used to automate mobile application testing, the following detailed explanation will throw light on your queries.
app testing
To answer the question “Can Selenium be a mobile application testing tool?” the answer is negative. But the good news is that you can make the most of the Selenium to test mobile websites. This is definitely a reason that can cheer you up. And there are a couple of another reasons that will make you smile.
Selenium, as an open-source testing tool, does not involve any licensing cost and hence ranks above over other testing tools that are currently employed. While you cannot use Selenium to automate mobile application testing, you are at an advantage to employ the frameworks of Selenium that are exclusively designed for mobile automated testing.
Selenium Frameworks Designed for Automating Mobile Application Testing

  1. Selendroid
  2. Appium

Selendroid:
In line with this very name, Selendroid is a Selenium framework that can be employed to test the user interface of native and hybrid applications that can be run on the Android platform. It is also important to note that while the Selendroid framework is suitable for emulators, it also can find its place in the Selenium Grid, when the framework can be integrated with real devices. Essentially meant to perform parallel testing and scaling, the Selendroid framework allows you to simultaneously communicate with multiple Android devices.
Selenium Appium: 
Selenium Appium is an automated, open source test framework that can be employed to test mobile user interfaces that come with native, hybrid and mobile web applications. It is also a cross-platform tool that can is compatible with many languages including Node.JS, PHP, Java, Objective-C, JavaScript, Clojure, C#, Python and Perl. You as a tester can make the most of its cross-platform characteristic when you can effortlessly employ Selenium Appium through a single test script to perform tests on Android, Windows, Mac, Linux or iOS platforms.
A Dozen Simple Steps Involved in Automating Mobile Application Testing Using Selenium Appium
1. Your first step is to visit http://appium.io. You then need to download the Appium framework along with sample files as demonstrated under:
appium-mobile-app-automation-screenshot
2. The next step is to unzip the downloaded files.
3. Proceed further by downloading and setting up Android-SDK file on to your computer.
4. Check out the Android-SDK framework and identify the AVD Manager application. This is to create a “Default”            Android Virtual Device.
5. The next step is to run Eclipse.
6. You then need to access the unzipped folder to import the Java->JUnit sample code according to the following              illustration.
import-screenshot
 
appium-master-screenshot
 
7. After the previous step, this is what you will get to see; the imported Java project structure.
src-screenshot
8. You are now all set to execute the Appium.exe file which is saved in the unzipped folder, as demonstrated below.
appium-desktop-screenshot
9. You can now launch the Appium server window that will show up as under.
appium-server-window-screenshot
10. Without any hassles, you can change the AndroidContactsTest.java file according to your requirements.
11. You can now run the Java class as JUnitTest as depicted below.
package-explorer-screenshot
12. Your outcome will be that the application has passed the test.
Voila! These simple steps when performed in series will grant you the power of Selenium Appium to automate mobile application testing.

5 Major Types of Test Automation Frameworks

Test automation frameworks uses a software to execute tests and then determine whether the resulted outcomes and the predicted outcomes are the same or not. Every organization needs software testing adequately, as quickly and thoroughly as possible. To accomplish this, organizations are turning to use automated testing methods.
As test automation frameworks are application independent, it has the ability to expand with the needs of each application. It promotes automation technologies to improve test coverage and gain better quality products. These frameworks help testers to save thousands of manual test execution hours and reduce costs significantly.
Let’s briefly look into the 5 main test automation categories and its functions:

#1) Linear Automation Framework:
This is the most simple framework of all types. Here, individual scripts are used for each test case and they are executed individually. This process enables the conversion of small or medium sized manual scripts to corresponding automation scripts.
Key Features:

  • Very little planning is required to work with this framework
  • Testing doesn’t take much time
  • A tester does not need detailed knowledge of the framework as it uses record and playback to create linear scripts
  • Created scripts are independent of each other

#2) Module-based Testing Framework:
This framework is based on object oriented programming method and uses the concept of abstraction. While testing, the application is divided into different modules, where each module consists of individual test scripts. The separation of modules is done using an abstraction layer, so that if any changes occur, it wouldn’t affect the other modules.
Key Features:

  • This framework includes a high level of modularization, which reduces cost and makes maintenance much easier
  • It’s pretty much scalable
  • If defects are detected, only that part of the test script needs to be changed. The rest remains untouched
  • Create new driver scripts for performing tests easily

#3) Data-Driven Testing Framework:
In this type of testing, the necessary inputs and expected output results are stored in separate data files. Here, a single driver test can execute all the necessary test cases with different sets of data. A driver script consists of functions like reading the data files, navigating through the entire program etc.
Key Features:

  • It reduces the number of overall test scripts to implement all the available test cases
  • Test data used can be created before test implementation gets ready or even before the testing system or environment is set up
  • When it comes to maintenance and fixing of bugs, this framework ensures greater flexibility
  • To generate test cases, less amount of codes are used

#4) Keyword-Driven Testing Framework:
This is an application independent framework that utilizes data tables and self-descriptive keywords, which explain the functions to be performed on the testing application.
The external input data file showcases the functions through ‘directives’, which are seen within the test scripts. These directives are called keywords. Therefore, this keyword based testing is considered to be an extension of the data-driven framework.
Key Features:

  • Keywords can be re-used in multiple test cases
  • An automation expertise is not required to create new or maintain the existing test cases
  • Reduce the number of overall test scripts
  • Use a minimal amount of codes to generate test cases
  • For each test, the functionalities are documented in a table as step by step instructions

#5) Selenium Automation Framework (SAF):
SAF is the most widely used, customized, open-source framework today for automated web application testing. As it reduces the initial coding efforts, SAF increases the efficiency of automation than any other framework.
SAF helps enterprises to speed up the testing mechanism by using accelerators at the test design layer and provides a comprehensive reporting strategy for managing tests.
Key Features:

  • Intuitive and user-friendly interface for creating and executing test suites
  • Flexible, robust and extensible framework to carry out test automation on diverse sets
  • Enables users to perform multiple testing processes for web apps
  • Detailed reports on test execution results with consolidated summary and snapshot of errors
  • SAF is built on open source tools, libraries or frameworks that reduce cost for users
  • Avoid redundancy on test case execution
  • Increased test coverage to enhance quality and reliability of the end product
  • Has high interaction with Selenium community, therefore, enables quick updates and shorter learning curve
  • Increases flexibility of used resource and time


In order to move with the pace of software testing process, development and delivery, it is essential to implement the most effective, reliable and reusable test automation frameworks. It’s not advisable to still hang on to the traditional methods as tools alone can never provide a long-term automation success, when compared to the other latest test automation frameworks.

Top 5 Automation Testing Tools for Android

Automation testing is used these days in almost all the test processes. The advantage of a reduced testing time along with reduction in error has led to its widespread acceptance among software testers. With a wide variety of testing tools available for this purpose, one should be aware of their features to better understand them.
automation testing
Choosing a single tool to support you entire project is rather impossible, since most tools may not be able to fully correspond to you project. Here we discuss the top 5 tools that have been the most sought after by Android testers around the globe.
1.Robotium Android Testing Tool
Pros
It is one of the first and frequently used automation tools for Android software testing. Robotium, a free Android UI testing tool is suitable for test automation of different Android versions. Often referred to as Selenium by Android Software developers, the tests created by Robotium are written in Java. Robotium is also a library for unit tests.
Cons
But Robotium is time consuming and needs much more effort to create tests in it. This is because in order to automate tests, one must work with the program source code. Also the tool is unsuitable for interacting with system software; it is incapable of locking and unlocking smart phones or tablets. Robotium does not have a record or a play function and it also does not provide screenshots. As part of continuous integration, Robotium incorporates easily with Maven, Gradle or Ant for the execution of tests.
2.MonkeyRunner
Pros
This is a popular Android app testing tool used for the automation of functional tests for Android software. This tool is more low-level when compared to Robotium, but does not have to work with the source code in order to automate tests. Written in Python, it also gives provision of using a recording tool for creating tests.
With MonkeyRunner, it is possible to run tests on real devices connected to a PC or emulators. The API within the tool helps to control a smart phone, a tablet or an emulator from outside of the Android code.
Cons
The biggest disadvantage of this mobile app testing tool is the necessity of writing scripts for each device. Another drawback is the need for a test to be adjusted each time the user interface of a test program changes.
3.Appium Android Automation Framework
Pros
Appium is used to test iOS and Android native mobile web and hybrid applications. While native apps are written with the help of iOS or Android SDKs, mobile web apps can be opened on mobile browsers and hybrid apps are totally involved with “webview”. It is an open-source mobile automation tool.
The running of tests does not require any changes to be made in the source code which is a huge advantage. The Selenium JSON Wire Protocol used in Appium allows you to write the test in any language supported by Selenium. Appium facilitates testers to reuse the code between iOS and Android test suites even though it is considered a “cross-platform” tool.
Cons
The advantages are in plenty, but it would be a sin not to discuss its drawbacks as well. It takes a long time to configure appium for both android and iOS and also is prone to too many unexpected errors.
4.UI Automator
Pros
UI Automator allows you to do more in Android app testing and games when compared to the basic framework that is Robotium. You can test the user interface (UI) of your native Android apps on one or more devices with Google’s test framework. Another advantage of UI Automator is that the cases can span across different processes with JUnit test cases having special privileges. It also provides five different classes for developers.
app testing
Cons
UI Automator has its downsides, one of them being it only works on Android devices with API level of 16 or higher. Another drawback of UI Automator is its lack of support for webview, were directly accessing Android objects is not possible.
5.Espresso
Pros
It is the latest Android test automation framework open-sourced by Google. It is available for developers and software testers to work on their UIs. Its API is small and predictable making it easy to learn and above all built on top of the Android instrumentation framework.
It helps to write concise and reliable Android UI tests and is supported on API level 8 (Froyo), 10 (Gingerbread), and 15 (Ice Cream Sandwich) till current versions.
Its reliability and the ability to synchronize with the UI thread makes it fast since there is no need for any sleeps.
Cons
Just like UI Automator, it too suffers the drawback of not supporting webviews.

6 Popular Myths in Test Automation You Must Know

Despite the several benefits test automation has to offer, many software testers still find excuses to not completely utilize these benefits. Faster releases, quicker feedback, frequent test execution, increased test coverage to development team are a few of the many advantages it possesses. Quite a few myths surround test automation and this blog will help you to identify them and embrace what it has to offer.
app testing
The most challenging task for a software tester when it comes to test automation is to understand its limitations and set goals accordingly.
Myths Surrounding Automated Testing

  • Myth #1: It’s better than Manual Testing
  • For those who claim this, you need to understand one thing; automated testing is not testing per se. It is checking of facts. When we have certain knowledge about a system under test, we enforce checks in the form of automated testing. The result of such a check will help confirm our understanding of the system.

However testing is a form of investigation, which gives us new information about the system under test. Hence we should refrain from being lenient to one or the other since both methods are required to get quality insight about an application.

  • Myth #2: 100% Automated Testing
  • 100% test coverage is impossible to achieve; and the same goes for test automation. While it is possible for us to increase test coverage by using more data, configurations, covering various operating systems and browsers, achieving 100% is an unrealistic goal.

More tests don’t mean better quality or confidence. The important thing is how good your test design is. Focus need to be put on the more important areas of functionality rather that chasing a full coverage.

  • Myth #3: Quick ROI Every Time
  • When implementing a test automation solution, the development of a framework is necessary and this will support operations.  This can be useful and meaningful for test case selection, reporting, data driven, etc. The framework development should be considered as a project on its own and thus requires an array of skilled developers. The process is also a time consuming one.

Scripting automated checks takes longer initially even with a fully functional framework. Hence when it is necessary to provide a quick feedback on the new feature, checking it manually is faster.

  • Myth #4: Automated Checks Have Higher Defect Detection Rate
  • While it is true that vendor-supplied or home-made test automation solutions are highly capable of performing complex operations; they will never be able to replace a human software tester. He is capable of identifying even the most subtle anomalies in the application.

An automated check is capable of checking only what they were programmed to. Therefore the scripts are only as good as the person who wrote them. If not scripted properly the automation test can easily overlook major flaws in these applications. In short, checking can prove the presence of a defect, but not necessary its absence.

  • Myth #5: Unit Test Automation is All That We Need
  • It should be understood that a unit test is only capable of identifying programmer errors and not his failures. When all the components are tied together to form a system, a much larger aspect of testing comes into the limelight. Most organization has their automated checks at the system UI layer.

The sheer volatility of the functionalities during development makes the process of scripting automated checks a tedious task. Spending time on automation for a functionality that might change is not advisable and may cause difficulties in the later stages of development.

  • Myth #6: System UI Automation is everything
  • Relying solely on automated checks, especially at UI layer can have a truck-load of negative impacts. The development stage will face numerous changes in the UI in the form of enhanced visual design and usability. If a similar change in the functionality is not in place a false impression about the state of the application will be indicated in the checks.

automation testing
Automation checks in the UI layer has a slower execution speed compared to the ones in the unit and API layers. This will result in a slower feedback process to the team. The root cause analysis takes longer as the exact location of the bug is unknown. Therefore it becomes necessary to identify the layers where the use of an automated test may become helpful.
Automated checks is not a onetime thing, it needs constant monitoring and updating. Above all you need to understand the limitations and set realistic goals to get the most out of you automated checks and most importantly your team.