About Cucumber & Cucumber vs. TestNG

0
55
Cucumber-logo-devtestops.in

A cucumber is a tool based on Behavior Driven Development (BDD) framework which is used to write acceptance tests for the application. It allows to write tests in easily readable and understandable format (like plain English) to Business Analysts, Developers, Testers, etc. Gherkin is the language that Cucumber uses to define test cases.

Install Cucumber

1. Add Cucumber Eclipse Plugin

• Go to Eclipse IDE > Install New Software > Add

Name:- Cucumber

• Location:- http://cucumber.github.com/cucumber-eclipse/update-site

Note:- It’s not mandatory plugin, it’s used to highlight Gherkin syntax. 

2. Add Cucumber’s Dependencies:-

• cucumber-core

• cucumber-java

• cucumber-testng

• cucumber-junit

Cucumber has four types of files:-

1. Features Files

2. Step Files

3. Runner File

4. Cucumber Report

Now, have a look at sample of each file one by one.

Feature File

You can write test cases in Gherkin language by using keywords FEATURE, SCENARIO, GIVEN, WHEN, THEN, AND, BUT

Feature: Create One Google Account

@Smoke
Scenario: Create an account for Google
Given Navigate to Google Account Page
When Enter First Name
And Enter Last Name
And Enter Username
And Enter Password
And Enter Confirm Password
Then Click on Next button

Step File

Each feature file will have a corresponding step file e.g.

package StepDefination;

import BaseInitiator.InitClass;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class CreateGoogleAccount extends InitClass{

@Given("Navigate to Google Account Page")
public void navigate_to_Google_Account_Page() {
    objCreateGoogleAccountPage.NavigateGoogleAccountPage();
    System.out.println("Google Account Page is open");
}

@When("Enter First Name")
public void enter_First_Name() {
    objCreateGoogleAccountPage.firstName.sendKeys("Deepak");
    System.out.println("Entered First Name");
}

@When("Enter Last Name")
public void enter_Last_Name() {
    objCreateGoogleAccountPage.lastName.sendKeys("Raja");
    System.out.println("Entered Last Name");
}

@When("Enter Username")
public void enter_Username() {
    objCreateGoogleAccountPage.username.sendKeys("deepakraja"); 
    System.out.println("Entered Username Name");
}

@When("Enter Password")
public void enter_Password() {
    objCreateGoogleAccountPage.password.sendKeys("pass@1234");
    System.out.println("Entered Password");
}

@When("Enter Confirm Password")
public void enter_Confirm_Password() {
    objCreateGoogleAccountPage.confirmPassword.sendKeys("pass@1234");
    System.out.println("Entered Confirm Password");
}

@Then("Click on Next button")
public void click_on_Next_button() {
    objCreateGoogleAccountPage.Next.click();
    System.out.println("Clicked Next Button");
}

}

Runner File

Runner file will execute each step of Feature file.

@CucumberOptions(
features = “src/test/resources/Features”,
glue = { “StepDefination” },
monochrome = true, //More readable
plugin = {“pretty”, “html:target/report/”},
tags = {“@Smoke”})

Cucumber Report

After successful run, the report will be shown in target/report folder:-

Difference between Cucumber & TestNG

Cucumber

• Good for Acceptance Testing

• It’s not a Unit Testing Tool

• Non Technical person can understand the test easily. •Cucumber Supports Gherkin Language to implement test in the same language as we discuss with business.

TestNG

• TestNG is a Unit Testing Tool.

• Difficult for Non Technical person.

• Supports Priorities, Dependencies, Grouping etc. Useful when large number of Test Cases are executed.

LEAVE A REPLY

Please enter your comment!
Please enter your name here