Guest Post: Automated iOS Acceptance Testing with Appium, Cucumber-JVM, Jenkins, and Sauce Labs

Unmesh Gundecha, tester extraordinaire and author of Selenium Testing Tools Cookbook wrote an awesome post about Appium earlier this year, and he kindly agreed to write us an extremely detailed and in-depth series of posts about iOS testing with Appium and Sauce. We'll be posting this 3-part series of posts every Wednesday, so make sure to check back every week to read more!

Agile development projects are adopting practices such as automated acceptance testing, BDD, continuous integration, and others. There is a lot written about these approaches for developing software, their benefits and limitations etc. However, one of the fundamental benefits these practices offers is enhanced communication between project stakeholders including users, product owner, and the development team. It requires all the project participants to come together, discuss, and elicit the behavior of the application in agreed upon format of features, user stories and acceptance criteria and shared definition of Done. Mobile Development Process

Cucumber-JVM

Cucumber-JVM is a pure Java implementation of original Cucumber BDD/ATDD framework. It supports the most popular programming languages on the JVM. It’s already been used by various teams along with Selenium WebDriver for testing Web applications. Cucumber support creating features files which are written in a ubiquitous language understood by the whole team. These feature file describe the expected behavior of the application and are used as tests to run against the application. Cucumber can be used for API, integration and functional testing of the application. In this example we will see functional testing of a sample native iOS App using Cucumber-JVM and Appium.

The Sample App

This example is based on a sample BMI Calculator application which is used by Health & Nutrition specialists to calculate the Body Mass Index of patients by submitting Height and Weight values to the App. Let’s work on the main feature of this App as described below Feature: Calculating Body Mass Index As a health specialist I want a BMI Calculator So that I can calculate patient's Body Mass Index

Setting up the test project

Let’s setup a new project using with IntelliJ IDEA using Maven & Cucumber-JVM with following steps:

  1. Create a new Project as Maven module, provide the appropriate values for GroupId and ArtifactId. In this example GroupId
    is set with org.bmicalc.test value and ArtifactId
    > as bmicalculator.test




  1. Once the Intellij IDEA creates the project with appropriate folder structure, locate and modify pom.xml file. Add the highlighted dependencies to pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.bmicalc.test</groupId>

<artifactId>bmicalculator.test</artifactId>

<version>1.0-SNAPSHOT</version>

<dependencies>

    <dependency>

        <groupId>junit</groupId>

        <artifactId>junit</artifactId>

        <version>4.11</version>

        <scope>test</scope>

    </dependency>

    <dependency>

        <groupId>org.seleniumhq.selenium</groupId>

        <artifactId>selenium-java</artifactId>

        <version>LATEST</version>

        <scope>test</scope>

    </dependency>

    <dependency>

        <groupId>info.cukes</groupId>

        <artifactId>cucumber-java</artifactId>

        <version>1.0.14</version>

        <scope>test</scope>

    </dependency>

    <dependency>

        <groupId>info.cukes</groupId>

        <artifactId>cucumber-junit</artifactId>

        <version>1.0.14</version>

        <scope>test</scope>

    </dependency>

    </dependencies>
lt;/project>

This will add the Cucumber-JVM and Selenium dependencies to the project.

Writing Feature file

In Cucumber-JVM the specifications or requirements are expressed in a plain text, Given/When/Then kind of syntax known as Gherkin language (https://github.com/cucumber/cucumber/wiki/Gherkin) which is understood by the whole team. So let’s create a feature file for the above feature in the project. Add a new package bmicalculator.test under src/test/resources as shown in below screenshot and add a new file with name bmi_calculator.featureiOS acceptance testing Add the following feature to bmi_calculator.feature file Feature: Calculating Body Mass Index As a health specialist I want a BMI Calculator So that I can calculate patient's Body Mass Index BmiCalculator @ios-sauce Scenario Outline: Calculate Body Mass Index Given I enter "<Height>" as height And I enter "<Weight>" as weight And I press the Calculate button Then I should see "<BMI>" as bmi and "<Category>" as category Examples: |Height |Weight |BMI  |Category   | |170    |50     |17.30|Underweight| |181    |80     |24.42|Normal     | |180    |90     |27.78|Overweight | |175    |100    |32.65|Obese      | Every feature file contains a single feature. A feature usually contains a list of scenarios.  Every scenario consists of a list of steps, which must start with one of the keywords Given, When, Then, But or And. Scenarios express the expected behavior of the system under given conditions. In addition to a scenario, a feature may contain a background, scenario outline and examples. Our example scenario contains Scenario background and examples for number of BMI calculations representing each category. This scenario outlines allow us to more concisely express these examples through the use of a template with placeholders. In this example Calculate Body Mass Index is run once for each row in the Examples section beneath it (not counting the first row which is a header). This is similar to data driven testing. Next week, we'll see how to run features with Maven, and enter step definitions.

Written by

Bill McGee

Topics

CI/CDAppium