Search code examples
bddreusabilityparameterizedjbehave

How to parameterize GivenStories as well as the current story I am testing?


I want to reuse some of the steps that are common. for example

Scenario: Navigate to Page 2 and perform first set of validations
Given A user<username> is logged in
When user clicks on <menuItem>
and page <page_name> is displayed
and user clicks on Submit button
Then Page <second_page> is displayed
And validate <condition_1>

Scenario: Navigate to Page 2 and perform second set of validations
Given A user<username> is logged in
When user clicks on <menuItem>
and page <page_name> is displayed
and user clicks on Submit button
Then Page <second_page> is displayed
And validate <condition_2>

Examples:
|username|page_name|menuItem|condition_1|condition_2|
|username1|Page1|Menu1|Condition1|Condition2|

Now, Since the given conditions are same, I would like to normalize the story to something like this.

In precondition1.story

Given A user<username> is logged in
When user clicks on <menuItem>
and page <page_name> is displayed
and user clicks on Submit button
Then Page <second_page> is displayed

In currentTestStory.story

GivenStories: precondition1.story

Scenario: Navigate to Page 2 and perform first set of validations
Given Page <second_page> is displayed
And validate <condition_1>

Scenario: Navigate to Page 2 and perform second set of validations
Given Page <second_page> is displayed
And validate <condition_2>

Examples:
|username|page_name|menuItem|condition_1|condition_2|
|username1|Page1|Menu1|Condition1|Condition2|

But the challenge I am facing is, I cannot parameterize the GiveStory from the current story. Is there a way to achieve what I am trying to do?


Solution

  • My approach would be to not use GivenStories at all in this story. Use the step

    Given Page <second_page> is displayed
    

    and then do whatever it takes in the step in order to display that second page.