Cucumber BDD Framework
Cucumber-jvm is an open source BDD (Behavior Driven Development) tool that lets user express the behavior of system under test in plain English. It is a great way to have an executable documentation of your system.
For reference please click on the links mentioned below:
For an example, think of writing a simple addition program. If you were to practice BDD, the team
should get together to define the expected behavior such as:
- should perform addition of two positive number
- should perform addition of a positive and a negative number
- should perform addition of two negative number
- should perform addition for decimal numbers upto 2 digits and likewise
Gherkin is a plain English text language, which helps the tool – Cucumber to interpret and execute the test scripts.
Example
- Feature – User Access Management for a social networking site.
- Scenario– Verify Authentication Functionality
- Given I am a social networking site user.
- When I enter username as username1.
- And I enter password as password1.
- Then I should be redirected to the home page of the site.
SLNO |
Pre-Condition |
Test step |
Test Data |
Expected |
Actual |
Given |
When |
Single Value/ Parameters |
Then |
- Create a Maven Project.
- Click on Next->Next->New Maven project. Enter the following details of New Maven Project.
ArtifactID->TotalQACucumberFwk
package->org.totalqa
GroupID->org.totalqa
Click on Finish button to create the Maven Project.
- Open pom.xml created in the Project. Provide the cucumber-jvm, cucumber-java dependencies in the pom.xml as mentioned below:
- Download the cucumber plugin in eclipse. Access Help->Eclipse Marketplace. Type cucumber and click install.
- Restart the Eclipse once the plugin is installed successfully.
- Right click on the project and select the New ->Folder to create a folder under the project.
Provide name as ‘cucumberfeatures’.
- Right click on the folder->Select File as shown file. Provide the file name as ‘login.feature’.
- Open the File ‘login.feature’ and provide the details mentioned below
- Create a package as ‘com.cucumber.tests’ under src/test/java folder.
10 . Create a Java Class named “LoginTest.java” using the following code under the package com.cucumber.tests.
Link the Feature file to the Java Class
@CucumberOptions(features=”cucumberfeatures/Login.feature”)
- Right click on the Java class->Run As->Junit Test
11 .Check the results in the Junit Tab and console.
Cucumber-JVM installation is done successful.
- Right click on the Java class->Run As->Junit Test.
- Once the program is executed successfully. Check the contents of the Console.
- Copy the contents of the console to the another page object program created under the package ‘com.cucumber.pages’.
- Contents of the Page Object program shown below:
- Update the Test Program to attach the Pages using the glue code.
- Execute the Test Program by right click run as Junit Program.
Thanks that was helpfull. Keep doing the good deeds.