Setup Cucumber with Appium in Ruby

Aya Akl
Aya Akl
Aug 25, 2017 · 3 min read

This is a small tutorial of what I have done to setup Cucumber with Appium in Ruby programming language.

But first let’s have a small intro on each one of them:

Cucumber runs automated acceptance tests written in a behavior-driven development (BDD) style.

Appium is an open source test automation framework for use with native, hybrid, and mobile web apps. It drives iOS, Android, and Windows apps using the WebDriver protocol.

Ruby is A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.



Cucumber works as follows:

  • Cucumber divides our work to features and step definitions.
  • Acceptance Test Cases can be written in Features files using Gherkin, the the language that Cucumber uses to define test cases.
  • These Features consists of subdivided into Scenarios, which are sequences of Steps of the acceptance test cases.
  • Step definitions file where we can define how these features and acceptance test cases will work (like methods’ implementation).

Setup Cucumber:

1- Installation

2- Setup Environment

3- Prepare Cucumber features file

Let’s say we have a feature called “addNote.feature”:

4- Prepare Cucumber Step Definitions file

There should be a step definition to the above feature file named “addNote.rb“

>> .rb file is the files that holds implementation by Ruby programming language.

In the code above of the step definition:

  • login object is created from the Login Screen.
  • Login Screen methods are then used by the login object by calling the loginWith method that takes username and user’s password.
  • User is logged in once username and password are correct.
  • appLoginDetails is an array user data that are stored in .yml file that stores data of the test. It exists under the config folder of Cucumber directory.

Given that this is how you get your elements inside Login Screen using loginWith method:


Appium Prerequisities:

  • We should create our automation directory so we put all the files in it that Appium and Cucumber need.
  • This tutorial is for iOS App, the same steps happens for Android Apps as well but with some differences in directories and the apps extensions.
  • We need to get the app we will work on. We need to run our iOS app so we could get the “.app” file.

So our prerequisites are as follows:

1- Open Xcode to run the App.

2- After running the App, get the “.app” file under your iOS app directory.

EX: “/Users/../../<iOSAppProjectName>/<iOSAppProjectName.iOS>/bin/iPhoneSimulator/Debug/<iOSAppProjectName.app>”

3- Then, put it in the Automation directory so that you can use it to run your tests on.

EX:

“../<appFolderName>/<simulator>/appName.app”

4- Then, prepare “appium.txt” file which is the file that you need to define your desired capabilities that used by Appium.

We can make different appium.txt files to run our tests on different devices or iOS versions

  • Tests to run on iPhone Simulator:
  • Tests to run on iPad Simulator:

Setup Appium

1- Installation

2- Setup Environment

Here we take advantage of the environment file of Cucumber that exists under Cucumber Support folder.

So now, prepare Appium environment that will handle when and how we can run our automated tests by creating the “env.rb” file

  • A configuration of which device we want to run on: “DEVICE_NAME” was added.
  • A configuration of which device we check if the device is on portrait or landscape orientation: “DEVICE_ORIENTATION” in case we needed this was added.

Integrating Appium with Cucumber

We should run the tests/step definitions we added using Appium.

This can be done by using the “cucumber” keyword in the terminal and calling our test with required settings, iPad or iPhone or whatever.

  • To run on iPad: cucumber DEVICE_NAME=’ipad simulator’
  • To run on iPhone: cucumber DEVICE_NAME=’iphone simulator’

As mentioned above when creating our automation environment, “DEVICE_NAME” is the configuration we set in the environment file that will call appium.txt of the ‘ipad simulator’ or ‘iphone simulator’.

This will then tell Appium the desired capabilities we want to run on and the same go for the device orientation, just call the environment variable in the cucumber terminal line.


The code written in the step definition file is how we will log to the app by username1 and password. I should post in next posts how we can use the POM- Page Object Model design pattern used in writing the automated scripts.

I hope this post would help testers who want to know how to get Cucumber and Appium to work together.

HAPPY TESTING!

)

Aya Akl

Written by

Aya Akl

#Quality is my thing - Passionate human being who wants to change the world!!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade