The BDD- Behavior Driver Development is basically the Software development process that actually originated from TDD. It is an extension of TDD, which is having Tests written in plain English language and explained as the behaviour of the application. Each Test/Scenario is written such way that the user can relate and understand those testes with the application. This is one of the major benefits of BDD that even a business person or stack-holders of the project can also understand how automation is going through the steps and can understand the execution process.
BDD with Cucumber
Cucumber is a testing tool which supports Behavior Driven Development (BDD). The language it uses is Gherkin which is nothing but the plain meaningful English text. Cucumber supports many other languages like ruby, python, java any others for automation.
A feature file consists of the following elements:
- Feature − Name of the feature under test.
- Description − Describe feature under test.
- Scenario – Your Test Scenario (Objective).
- Given − Prerequisite before the test steps get executed.
- When − Specific condition which should match in order to execute the next step.
- Then – It is kind of validation after “When” Statement getting executed
Step Definitions
We have got our feature file ready with the test scenarios defined. However, this is not the complete job done. Cucumber doesn’t really know which piece of code is to be executed for any specific scenario outlined in a feature file.
This calls the need of an intermediate – Step Definition file. Steps definition file stores the mapping between each step of the scenario defined in the feature file with a code of the function to be executed.
So, now when Cucumber executes a step of the scenario mentioned in the feature file, it scans the step definition file and figures out which function is to be called.
Behavior-Driven Development (BDD) is an approach to develop software solutions guided by examples, instead of more generic specifications that might guide the development differently (e.g., creating foundation first and then adding the functionality). The examples model the behaviour expected in the software solution once completed. Commonly, these examples are captured as automated scripts in Gherkin (Given-When-Then) and used to guide (or drive) the creation of the code that would implement the associated behaviour. Notice, however, that BDD, in its current stage, does not prescribe automation. It’s more about having conversations about the behaviour than automating “tests”.
before start with cucumber, you need to install cucumber plugin in eclipse marketplace
we are going to go step to learn cucumber using java and we will learn how to set up our
project in Eclipse so let's get started
and step number one is we have to create a new maven project in Eclipse so I will go to my Eclipse and here I am on my windows an Eclipse in case you are on Mac you can follow the same steps so here you can use Eclipse is on Mac and this one is on Windows so I am going to follow this on Windows but I will tell you if there are any differences you can follow this on Windows or Mac operating system so here I have to create a new maven project that is step number one I can do a right-click under the package Explorer and go to new and here I can go to others you can also go to your file and then go to new and go to others and here search for maven and you will find an option for maven project now in all the recent versions of Eclipse maven plugin is already installed and you will directly find this option just in case you are using a very old version of Eclipse.
I will select create a simple project so that it can skip the archetype selection and say
next and here I will give the group ID and artefact ID so I will say this is cucumber Java project or you can say cucumber Java selenium any name you can give here I will again say cucumber Java and I will click on finish and this will
create the project just go to
new and go to Java and say next and you can create working folders and the files present and here you will find a file called pom.xml where we can add our dependencies so we have done step number one which is create a new maven project and now step number two is we will add the Maven dependencies for cucumber java cucumber TestNG and selenium Java now I will add these dependencies one by one so that I can see libraries or dependencies are used in total these are the four dependencies that we will need so let me start with cucumber Java and for that, here I
from now on I'm going to stop this article. I will suggest you for pom.xml to continue in the next article it incudes selenium , junit and extent reports.
<dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.7.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.7.0</version> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-java</artifactId> <version>1.2.5</version> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-jvm-deps</artifactId> <version>1.0.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-junit</artifactId> <version>1.2.5</version> <scope>test</scope> </dependency> <dependency> <groupId>com.vimalselvam</groupId> <artifactId>cucumber-extentsreport</artifactId> <version>3.0.2</version> </dependency> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> <version>3.1.2</version> </dependency> </dependencies>
No comments:
Post a Comment