Tech

Getting started with Automated mobile testing

Table of contents

Hello, readers!

I’m a QA specialist in Uptech, a Design & Development company which creates mobile and web apps. Today I want to enrich your knowledge about automated mobile testing. In this article, you will find step by step guide along with a simple example of automation testing 💁💻.

What do we need for automation?

I am going to tell you about creating tests using Cucumber, Appium, and Java in IntelliJ Idea. Next, we will learn how to write a sample feature and automate testing. Let’s get started!

Appium — a framework that allows you to write simple automated tests for your mobile apps and websites.

Cucumber — a framework which supports behaviour driven development.

Gradle — a build tool.

JUnit — a framework for running tests.

How to set up an automated testing?

Appium is a powerful tool for testing, but it is not straightforward and easy to install. The documentation does not provide a good tutorial to get things working fast. In this post, I am going to provide everything you need to set up Appium for running a basic test scenario written in Java.

First of all, we need to setup all the components:

Step 1: Install Java

Step 2: Install Android Studio

Step 3: Add JAVA_HOME and ANDROID_HOME to the environment variable

Step 4: Configure Emulator in Android Studio

Step 5: Install Node.js

Step 6: Install Appium Server and Appium Client

Step 8: Install IntelliJ Idea

Check the installation of the components using the command in the terminal:

$ appium-doctor

If everything is ok, you will see the following screen:

Appium installation
Verify Appium installation

Setting up Appium configuration

Launch the Appium GUI application ☝️️. Click Android icon and enter these details:

  • App Path — browse to the .apk location under the app folder
  • Platform Name — select Android
  • Automation Name — select Appium
  • Platform Version — select 5.1 Lollipop (API Level 22) from the drop-down

Once the preceding settings are done, click on the General Settings icon and choose the following settings:

  • Select Pre-launch Application
  • Select Strict Capabilities
  • Select Override Existing Sessions
  • Select Kill Processes Using Server Port Before Launch
  • Select New Command Timeout and enter the value 7200.
Appium settings
Appium settings

Also, you need to install your application on the emulator. You can use the emulator from Android Studio. When it is done — launch the Appium server.

Appium Server
Launched Appium Server

When you start the Appium app, you will see icons at the top. I highlighted the Appium Inspector in red.

Appium
Appium

When you click on the highlighted icon (Appium Inspector), it will open a new window with the application UI state capture.

Appium Inspector
Appium Inspector

Click on any element on the right panel to find the details about it. After clicking Details you will see a group of attributes listed for the selected element:

Details about element Appium
Details about element

You might notice the attribute “resource-id” and the value of id attribute. It can be used as an identifier for the element in your tests.

Example of using automation on mobile devices

To use automation on mobile devices, we will create a simple test for login with correct credentials. The test is written using Page Object Pattern.

Step 1: Create a Gradle-project and add required dependencies for JUnit, Appium, Cucumber, and log4J to your “build.gradle” file. The current “build.gradle” and the source code of the project are available here.

Step 2: Add Cucumber plugin and create “.feature” file.

CODE:https://gist.github.com/alina-diachuk/08b2c28ad2daa1958f1430be18fc0a94.js

Step 3: Create steps definition. Press Alt+Enter to show the Create Step Definition intention action. Select the target step definition file from the pop-up list.

Step definition Appium
Step definition

Step 4: Every testing scenario should be executed on some specific testing environment. The desired capabilities for the mobile emulator for Android and iOS:

CODE:https://gist.github.com/alina-diachuk/5b615feb000be53c1a3230f258032991.js

Step 5: Now we need to add the page with elements and methods using Page Object Pattern:

CODE:https://gist.github.com/alina-diachuk/fb3d10dd841cdee545f3827457530d66.js

Step 6: Cucumber has a very interesting feature called hooks. They help us execute a block of code before or/and after each scenario. Add them:

CODE:https://gist.github.com/alina-diachuk/40831398c1df29a8242519b4267fb522.js

Example of a successful test for Login with valid credentials:

CODE:https://gist.github.com/alina-diachuk/82750181c984bb4ece0306bd5385b4c1.js

Step 9: Since we want to use the JUnit framework to run Cucumber, we need to create the following class:

CODE:https://gist.github.com/alina-diachuk/2a79f9a469fa763ee1046ba5736953ae

You are done 💪

With this, we can run the tests in the same way as we run typical JUnit tests. There is a myriad of different ways you can set up, build and run your Appium tests as well.

Conclusion 💡

In the article, I described how to create tests for a native app. We also learned how to set up Appium. In most cases, Appium is the best choice out of all the available options because it is a ”cross-platform” automation tool and you can write software automation tests against iOS and Android platforms using the same API. By adding a Cucumber framework you integrate a BDD approach into your project. Since BDD is a part of test-driven development (TDD) you also get a shared view and process for all collaborators as a bonus 😃.

See the full project with the source code on GitHub.

Let us know if you have any questions or would like to share your experience with Appium test!

Free Product Roadmap Template

By opting in you agree with your information being stored by us in relation to dealing with your inquiry and to get an email with News, Blog Posts and Offers from Uptech. Please have a look at our Privacy Policy.
You can unsubscribe anytime.
Thank you!
Open Google Sheets.
Download Excel Spreadsheet.
By the way, we prepared a case study on how we saved $ 50K with design sprint
Oops! Something went wrong while submitting the form.

Free Checklist to Build An On-Demand Delivery App

Download our checklist to make sure your project goes as well as the case study above.
Thank you!
Download your check list.
By the way, we prepared a case study on how we saved $ 50K with design sprint
Oops! Something went wrong while submitting the form.

have a project
for US?

Let’s build your next product! Share your idea or request a free consultation from us.

contact us
You may also read