5 Important Tips to be Successful in Cucumber


I have been developing automation solutions for a few years. Two years ago, Cucumber came into our daily talks even though it has been around for a while. Many people talk about how Cucumber can change automation. I have asked many questions like “In case you develop your Gherkin test cases without structured sentences, how do you keep your code base updated? Don’t you need to write Java code accordingly?” or “You talk about minimizing your maintenance effort but you maintain Java part and Gherkin part together? What kind of minimizing is that?”.

I have searched for cucumber library from various sources but never liked it because I have never seen an implementation example that suits my need which is “I WON’T change my code base in case a new web component is added to my AUT

Then one of my clients decided to implement Cucumber. There you have a challenge, you have to deal with a library that you don’t like. But that’s also an opportunity as I am now able to implement a solution aligned with my motto.

We succeeded in Cucumber in two weeks. Right now, we don’t change our Java code base, we don’t add any step definition. We just write Gherkin test cases. I am going to explain how we succeeded.

Step 1: Create Identifier For All Elements

As a best practice, we want dev team to add identifiers for web element that will be interacted in automation. Best practices say that ID’s should be the first choice, then class’ should be used. Dev team suggested us to create unique data attributes to elements that we will interact because ID and class are linked to CSS and they don’t want to mess with them.

So we have elements like. I am going to use those example elements below steps.

<a href=“/login.php” class=“login” data-automation=“login-button>Giriş Yap</a>

<select class=“profile-type-class-ui” data-automation=“profile-type></select>

<option value=”0″>Profile Type</option>

<option value=”1″>Admin</option>

<option value=”2″>Manager</option>

In case no data attribute, don’t implement test case, wait for dev team to create those attribute.

Step 2: Smart Waits

Many Selenium based tests have the dependency on Fluent, Implicit or Explicit waits. As a matter of facts, while developing Gherkin test cases, you only write test steps. Test automation engineers define elements to have waited. Why would you for an object to move on to another step? Because you don’t know what you are waiting for!!! I don’t rely on that approach.

You should properly wait for DOM Ready, Ajax, JQuery or Angular calls.

Thus, your automation code will wait till any of those requests finish its execution. So learn what DOM Ready is, learn how JQuery can be detected via javascript.

Step 3: Create a Proper Test Case Template Aligned with Your Web Framework

You web app have different objects like a combobox, list boxes, text box, etc. They all behave differently. Implement a test case template aligned with your automation code structure

So every user uses the same sentences while interacting same element type.

Example scenario:

Scenario: Changing Profile Type

Given Main Page“ is loaded

When User fill form with below

 | E-mail    | testuser@aut.com |

 | Password  | 123456           |

And Login button“ is clicked

Then Profile Page“ is loaded

When “Admin” is selected on “Profile Type” combobox

As you see, I have Profile Type combobox and Login button on my page, I am using their visible name in my test case. So how do my automation code running below Gherkin uses those variable to interact with AUT? The answer is in below step.

Step 4: Map Your Gherkin Variable with Your Data Attribute

In that step, you need to create a Mapping structure which links Gerking variable and data attributes defined in AUT. I store my variable and data-attributes in a property file. That code reads from the property file. For this step, you need to stick steps 1 and 3 strictly. You shouldn’t mess with them.

My property file:

Login Button=login-button

Profile Page=profile-image

Profile Type=profile-type

Step 5: Create Your Code Base with Minimum Viable Functions

Here are few example methods that I use.

Run Your Cucumber Tests like a Charm

By following those steps, we don’t write any Java code, we only update the property file for new elements to interact.

javafx

Database Operations in JavaFX

By Onur Baskirt / Apr 1, 2016 / 56 Comments
Before started this section, please check the first article and learn How to Start JAVAFX! http://www.swtestacademy.com/getting-started-with-javafx/ At first, part of JavaFX tutorial series, we created a sample JavaFX project, designed the draft version of the UI and set up an...
rest assured

REST API Testing with Rest Assured

By Onur Baskirt / Mar 8, 2016 / 32 Comments
Outline In this post, I will explain what is API and API testing, what is the difference between SOAP and REST services, and how to test REST APIs with Rest Assured Library. What is API? API stands for Application Programming...
extentreports

How to Write Effective CSS Locators

By Onur Baskirt / Oct 1, 2017 / 0 Comments
Hi all, in this tutorial, I will describe you how to write effective CSS locators to interrogate web elements for your automation projects. As a rule of thumb, your interrogation strategy should be in below order: First try to use...
extentreports

Selenium-11: Execute JavaScript with JavascriptExecutor

By Onur Baskirt / Jan 27, 2016 / 15 Comments
Outline Sometimes we cannot handle some conditions or problems with Webdriver, web controls don't react well against selenium commands. In this kind of situations, we use Javascript. It is useful for custom synchronizations, hide or show the web elements, change...
javafx

Getting Started with JavaFX

By Onur Baskirt / Mar 25, 2016 / 0 Comments
When I started to work in my current position, one of my task is to do manual operations for campaign products  every week. After the second week, I thought that I have to automate this task using a GUI based...
extentreports

How to Write Smart XPath Locators

By Onur Baskirt / Sep 24, 2017 / 4 Comments
Hi all, in this tutorial, I will describe you how to write smart and non-brittle XPath locators. When we write our test scripts, we generally prefer to use id, name, class, etc. these kinds of locators. However, sometimes we could not...
extentreports

Selenium-1: Quick Start to Automation with Selenium WebDriver & JAVA & JUnit & Maven & IntelliJ

By Onur Baskirt / Sep 8, 2015 / 26 Comments
Outline Selenium Webdriver is the most popular open source web test automation framework across wide range of browsers and platforms. In this tutorial you will learn how to do web test automation with Selenium Webdriver and the related tools. Audience...
page object model

Page Object Model with C#

By Ege Aksoz / Jun 18, 2017 / 8 Comments
In the previous tutorial, we’ve taken the initial steps and entered the world of automated testing. We also wrote our first automated test. From this point on, since we are not just going to write one test, we need to...
extentreports

How to Select a Date From DatePicker Using Selenium

By Onur Baskirt / Aug 13, 2016 / 6 Comments
When you need to automate a airway, hotel, or similar websites you need to deal with Datepickers and some times it is a little bit cumbersome to select a specific date on the Datepicker or calendar.  In this post, I...
extentreports

Selenium Webdriver Performance testing with Jmeter and Selenium Grid

By Ozgur Kaya / Aug 9, 2016 / 2 Comments
In this post, we will complete Selenium Webdriver Performance testing scenario using Jmeter and Selenium Grid. 1- Install Java 7 or later If necessary https://java.com/tr/download/ 2- Download latest Jmeter version 3.0 or higher. http://jmeter.apache.org/download_jmeter.cgi 3- Download Jmeter PluginsManager JAR file and...
By | 2017-06-05T09:47:12+00:00 June 4th, 2017|Uncategorized|1 Comment

About the Author:

Canberk Akduygu
Canberk Akduygu is working as a Technical QA Architect on test automation and performance testing. Formerly, he worked at TEB as QA Project Lead, Ayrotek IBM Business Partner and Yapi Kredi Bank as Java Developer. You can also follow him on Linkedin.

One Comment

  1. Thy Nguyen June 6, 2017 at 5:38 am - Reply

    @Canberk Akduygu: Thanks for your tips. It’s very useful.

Leave A Comment