Cucumber Framework

 Choose Maven FW:


Step 1 - Create a new maven project
Step 2 - Add maven dependencies
  Cucumber Java | Cucumber JUnit | JUnit | Selenium Java
Step 3 - Create a folder Features under src/test/resources
Step 4 - Under features folder create a new feature file login.feature
Step 5 - Download cucumber plugin from Eclipse Marketplace
Step 6 - Create feature file and add contents
  • Feature
  • Scenario
  • Steps
  • Scenario Outline
  • Example
  • Tags
  • Comments
Step 7 - Try to run the feature file
Step 8 - Add Step Definitions / Glue Code under src/test/java package
Step 9 - Create a Runner class
Step 10 - Create Add Cucumber Options for generating reports
   HTML | JSON | JUNIT/XML   
Step 11 - Run and verify results


HOOKS:

Cucumber supports hooks, which are blocks of code that run before or after each scenario.:

@Before and @After


package utilities;

import cucumber.api.java.After;
import cucumber.api.java.Before;
public class Hooks {

@Before
public void beforeScenario(){
System.out.println("This will run before the Scenario");
}
@After
public void afterScenario(){
System.out.println("This will run after the Scenario");
}
}

An important thing to note about the after hook is that even in case of test fail, after hook will execute for sure.

Method name can be anything, need not to be beforeScenario() or afterScenario(). can also be named as setUp() and tearDown().

*Make sure that the package import statement should be import cucumber.api.java.After; & import cucumber.api.java.Before;


package stepDefinition;

import org.junit.runner.RunWith;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(features="src/test/resources/Features",
glue={"StepDefinitions"},
monochrome = true,
plugin = {
"pretty", "html:target/reports",
"pretty", "json:target/reports/cucumber.json",
"pretty", "junit:target/reports/cucumber.xml"
},
tags="@smoketest"
)
public class Runner {

}


Comments

Popular posts from this blog

The self healing automation framework - Healenium Updated Dec2023

Heleanium - Web without using Docker