In our previous article, we discussed how to use And and But in Cucumber to avoid repetitive keywords and make our scenario more readable and expressive. When you have a scenario with lots of steps that are effectively a list of things, you will find even And and But are not enough.
For Long lists of steps that can be grouped and relate to the same subject, we can use an asterisk (*) instead of And, But, or any other keyword.
Scenario with And and But
@SmokeA
Scenario: Sample Scenario 2
Given I am on the homepage
And I should see "Sign in" link
When I follow "Sign in"
And I fill "email address" with "goswami.tarun77@gmail.com"
And I fill "password" with "tarun@123"
And I click "sign in"
Then I should see "My Account" Heading
And I should see "my account" link
But I should not see "Login" Heading
Scenario with Asterisk
@SmokeA
Scenario: Sample Scenario 2
Given I am on the homepage
And I should see "Sign in" link
When I follow "Sign in"
And I fill "email address" with "goswami.tarun77@gmail.com"
* I fill "password" with "tarun@123"
* I click "sign in"
Then I should see "My Account" Heading
And I should see "my account" link
But I should not see "Login" Heading
These asterisks (*), which are more like bullet points, are suitable for visual distinction and let readers see logical groups clearly.
You can use * for all keywords but for best results, mix asterisks and keywords to improve the readability of your scenario.