Gherkin Is The Language To Define The BDD Framework
Gherkin Is The Language To Define The BDD Framework
On the basis of behaviour, we write the test cases, there are 3 components in Cucumber
1 feature file
feature file is a login.feature all the gerkins features will be used here. We use all the key word here
like given, when, then as, but, and,
With the help of these key words we will define SCENARIO, SCENARIO OUTLINE FOR a specific
feature Feature: is the keyword
(login.feature) file
We need to download get the Gherkin keyword automatically that is "Natural Plugin"
Our product managers/BA /manual testers will write the acceptance criteria in feature file format
// nothing but they are defining the behaviour of the test cases and we are converting into the step
definitions
Disadvantages of BDD: So many steps we have write in this framework its lengthy but entire agile
team will contribute everybody will be on the same page
2 STEP DEFINITION
Corresponding to the feature file we will write all codes into Step definition like JAVA and selenium
code and different annotations.
@Given("^copy the exact line given in feature file$") ^$ will understand the cucumber language
// create a method
public void User_is_already_on_login page(){
}
3. Test Runner
We will be writing the Test Runner in JUNIT to run in your feature and to generate the output/report
@RunWith(Cucumber.class) // Run with import from JUNIT and Cucumber.class import from
cucumber.apu.CucumberOptions;
// in testng we use testng.xml file to control our test cases like wise we have TestRunner.java in
cucumber control the executions
features = "Copy you path of features" // where exactly your feature file is available
no need to write login.feature file direct package name
,glue= {"package name of stepDefinition or path "} // standard thing
,format = {"pretty", "html:test-output"}
// scenario will get skipped if the step definition is not written, in the console the step definition
missing just copy the code snippet
All these Cucumber Options are defined in runner class expect Tags
Dryrun
to check whether the mapping is done fine or not between Feature file and Step Definition.
It gives missing stepdefinition
you will come to know which methods are missing in for stepdefinition the we can write the code in
it with respect to steps available in Login.feature file
dryRun= true
dryRun = false
Glue
The path of StepDefinition
Features
The path of feature file/package
Format
Format is used to generate different types of reporting
Html
JSON
XML format is format = {"pretty", "junit:junit_xml/cucumber.xml"}
Strict
strict=true,
it will check if any step is not defined in definition file
@Then ("^ user enters \"(.*)\" and \"(.*)\"$") // this is the \"(.*)\" regular expression it picks from
feature file (no hardcoded)
driver.findelement(By.name("username").sendkeys("username");
driver.findelement(By.name("password").sendkeys("password");
With examples keyword
Scenario Outline: free crm test
Examples:
|username|password|
|naveen |123456|
|tom |122122|
If you are using with examples keyword then Scenario outline (multiple data can be pass through
pipe symbol)
To achieve data driven We have to use examples keyword with scenario outline
Cucumber Tags
This is like @Before and @After this is used for each SCENARIO
like launching browser we can use this one time instead of repeating
hook.feature file
Hooks_step_def
@Before
public void 5etup(){
System.out.println(“launch FF”);
System.out.println(“Enter URL”);
@After
public void teardown(){
System.out.println(“Close browser”);
//Global Hooks @After @Before it will be executed to all scenarion (This is @beforeClass in
TestNG)
// @Before("@First") // local (this is @First you must mention in your feature file too)
This is like Before method in TestNG that means you can customize the scenarios
You can control scenarios’ which has to be executed
We can also define ordering for Hooks this gives the preference
@Before(order=0)
@After(order=0)
@Before(order=1)
@After(order=1)