Key concepts for app test automation

Thiago Werner
ArcTouch
Published in
6 min readJun 22, 2022

The QA Engineers at ArcTouch are big fans of automated testing. We’re often asked by clients for more information about it, so here’s a guide to the key concepts of app automated testing to help you get started.

WebDriver

WebDriver is a remote control interface that enables introspection and control of user agents. It provides a platform- and language-neutral wire protocol as a way for out-of-process programs to remotely instruct the behavior of web browsers. — https://www.w3.org/TR/webdriver/

The WebDriver is middleware that connects our code with the application. Basically, the WebDriver is an API that can be used by a program to send instructions remotely.

As you can see in the image below, the WebDriver's role is intermediate the code relation with the application platform.

Diagram block that starts with code before the cloud that represents the WebDriver that connects to the application (devices).
WebDriver role in the Test Automation diagram

Selenium

Selenium WebDriver is the name of a WebDriver that uses the W3C API for Web applications.

Basically, Selenium provides some methods so you can consume the W3C API programmatically.

There are some implementations of Selenium WebDriver in many languages (Java, Python, Kotlin, C#, Ruby and JavaScript).

As you can see in the image below, Selenium WebDriver uses a client that interprets your code and send instructions using W3C JSON API to connect to specific web-browser drivers that connects to real web-browser drivers to automate our Web application.

Block diagram: begins with Selenium client that uses W3C JSON API to connect our code to the browsers' drivers that connects to real browser drivers.
Selenium WebDriver role in the Test Automation diagram

Appium

Appium is an open-source “automation library” that uses the W3C API for Mobile applications.

Basically, Appium is the Selenium variation for Mobile platform.

There are some implementations of Appium in many languages (Java, Python, Kotlin, C#, Ruby and JavaScript).

As you can see in the image below, Appium is composed by a client and server. The client will interpret your code and use W3C JSON API to send instructions to the Appium Server. Appium Server will use one of the many drivers to access the real mobile devices.

Block diagram: begins with Appium client that uses W3C JSON API to connect our code to the Appium Server (coded using Node.js) that uses specific drivers that connects to real mobile devices.
Appium automation library role in the Test Automation diagram.

Locators

But, how to say to our code that we want a specific element at the screen?

The WebDriver uses locators to find and match the elements in your application. There are so many kind of elements such as: ID, CSS Selector, XPATH, Accessibility ID, etc.

XPATHs are not recommended. XPATH creates a new index of elements every time it’s called. It increases the execution time.

It’s really important to have a proper list of elements pre-configured in your application. So, you will need a easiest way to access the elements.

Cucumber

Cucumber is a tool that supports Behaviour-Driven Development (BDD) — a software development process that aims to enhance software quality and reduce maintenance costs.

Cucumber executes executable specifications written in plain language (Gherkin) and produces reports indicating whether the software behaves according to the specification or not. — https://github.com/cucumber/cucumber

Step Definitions is the way to translate Gherkin scenarios to the programming code. Cucumber® provides support to: Java, JavaScript, Kotlin and Ruby.

There are some auxiliary tools to provide the support for others (i.e. Behave (Python)).

Block Diagram: begins with Gherkin being translated by Steps Definitions that uses programming language to manipulate the application.
Gherkin being translated by Cucumber

Steps Definitions

Let's see a common project structure containing Steps Definitions folder to organize the code.

A common project structure using Steps folder

A couple advises:

  • Avoid using one giant file containing all steps;
  • It doesn’t matter the name of your file. There is no keyword treatment;
  • Organize the steps based on feature-related steps and general steps;
  • Choose meaningful names for your project.

The steps definitions look intuitive on all programming languages. As you can see below in the code written in Java.

Scenario: Breaker guesses a word

Given the Maker has chosen a word

When the Breaker makes a guess

Then the Maker is asked to score

translation:

@Given(“the {people} has chosen a word”)

public void given_chosen_word(String people) {

}

Without Cucumber

Sometimes, it is not necessary use Cucumber in our Test Automation Framework. In this case, there are few advantages:

  • Less code dependencies;
  • Less complexity.

Currently, there are some Test Automation Frameworks that provide pretty straight-forward interactions and tests.

It doesn’t mean that a simple code using Appium or Selenium won’t work.

Examples: Cypress, Robot Framework, others.

See below an example of a code written in Robot Framework:

*** Settings ***

Documentation A test suite with a single test for valid login.

… This test has a workflow that is created using keywords in

… the imported resource file.

Resource resource.robot

*** Test Cases ***

Valid Login

Open Browser To Login Page

Input Username demo

Input Password mode

Submit Credentials

Welcome Page Should Be Open

[Teardown] Close Browser

F.I.R.S.T. principle

Meaningful and good practice to all of us, F.I.R.S.T. is:

Page Objects Model

The basic idea of Page Objects is sound — hide the logic about how you find the elements of a page (for example, ID fields or XPATH or CSS Selectors) from how you interact with these elements (what value your enter into a field for example). — https://johnfergusonsmart.com/page-objects-that-suck-less-tips-for-writing-more-maintainable-page-objects/

Basically, Page Objects Model (POM) is a good practice to organize our code. A poor use of POM will result “in test automation code that is fragile and hard to maintain”. — https://johnfergusonsmart.com/page-objects-that-suck-less-tips-for-writing-more-maintainable-page-objects/

Let's see an example of a code with/out POM:

Without POM:

public void login() {

Webdriver driver = new FirefoxDriver();

driver.get(“https://test-website.com“);

driver.findElement(by.ID(“USERNAME_FIELD”)).sendKeys(“potato”);

driver.findElement(by.ID(“PASSWORD_FIELD”)).sendKeys(“watermelon”);
driver.findElement(by.ID(“LOGIN_BUTTON”)).click();

}

With POM:

public void login(String username, String password) {

driver.get(“https://test-website.com“); //previously created

loginPage = new LoginPage(driver);

loginPage.login(username, password);

}

It is evident that a code that uses POM properly will be simplest and plain for everyone who is reading.

Let's see a common project structure using POM. As well as the Step Definitions, it’s a good practice to gather the common methods in one file, in this case, BasePage.*.

Locators, Specific Interactions and Page Navigation should be written inside the pages.

Project structure using Cucumber and POM

Device Farm

Who has all the important platforms, OS versions, browsers, devices available every time?

Device Farm is the name of the service that provides a set of structure (cloud or not) to run your tests. For example: SauceLabs, BrowserStack, others.

A list of features available:

  • Parallel testing: how many tests in parallel can be run;
  • Live testing: manual tests;
  • Automate testing: automated tests;
  • Mobile and Desktop testing: multi-platform testing.

Mock Server

Account Creation, Content Checking, and other tasks demand a specific set of values to run. How many type of user/content you ever tested?

Mock Server is the HTTP consumable environment that supports our tests to do not change testing data in the application DB.

With a Mock solution, tests will always have the same unchangeable resources to run.

About Us

Are you an experienced QA professional looking for your next challenge? Take a look at our ArcTouch careers page and join us.

--

--

Thiago Werner
ArcTouch
Writer for

Master QA Analyst at @ArcTouch; BDD and Agile enthusiast; Test Automation specialist.