Cucmber Material
Cucmber Material
Cucmber Material
Scenario Outline – This is used to run the same scenario for 2 or more different set of test
data. E.g. In our scenario, if you want to register another user you can data drive the same scenario
twice.
Examples – All scenario outlines have to be followed with the Examples section. This contains the
data that has to be passed on to the scenario.
@When(“^User enters \”(.*)\” and \”(.*)\”$”)
The same can be achieved by using the below code as well:
@When(“^User enters \”([^\”]*)\” and \”([^\”]*)\”$”)
With the help of the above statements, Cucumber will understand that the associated Test_Step is
expecting some parameters.
intuitive as you either need to deal with a list of maps or a map of lists.
Feature File:
We will pass the test data using data table and handle it with using Raw() method.
@When("^User enters Credentials to LogIn$")
public void user_enters_testuser__and_Test(DataTable usercredentials) throws Throwable {
//This is to get the first data of the set (First Row + First Column)
driver.findElement(By.id("log")).sendKeys(data.get(0).get(0));
//This is to get the first data of the set (First Row + Second Column)
driver.findElement(By.id("pwd")).sendKeys(data.get(0).get(1));
driver.findElement(By.id("login")).click();
}
In this test we will pass Username and Password two times to the test step. So our test should
enter Username & Password once, click on LogIn button and repeat the same steps again.
Things to note
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;
2) Create a Step definition file and just print the execution order of the steps in the console.
Hooks can be used like @Before(“@TagName”). Create before and after hooks for every scenario.
I have also added normal before and after hooks,
Note: We learned that @Before & @After hooks runs before & after every Scenario.
But @Before(“@First”) will run only before the first scenario and like wise other tagged hooks.
Again, these tags names can be anything and no need to be first, second and third.