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.
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:
- 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
- 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.feature