0

This is my feature file -

Background: Common steps
Given User should be on profile dashboard page


Scenario Outline: Adding new key and values
**Then User clicks on Add New Key button**
Then User enters Key name, Key description, Value type and Add 
value to key
Then User selects the required default value radio button
**Then User clicks on save button
Then User clicks on cancel button**
And User can see the newly added key-value on the profile 
dashboard page

Examples: | KeyName | Desc | AddValue |
          | TestKey | Test | Required |

Scenario: To verify if able to add same Key name
**Then User clicks on Add New Key button**
Then User enters existing key name and values
Then User selects the default value
**Then Now user clicks on Save button**
And User should see error message saying Key & values already 
existing

Can I use the highlighted steps in background and how, please help me with this

Rudra
  • 1
  • 4
  • if every scenario start with step `Then User clicks on Add New Key button` you can simply move this step to background. With steps inside scenarios you can't do it, but you can merge them. – lojza Apr 20 '22 at 15:41
  • Ok Thank you.. I will try that.. – Rudra Apr 22 '22 at 17:40

1 Answers1

0

First of all as a new cuker avoid scenario outlines. They just make things more complicated and you don't need that when starting (or ever actually)

The next thing to do is to avoid putting HOW you do things in your feature files. So instead of

When I type in my username
Add I type in my password
And I click login

you write

When I login

Note how you are only described WHAT you are doing, not HOW you are doing it.

This pushes all the detail down out of your feature and into steps (or better yet helper methods your steps call). Lower is better for details because you are now in a programming language which is far better for programming details.

When you do the above most/all of your problems in your original post disappear. In addition you feature is much easier to read.

If you follow on from this and make each step definition implementation a call to a helper method you will find things become even easier to manage, as you can easily re-use helper methods in other step definitions and other helper methods.

TLDR Express only the intent of what you are doing in features. Push all the details of HOW you do thing DOWN to the code.

diabolist
  • 3,990
  • 1
  • 11
  • 15