Cucumber JVM is one of the fastest-growing tools that offer a cutting-edge platform to conceptualize and implement behaviour-driven development (BDD). The variety of features available within Cucumber bolsters and enhances experiences of implementing BDD for both business and development teams.
This cookbook has around 40 recipes. It takes you on a learning journey, where you start from basic concepts such as Feature files, Step Definitions, and then moves on to advanced concepts such as Hooks, Tags, configuration, and integration with Jenkins and test automation frameworks. Each chapter has multiple recipes, with the first recipe introducing the main concept of that chapter; the complexity level of each recipe increases as you progress through the chapter. The book has sufficient topics for product owners, business analysts, testers, developers, and everyone who wants to implement BDD.
This book is written with an assumption that the reader already has some idea about Cucumber. If you are new to Cucumber, it is advisable to go over my blog first:
Blog 1: How to integrate Eclipse with Cucumber plugin https://shankargarg.wordpress.com/2015/04/26/how-to-integrate-eclipse-with-cucumber-plugin/
Blog 2: Create a Cucumber Project by Integrating Maven-Cucumber-Selenium-Eclipse https://shankargarg.wordpress.com/2015/04/29/create-a-cucumber-project-by-integrating-maven-cucumber-selenium-eclipse/
These two blogs will help you integrate Cucumber and Eclipse and help you create and run a basic project.
All of the code explained in this book is committed on GitHub. Here is the URL of the code repository: https://github.com/ShankarGarg/CucumberBook.git.
This repository has five projects:
Cucumber-book-blog: This project is used in the blogs mentioned earlier to start with Cucumber, Maven, and Eclipse
CucumberCookbook: This project is used in chapters 1 to 5
CucumberWebAutomation, CucumberMobileAutomation, and CucumberRESTAutomation: This project is used in Chapter 6, Building Cucumber Frameworks
Chapter 1, Writing Feature Files, covers unique aspect of Cucumber – the Gherkin language and usage of Gherkin language to write meaningful and smart Feature files. This chapter will also cover different keywords, such as files Scenario, Steps, Scenario Outlines, and Data Tables.
Chapter 2, Creating Step Definitions, covers basic concepts and usage of Glue Code/Step Definitions, and regular expressions to come up with efficient and optimized Step Definitions. This chapter will also elaborate the concept of String and Data Table transformations.
Chapter 3, Enabling Fixtures, covers the advanced concepts of implementing fixtures by Tags and Hooks. Here not only the individual concepts of Tags and Hooks are explained, but practical example of using Tags and Hooks combination is also explained.
Chapter 4, Configuring Cucumber, deals with integration of Cucumber with JUnit and the concept of Cucumber Options. Here you will learn various practical examples of using Cucumber Options and different types of reports that can be generated with Cucumber.
Chapter 5, Running Cucumber, covers topics of running Cucumber from the Terminal and from Jenkins. You will learn Cucumber integration with Jenkins and GitHub to implement Continuous Integration and Continuous Deployment (CICD) pipelines. Then you will learn parallel execution to take full advantage of Cucumber.
Chapter 6, Building Cucumber Frameworks, covers detailed Steps to create robust test automation frameworks to automate web applications, mobile applications, and REST services.
Before starting with Cucumber, let's make sure that we have all the necessary software installed.
The pre-requisites for Cucumber are as follows:
Java (Version 7 or later) as the programming language
Eclipse as the IDE
Maven as the build tool
Firefox as the Browser
The Eclipse-Maven plugin
The Eclipse-Cucumber plugin
Jenkins
GIT
Appium
Android SDK
This book is intended for business and development personnel who want to use Cucumber for behavior-driven development and test automation. Readers with some familiarity with Cucumber will find this book of most benefit.
Since the main objective of this book is to create test automation frameworks, previous experience in automation will be helpful.
In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).
To give clear instructions on how to complete a recipe, we use these sections as follows:
This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.
This section usually consists of a detailed explanation of what happened in the previous section.
This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include
directive."
A block of code is set as follows:
@When("^user enters \"(.*?)\" in username field$") public void user_enters_in_username_field(String userName) { //print the value of data passed from Feature file System.out.println(userName); }
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
Scenario: checking pre-condition, action and results Given user is on Application landing page When user clicks Sign in button Then user is on login screen
Any command-line input or output is written as follows:
mvn test -Dcucumber.options="--tags @sanity"
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Click on the timestamp on the build. And then click on Console Output."
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>
, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>
, and we will do our best to address the problem.