Start Automating your mobile tests with Cucumber and Appium
This tutorial helps Test Engineers start automating their Mobile tests using the Cucumber framework and Appium libraries.
Before we cover the details of using the Cucumber and Appium frameworks here is a short introduction.
Cucumber is one of the more widely used BDD (Behavior Driven Development testing frameworks. Behavior Driven Development gives us an opportunity to create test scripts from both the developer and the customer perspective.
Cucumber based tests are designed as,
- Features - Test Scenarios described in plain English.
- Steps - Test code corresponding to the features.
Cucumber Features and Steps adhere to the Given, When and Then scheme of Testing, where
- Given - Describes the Inputs and initial state of the scenario for testing.
- When - Describes the action or operation performed
- Then - Outcome of the action and Result assertion.
Note: Cucumber also includes a Before and After directive which enables testers to move to the Initial state of the test scenario and the state before the test scenario respectively.
Since the Cucumber framework is driven by Features which are described in plain English, it can be understood and implemented quickly by all the stakeholders involved.
Cucumber Steps contains the core programming logic.
Appium is an Open Source, Cross-platform utility for testing Native, Web, and Hybrid applications on iOS, and Android Mobile Operating System platforms.
Based on Client-Server Architecture, Appium Clients send automation commands to the Appium Server which translates it to platform-specific commands and executes on the devices.
This example is based on the following technologies and platforms.
- Windows Platform for development
- Android as a device OS
- Visual Studio as development IDE
NodeJS and Appium Desktop
- Download Node
- Double click the downloaded file and follow the steps in the wizard to finish the installation of Node.
- Download the Appium Desktop
- Launch the Installer of the platform of your choice and follow the setup wizard.
- Run the Appium Desktop installed in the machine, this also launches the Appium Server.
Visual Studio Code
Download and Install by referring to the official Visual Studio Code page.
Android Studio and ADB
You will also have to install Android Studio/Java because you will have to use the ADB utility for android device recognition.
Download the Android Studio Software and refer to the official page of Android Studio for installation.
Connecting the Mobile device to the PC using USB cable and enabling the developer mode/USB debugging in the android device.
Download Sample Android Application
Download sample Android application called Eribank using the link https://experitest.s3.amazonaws.com/eribank.apk
With all of the steps above completed, we are ready for the Cucumber and Appium example.
Step 1. Add Workspace Folder to in Visual Studio
Step 2: Go to the Terminal and Create Package.json
Note: Package.json contains the metadata of a NodeJS/JS project.
Specify all of the necessary information for the project as shown below.
Note: We use the WebDriverJS framework which uses Appium.
Step 3: Resolve Dependencies
This downloads the dependencies and creates a node_modules directory (where the dependencies are downloaded) in the workspace.
Step 4: Create Features and Steps directory
Step 5: Create Features file for Cucumber framework
As already described in the Cucumber section we define here in plain text:
Given , When and Then.
Start the Appium Desktop and click the Start Server button, this will start the server's specified host and port.
Note: Before executing the code make sure the device is recognized by your PC. We mentioned this step in the Prerequisites and Installation section under Device Recognition.
Now that we have shown you how Cucumber and Appium work together we suggest you try it for yourself. The full code for the example project can be downloaded from the git repo Cucumber and Appium Example.