What is Scenario Outline in Cucumber?
Scenario Outline:
Please comment below to feedback or ask questions.
Scenario Outline:
- It is a keyword provided in gherkin language.
- It is mainly used to execute the same scenario multiple times, with different combinations of input test data/values.
- Scenario Outline is a synonym of the keyword Scenario Template.
- Examples is a keyword and must be used in the scenario outline to pass the input data/values.
Demo on Scenario Outline:
Let's say I have 2 scenarios like below:
scenarioOutline.feature:
Feature: Demo on scenario outline
Scenario: First scenario
Given I am on home page
When I search for "Nokia" mobile
Then I should see mobile phones
Scenario: Second scenario
Given I am on home page
When I search for "Samsung" mobile
Then I should see mobile phones
Here,we observe 2 scenarios having same steps but with different input values.(nokia,samsung)
By using scenario outline we write above 2 scenarios into 1 scenario with different input values.
Scenario Template: Scenario outline example
Given I am on home page
When I search for "<mobile_company>" mobile
Then I should see mobile phones
Examples:
| mobile_company |
| Nokia |
| Samsung |
For above scenario,
Observe we have used keyword Scenario Template and step definitions are implemented like below:
public class outLineStepDefinitions {
@Given("I am on home page")
public void iAmOnHomePage() {
System.out.println("I am on Home Page");
}
@When("I search for {string} mobile")
public void iSearchForMobile(String parameter) {
System.out.println("I search for "+parameter+" mobile");
}
@Then("I should see mobile phones")
public void iShouldSeeMobilePhones() {
System.out.println("I should see Mobile Phones");
}
}
Now execute the scenario:
Cucumber Scenario Outline |
We can also pass multiple arguments/test data/values in steps.
Cucumber Scenario Outline |
No comments:
Post a Comment
Please comment below to feedback or ask questions.