2

我想重用一些常见的步骤。例如

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|

现在,由于给定的条件相同,我想将故事规范化为这样的东西。

在 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

在 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|

但我面临的挑战是,我无法从当前故事中参数化 GiveStory。有没有办法实现我想要做的事情?

4

2 回答 2

0

您可以从当前故事参数化给定故事。

请参阅http://jbehave.org/reference/stable/given-stories.html页面上的“通过示例参数化的 GivenStories”部分

缺点是您必须修改代码并将 @Named 注释添加到您的 java 步骤中。所以根据页面中的例子,下面的方法可以照顾到例子中的参数:

@When("Something happens")
public void happening(@Named("One") String one, @Named("Two") String two) {
    //Do good
}
于 2013-04-05T09:48:40.080 回答
0

我的方法是在这个故事中根本不使用 GivenStories。使用步骤

Given Page <second_page> is displayed

然后在该步骤中执行任何操作以显示第二页。

于 2013-04-16T14:15:56.760 回答