Mastering Behavior-Driven Development Using Cucumber
eBook - ePub

Mastering Behavior-Driven Development Using Cucumber

Practice and Implement Page Object Design Pattern, Test Suites in Cucumber, POM TestNG Integration, Cucumber Reports, and work with Selenium Grid

  1. English
  2. ePUB (mobile friendly)
  3. Available on iOS & Android
eBook - ePub

Mastering Behavior-Driven Development Using Cucumber

Practice and Implement Page Object Design Pattern, Test Suites in Cucumber, POM TestNG Integration, Cucumber Reports, and work with Selenium Grid

Book details
Book preview
Table of contents
Citations

About This Book

Master the skills required to effectively use Cucumber BDD which simplifies Agile development and fast-paced time-to-market

Key Features
? A step-by-step explanation of each component of the Cucumber framework.
? Expert coverage on speeding up the implementation of the Cucumber framework.
? Includes Parallel Execution, Cloud Testing, Explore Gherkin, and many more.

Description
In this book, readers will learn everything they need to know about Behavior-Driven Development (BDD) and a framework used for automation testing for BDD.The book is divided into three sections. The first section covers the building blocks of Cucumber such as Feature files, Step Definition classes, and Runner classes, among other things. These will serve as the building blocks for becoming more familiar with Cucumber.The second section covers the Page Object design pattern and Page Factories, both of which are useful in developing robust frameworks.The final section demonstrates Cucumber's integration with TestNG and Maven. We will be putting each Maven build in Jenkins and configuring Jenkins to trigger automatically when a development build is completed.After reading this book, the test engineer will understand the concept of incorporating Cucumber as a BDD framework into his testing.

What you will learn
? Understand the fundamentals of Test-Driven Development and Behavior-Driven Development.
? Investigate Cucumber's building blocks such as Feature Files and Step Definition Files.
? Learn the Base Class and inheritance concept within the Page Object Model Framework.
? Create a TestNG XML that calls the test runner class.

Who this book is for
This book is aimed at individuals who have a firm grasp of the fundamentals of Java and are interested in improving their knowledge of the BDD framework.

Table of Contents
Section 1: Understanding the Cucumber framework
Chapter 1: Introduction to Behavior-Driven Development
Chapter 2: Understanding Feature Files
Chapter 3: Understanding Step Definition files
Chapter 4: Learning about the TestRunner Section 2: Learning the Page Object Design Pattern
Chapter 5: Understanding the Page Object Model and Creating Page Objects
Chapter 6: Understanding Page Factories and Creating Page Factories Section 3: Integration with TestNG, Maven, and Jenkins
Chapter 7: Configuring the TestNG Framework
Chapter 8: Configuring Maven and Learning about POM.xml
Chapter 9: POM.xml Execution from Eclipse and Command Line
Chapter 10: Configuring POM.xml to Trigger TestNG xml
Chapter 11: Configuring the Runner Class for Cucumber Reporter Plugin
Chapter 12: Reporting Using Extent Reports
Chapter 13: Parallel Execution Using Selenium Grid
Chapter 14: Integration with Jenkins

About the Authors
Pinakin Chaubal is a BE (Computer Science) with 19+ years of experience in the IT area. He has done PMP, ISTQB, HP0-M47 (QTP 11.0 Functional testing expert), and INS-21(General Insurance). He is working as an Automation Architect at Intellect Design Arena Ltd. (Previously, Polaris Consulting). Previously, he worked with companies like Patni, Accenture, ACS International (USA), L&T Infotech (USA & India), Polaris Financial Technology, and SQS. He carries 6 years of onsite experience in the US and 8 months in Hong Kong and China working closely with the client and getting involved in senior management and stakeholder meetings. The clients that he has worked for are YES Bank, HSBC, Travelers Insurance, Harleysville Insurance, Albertsons retail chain, Bellsouth Telecommunications GE-Fleet Services, and GE-Supply. LinkedIn Profile: https://www.linkedin.com/in/pinakin-chaubal-300b372/
Blog Link: //www.youtube.com/channel/UCkkh8bX1KS5iaORXX23P8ZA

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Mastering Behavior-Driven Development Using Cucumber by Pinakin A Chaubal in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in Java. We have over one million books available in our catalogue for you to explore.

Information

Year
2021
ISBN
9789391030476

CHAPTER 1

Introduction to Behavior Driven Development

Welcome to the exciting world of Behavior Driven Development (BDD). This book will be divided into three parts. The first part will make the user understand what Cucumber is all about. The second part will explore the Page Object Model and Page Factories. The third part will cover integration of Cucumber with the TestNG framework. It is going to be a very exciting journey, so let’s get started and understand what BDD is all about.
BDD helps to bridge the gap between business people and technical people by implementing a language called ‘Gherkin’. It consists of statements in English predominantly, although other languages are available for this purpose too. A group of Gherkin statements together lists a functional flow. These statements are taken by the Automation developer and converted into code using frameworks like Cucumber, JBehave or Specflow. BDD is quite frequently used in Agile projects for getting quick feedback on code quality after developers check in their code in source code management systems like GitHub or SVN. The BDD tests can be configured to execute immediately after the code is checked in.
This chapter will predominantly focus on
  • Test Driven Development
  • Behavior Driven Development
  • Understanding Gherkin
  • Introduction to Cucumber
  • Understanding the DRY principle
  • Components of Cucumber
  • Setup of the project in Eclipse
  • Setup of TestNG in Eclipse
  • Understanding the project structure

Objective

After reading this chapter, the reader will be conversant with the concepts of TDD, BDD, Gherkin and able to create a basic file called ‘Feature File’ in the Gherkin Language. He will also learn how the Gherkin file relates to the Step Definition file which is one of the components of Cucumber. He will get knowledge of the project structure and understand how to set up a project in Eclipse along with TestNG Plugin integration. This chapter will serve as the foundation for one who wishes to work as a Test Automation Engineer and wants to make a career in BDD framework.

1.1 What is TDD?

TDD stands for Test Driven Development. Test Driven Development is a software development process where test cases are written first taking into consideration the requirements in a traditional project or the user stories in a scrum or agile project. Once the tests are created, minimal code to make the tests pass is created. As and when new tests are created, the code is updated to make the new tests pass and at the same time ensuring that the existing tests pass as well.
TDD (We will refer to this acronym for Test Driven Development going forward) was developed or rediscovered by Kent Beck in 2003 to facilitate simple designs. TDD is related to test first programming concepts of Extreme Programming.

1.1.1 Steps involved in a TDD

The steps mentioned below should be followed in a typical Test Driven Development approach.
  1. Write the test: This activity can be done by the tester or developer where a test is created from the user story, requirement or use case. This is contrasted to the traditional approach of writing unit tests after the code is written. TDD enables the developer to focus on the requirements (We will refer to user stories, traditional requirements or use cases as requirements going forward) before getting started with the code. This differentiated TDD from a traditional development approach.
  2. Run the test to check that it fails: Prepare the development system such that bare minimum code is there to make your application run like creating the main method or a screen with the required stubs for the database or web service for example. Since writing the test was the very first activity done, it should definitely fail since we don't have any code in place to support the test. If the test fails, then we are sure that the test has been written correctly.
  3. Write the development code: Now it's time to make our test pass by writing only the required code to make the test pass. It is strongly recommended not to write more code in this step. Writing more code results in what is called Gold Plating where you are just giving additional features that are not required at the present moment.
  4. Check to see that the test passes: Run our first test again and this time it should pass. This helps to ensure that all the correct development code is in place and we can move on to the next test.
  5. Refactor the code: In the iterative TDD process, we need to make sure that we have not introduced any duplication, all the design principles are met and the methods are where they are supposed to be, that is, logically grouped together in a class.
  6. Repeat with new tests: Next we write new tests for new requirements and repeat steps 1-5 to ensure that the correct code is written and only the required code is written. TDD will help you build a near defect free application using the minimum amount of code. There are many tools in the market for TDD one of them being JUnit. Since this book is focussed on BDD, we won’t go into details about testing with JUnit.

1.2 What is BDD?

BDD is an extension of TDD that makes use of a simple, Domain Specific Language (DSL). The DSL is in plain English and convert natural language statements into executable tests. The DSL that we are going to study in this book is known by the name Gherkin. The term Gherkin however is specific to Cucumber, JBehave, Behave and Behat software tools.
BDD focuses on:
  • Where to start
  • What to test and what to exclude
  • How much to test
  • What to name the tests
  • Understanding why a test fails
Let's get our hands dirty with the first DSL in Gherkin.
Feature: Cash withdrawal from ATM
Scenario: Successful cash withdrawal
Given the account balance is $100
And the card is valid
And the ATM contains sufficient money
When the account holder requests $20
Then the cashslot should dispense $20
And the account balance should be $80
And the card should be returned
These very simple English statements can be split into three distinct sections.
  1. Context: This defines the starting state
    Figure 1.1: Example of Given keyword
  2. Event: This defines the user's action or actions
    Figure 1.2: Example of When keyword
  3. Outcomes: This defines the expected results
    Figure 1.3: Example of ‘Then’ and ‘And’ keywords
The words highlighted in Bold like ‘’‘’’’“Given”, “When”, “Then” and ‘’“And‘’ are known as Cucumber steps.
Let’s have a look at each of these keywords
  1. Given: The purpose of Given is to put the system in a known state before the user starts interacting with the system.
  2. When: The purpose of When steps is to describe the key action the user performs.
  3. Then: The purpose of Then steps is to observe outcomes. The observations should be related in some way to the business value in your feature description. The observations should also be on some kind of output – that is values that come out of the system.
  4. And: Used to connect multiple Given, When and Then steps.
The above Domain Specific Language has the Feature and Scenario steps also. We will cover each of these steps in detail when we start designing the Page Object Model Framework. We are now ready to get introduced to Cucumber.

1.3 What is Cucumber?

Cucumber is a tool based on the BDD Framework. Cucumber makes use of Gherkin keywords. Gherkin is a DSL which is used in Cucumber to create test cases. Rather than...

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Dedication Page
  5. About the Author
  6. About the Reviewers
  7. Acknowledgement
  8. Preface
  9. Errata
  10. Table of Contents
  11. 1. Introduction to Behavior Driven Development
  12. 2. Understanding Feature Files
  13. 3. Step Definitions
  14. 4. Learning About the Test Runner
  15. 5. The Page Object Model Without Page Factory
  16. 6. Learning About the Page Object Model Using Page Factory
  17. 7. Configuring the TestNG Framework
  18. 8. Configuring Maven and Learning About POM.xml
  19. 9. Test Execution with Maven and Log4J
  20. 10. Configuring POM.XML to Trigger TestNG.XML
  21. 11. Configuring the Runner Class for the Cucumber Reporter Plugin
  22. 12. Reporting Using Extent Reports
  23. 13. Parallel Execution Using Selenium Grid
  24. 14. Integration with Jenkins
  25. Index