Cucumber Series Tutorial 3- Make your Automation Data Driven by Parametrising Feature File with Scenario Outline and Examples keyword.
In Tutorial 2 we have seen, how to make test script data-driven by parametrizing the Feature file.
But the problem with this approach is, if we have to supply multiple data then we have to write separate methods in step definition file, which will add a lot of boilerplate code. Another approach is using "Examples"
And we will provide test data through Examples keyword:
Changes in Step definition:
No changes in the step definition file, from tutorial 2. Please find below the example.
Now perform the dry run from the Test Runner class.
Console Output in Eclipse:
I hope you like this tutorial, please share it and like and comment. Also let me know, if you want me to write a tutorial on some other topic as well. Till then, Happy Learning !!!!
But the problem with this approach is, if we have to supply multiple data then we have to write separate methods in step definition file, which will add a lot of boilerplate code. Another approach is using "Examples"
Approach 2: Parametrising the Test script using Examples Keyword and Scenario Outline.
Changes in Feature File:
Here, instead of using Scenario, we will be using Scenario OutlineAnd we will provide test data through Examples keyword:
Feature: Free CRM Login Feature
Scenario Outline: Free CRM Login Test Scenario
Given User is already on Login Page
When Title of login page is Free CRM
Then user enters "<username>" and "<password>"
And User clicks on login button
And user is on home page
Examples:
| username | password |
| user1 | password1 |
| user2 | password2 |
Changes in Step definition:
No changes in the step definition file, from tutorial 2. Please find below the example.
@Then("^user enters \"(.*)\" and \"(.*)\"$")
public void user_enters_Username_and_password(String username, String password) {
driver.findElement(By.xpath("//input[@name='email']")).sendKeys(username);
driver.findElement(By.xpath("//input[@name='password']")).sendKeys(password);
}
Now perform the dry run from the Test Runner class.
Console Output in Eclipse:
I hope you like this tutorial, please share it and like and comment. Also let me know, if you want me to write a tutorial on some other topic as well. Till then, Happy Learning !!!!
Great Content. very Helpful!!
ReplyDelete