Domanda

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

You CAN parameterize the Given story from the current story.

See section "GivenStories parametrized by Examples" on page http://jbehave.org/reference/stable/given-stories.html

The drawback is that you have to modify the code and add @Named annotation to your java steps. So according to the example in the page, the following method can take care of the parameters in the example:

@When("Something happens")
public void happening(@Named("One") String one, @Named("Two") String two) {
    //Do good
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top