BDD
BDD
To fill the gap between technical team and non-technical team BDD came into picture.
BDD uses simple plain English language (Gherkin) to the features, so that a non-
technical guy also understands the project flow easily.
Cucumber is the tool one way to achieve the BDD approach. Another one is Spec flow
Required Dependencies:
Cucumber Java
Cucumber JUnit
JUnit
Selenium Java
WebDriverManager
Cucumber Eclipse Plugin from Eclipse Market
Participation: Technical team interaction more. All the team members including Client.
Cucumber Annotations:
Given (): Pre condition.
When (): Action
Then (): Expected Results.
And (): to extend
Feature file: Which allow us to write all the scenarios in plain English language (Gherkin).
Stepdefination-file (or) Glue Code: Which allows us to add all technical implementation of
feature file.
Runner Class: Where we can run our project or Run individual classes and It has different
options like.
@RunWith (Cucumber. Class)
@CucumberOptions (features= “./Features/Login.feature”,
glue = "stepDefinations",
monochrome=true, //to clean up the unwanted symbols in the console
dry Run=false, // will be used to check for any compilation errors and it works like a headless
browser testing
plugin= {"pretty","html:reports/cucumber.html"}
)
public class RunnerClass {
}
| username | password |
|[email protected] | admin@123 |
|[email protected] | admin123@ |
TAGS:
It will be used when we want to run different test cases from scenarios like
@SmokeTest, @SanityTest @RegressionTest etc...
@sanity
Scenario2
Given
When
Then
@regression
Scenario3
Given
When
Then
HOOKS:
Hooks are listeners in TestNG
To manage setup and tearDown methods we use @Before and @After hooks
@BeforeStep
public void setup ()
{
Syso ("I will execute before every step")
}
@AfterStep
public void after ()
{
Syso ("I will execute after every step")
}
@When ("UserclickonSignInoption")
public void UserclickonSignInoption () {
loginpage = new LoginPage ();
loginpage. signInOption ();
}
output:
I will execute before every step
@Given
I will execute before after step
I will execute before every step
@When
I will execute after every step
But @Before and @After hooks executes only before and after scenarios.
Conditional Hooks: If I want to execute some of the methods in order.
@Before(order=0)
public void setup ()
{
Syso ("I will execute first")
}
@Before(order=1)
public void setupOne ()
{
Syso ("I will execute second")
}
@After(order=0)
public void after ()
{
Syso ("I will execute second")
}
@After(order=1)
public void afterOne ()
{
Syso ("I will execute first")
}
BACKGROUND: A Step or Group of steps common to all the features (Example: Login is common
for some functionalities hence make login as background)
Backgrounds will be defined in Feature file and runs before every scenario. Unlike hooks
background visible to users.