Appearance
Writing Effective Scenarios
A scenario is a detailed test case document covering an application's feature in linear statements. BlinqIO AI generates the test execution code based on the steps defined in a scenario.
Scenarios are defined using Gherkin syntax, which uses a set of special keywords to give structure and meaning to executable test cases.
Example:
gherkin
Scenario Outline: Create a new Github repository
"""
Create a new GitHub repository and verify it is present in the top repositories list.
"""
# The repository should be private
Given Create a new repository name "<repo>", description "<description>", and README file
When Navigate to the home page
When filter the top repository with "<repo>"
Then Verify the repository name "<repo>" can be found under Top Repositories
Examples:
| repo | description |
| {{string.alpha(10)}} | description 1 |
We currently support these keywords for defining a scenario using the Gherkin syntax:
- Scenario Outline
- Given
- When
- Then
- And
- Examples
Scenario Outline
Use the Scenario Outline
keyword to provide a one-line test scenario description. This should always be the first line in the scenario.
Example:
gherkin
Scenario Outline: Create a new Github repository
...
...
Given & When
Use Given
and When
for operations that require actions like navigating to a different page or interaction with UI elements like forms, inputs, buttons, menus, etc.
Example:
gherkin
Scenario Outline: Buy Item
Given login with username as "blinq_admin" and password as "let_me_in"
Given add "keyboard" to basket
When open basket
When checkout with first name "John", last name "Doe", zip "10001"
...
Then
Then
steps are used to describe an expected outcome, or result. Use Then
only for different types of analysis
Example:
Note
While it might be tempting to implement Then
steps to look in the database - resist that temptation! You should only verify an outcome that is observable for the user (or external system), and changes to a database are usually not.
gherkin
Scenario Outline: buy item
Given login with username as "blinq_admin" and password as "let_me_in"
Given add "keyboard" to basket
When open basket
Then the total price is 25.99
When checkout with first name "John", last name "Doe", zip "10001"
Then verify "Thank you for your order" can be found in the page
And
If you have successive Given
,When
or Then
’s, you could make the scenario more fluidly structured by replacing them with And
.
Example: Before using And
gherkin
Scenario Outline: buy item
Given login with username as "blinq_admin" and password as "let_me_in"
Given add "keyboard" to basket
When open basket
When select shipping option as premium
Then the total price is 25.99
Then verify "Thank you for your order" can be found in the page
Example: After using And
gherkin
Scenario Outline: buy item
Given login with username as "blinq_admin" and password as "let_me_in"
And add "keyboard" to basket
When open basket
And select shipping option as premium
Then the total price is 25.99
And verify "Thank you for your order" can be found in the page
The Examples
Section
You can define the test parameters for your scenario steps in the Examples
section. The Examples section contains a pipe (|
) delimited table with a header row for parameter names and subsequent rows that define test values. The Scenario Outline
is run once for each row in the Examples
section.
Use <>
delimited parameters to reference parameters in the examples table.
Note
The parameter values in the Examples
table can also contain dynamic values like:
1. {{string.alpha(N)}} : Generate a random string of length N.
Example:
Gherkin
Scenario Outline: Create a new Github repository
Given Create a new repository name "<repo>", description "<description>", and README file
When Navigate to the home page
When filter the top repository with "<repo>"
Then Verify the repository name "<repo>" can be found under Top Repositories
Examples:
| repo | description |
| {{string.alpha(10)}} | A test repo |
TIP
For more advanced information, see Writing Effective Test Scenarios.