You are currently viewing Mobile Test Automation

Mobile Test Automation

  • By Ruchi Parijat
  • Post category:Engineering
  • Reading time:9 mins read

In the past few years mobile app development has become a booming industry. It is estimated that there are 2.3 million mobile app developers who are devoted to keeping up with the industry demand. In 2021 there were approx 230 billion global app downloads. In 2021 app store spend hit $170 billion worldwide, an increase of 30 percent year-over-year.

Few years ago, apple mentioned , 1.25 million apps were registered in the Apple app store and accounted for 50 billion downloads and $5 billion paid to developers. With these types of industry numbers, it soon becomes clear that mobile app development is a key factor for business success. 

Globally, the average mobile user spent 4.8 hours on their mobile devices.  In 2021,  53.96% of web traffic comes from mobile phones. With that aim to ease logistics solutions, we wanted to get on with mobile application of shiprocket. With the growing number of people accessing the Internet via smartphones and tablets, mobile app development has the unique ability to access a large number of potential consumers. The reason behind these exceptional numbers lies in the continued growth of smartphone and tablet sales. Mobile users don’t just find their devices convenient, they are dependent on them. Given the continued increase in dependence on mobile, it’s critical to adapt business models to match key audiences’ behavior. If a large majority of your audience is mobile-first or mobile-only, your business needs to communicate with them based on their preference.  

As a business there were multiple benefits for us to create mobile app. 

  1. Mobile apps work to consistently increase customer loyalty, especially in the logistics sector. They tend to get all the information about packed, shipped, in-transit to delivered on their cellphones. 
  2. Mobile applications increase your visibility.

As we continued to evolve into a mobile-centric society, it comes as no surprise that mobile apps are at the center of the developmental push. Developing a mobile app can go a long ways towards propelling our company into the hands of new customers and future business success.

Downloads of our mobile app in 2019 were approximately 35000 . In 2020, we have observed tremendous change in that stats. Numbers grew in an outstanding ratio. Eventually our business expanded. And now, our usual total active users on a daily basis are 21500 approx. We were supposed to release new features every now and then.  We came forward with so many releases and changes for customers that it was impossible for us to test everything manually before every release. Hence, we came up with automation testing using espresso. 

Problem statement 

This time we had multiple challenges. Where to test? What to test? And how to test?

With an increase in demand for features, team of product managers and engineers were trying to figure out multiple problems. As it is known, you can only find optimal solutions only if you know your problem statements. 

  1. Testing was supposed to be done across multiple devices. 
  2. Testing the whole application for every continuous release was important.
  3. Testing was supposed to be done for all of the critical scenarios, repeatedly. 

Infact, the team also faced some challenges while implementing these solutions. 

  1. Identifying all the critical scenarios. 
  2. Building these critical scenarios in google test labs. 
  3. Identification of  ID for the CTA (call to action)

 More set of challenges were even crucial and critical. 

  1. Finding the problems in software products.
  2. Confirming that the software is up to end user requirements.
  3. Enhancement of  software quality.
  4. Reducing the maintenance and software support costs.
  5. Avoid post deployment risks.
  6. Compliance check with the software development processes.
  7. Helping developers to make software delivery decisions. 

Potential Solution

When you write an Android/ ios app, you need to check that it is working as expected. One way to do that, is to manually go through scenarios clicking buttons, typing tests just like new users do. However, that is very tedious. Automated testing allows you to execute and verify your app automatically. Most people think of testing as a way to catch bugs but writing a testable app needs proper separation of concerns, which means you will end up with highly modular code. And with proper architecture, testing allows you to implement features faster. 

One common way to think about testing is the testing pyramid. It talks about three types of tests. Unit tests, integration tests and end to end tests. The testing pyramid is a visual way to represent the ideal distribution of tests. We tested the fundamental building blocks with unit tests which makes up the bulk of our tests. Then we verified  how the units interact with each other with integration tests. Finally we had a small number of end to end tests to make sure the whole system works.

Source: Internet

Hence, We decided to go ahead with espresso due to multiple reasons, as stated. 

  1. Espresso Framework can be categorized between black box and white box testing, commonly called as gray box testing framework.
  2. It is most optimal during end to end testing. 
  3. Accessibility testing is possible in Native Espresso.
  4. Requires the entire code base to run the test.
  5. For testing webviews, Espresso internally uses WebDriver APIs to control the behavior of a webview.

Implementation Route

Before we jump onto test cases, there are three components we should know. 

  1. ViewMatchers

Views are always in a hierarchy called the View Hierarchy. For the test cases to navigate the view hierarchy, ViewMatchers are used. Technically, they are a collection of objects and they implement the Matcher interface. Testers will be able to pass one or more of these objects to the OnView() method provided by Espresso Component.

  1.  ViewActions

These components define the action that has to be performed on any given View. Espresso allows testers to send more than one ViewAction as a collection to the Interaction method. An example of a view action would be the click() method which helps a test script click on a given View’s UI component.

  1.  ViewAssertions

Assertions complete a test case. They are the components that check if the test has passed or failed. In Espresso Android, the ViewAssertions can be passed to the Check() method from the ViewInteraction package. Matches assertion is the most commonly used to check which verifies the final state of the view with what is expected.

You must be thinking that how all of this was implemented for our product.Given is an example of our implementation in the login module.  Initially, it will find the Email EditText on screen using the code onView(allOf(withId(R.id.email))). This is known as ViewMatcher.  Followed  by that, it will fetch input in Email EditText using the code emailEditText.perform(replaceText(“dummy@gmail.com“)).  It is addressed as ViewAction. 

Now, it will find Password EditText using functionality of ViewMatcher. 

In order to generate input in Password EditText, functionality of ViewAction is performed. 

Now again, we have to find Sign-In Button, so we will use the functionality of ViewMatcher. 

As we have to click on Sign-In Button, we will perform the functionality of ViewAction. 

Next step is to verify that you landed on Home screen by checking view in home screen 

find Quick Actions in Home Page.

Final step to check if it has the same text or some other condition according to your application.Hence, functionality of ViewAssertion is used. 

If ViewAssertion passes that means you have landed on the correct screen and login was successful, else the test case fails.

For detailed explanation, check out table 1.1

FunctionFunctionality
finds the E-mail EditTextViewMatcher
enters input in E-mail EditTextViewAction
find Password EditTextViewMatcher
enter input in Password EditTextViewAction
find Sign-In ButtonViewMatcher
click Sign-In ButtonViewAction
find Quick ActionsViewMatcher
check if it has the same text or some other condition according to your applicationViewAssertion

You can find video attached for more more specifics. 

Comparative Analysis

Mobile application development can be very different from developing software for desktops. Mobile development is usually agile, and a lot of tools and practices have been created to facilitate that agility. However, when it comes to testing an app (manually) we tend to lose some of that agility. This is why test automation has shown great progress among app developers, speeding up the process and delivering better results.

In order to ensure compatibility between devices, users, and markets, test automation is a fantastic option for developers. Test automation added a significant value by enabling testing to be done in parallel with development.

Let’s see how test automation has improved the development process, add value and speed up development.

Source: Internet

Test automation has provided a good return on investment. For example, once test cases have been developed, tests can be run repetitively without any additional cost and these can be swiftly executed as compared to the manual tests. This can decrease the time required to run repetitive tests from weeks to hours. This is an important time-saving that converts directly into cost-saving.

As far as testing cycle is considered, Tests have to be repetitive, often during all development cycles to guarantee the best possible quality of an application. Every time code is modified, tests should be reiterated. For every release, our app is tested on all supported variants of operating systems and all devices. As it is imaginable, manually reiterating these tests is expensive and time-consuming. For example, executing complete tests manually on all variations of Android and on actual devices takes a lot of time.

Given is the graph that shows rough estimation of release rate with and without automation wrt cost.

Source: Internet

Steady state

Testing is vital to guarantee success in the extremely competitive market of mobile apps. Automated testing improves business results in three ways: greater testing efficiency, greater testing effectiveness and a shorter time to market. So far we have automated approximately 10 critical modules so far. 

We have planned to get started with further modules, scaling up automation to most of the modules of our application.