我正在我的项目中使用由代码感知驱动的小黄瓜。我想测试一个角色的用户是否能够看到适合他的菜单入口点。
此时我使用这个场景:
Scenario: basic menu check
User "foo" has role "basic_user"
Given I am logged in as "foo" with password "Test123!"
Then I should see "Project" menu point
And I should see "Settings" menu point
And I should see "Notifications" menu point
And I should see "Messages" menu point
And I should see "Logout" menu point
Then I logout
我想多次重复使用3个步骤:
And I should see "Settings" menu point
And I should see "Notifications" menu point
And I should see "Messages" menu point
每次创建新方案时,我都不想复制和粘贴它。相反,我想把它写成...让我们说包含文件(也用小黄瓜语言),并在我的场景中使用它:
Scenario: basic menu check
...
Include "common_menu_check"
...
有可能吗?我怎么能这样做?
答案 0 :(得分:2)
为什么你不能写一个新的步骤?
/**
*
* @Then /^I should see the common menu points$/
*/
public function iShouldSeeTheCommonMenuPoints()
{
// CODE HERE FOR SEEING MENU ITEMS
}
然后在功能文件中使用此步骤:
Scenario: basic menu check
User "foo" has role "basic_user"
Given I am logged in as "foo" with password "Test123!"
Then I should see the common menu points
And I should see "Project" menu point
And I should see "Logout" menu point
Then I logout
答案 1 :(得分:2)
除了Kyle的回答之外,我更倾向于以下列方式重写使用table作为多行参数的示例中的场景:
Scenario: basic menu check
User "foo" has role "basic_user"
Given I am logged in as "foo" with password "Test123!"
Then I should see menu points:
| Settings |
| Notifications |
| Messages |
| Logout |
Then I logout
它不那么迫切,更加人性化("我应该看到"在每一行都太无聊了)所以与客户讨论会更容易。
请注意,此处用作多行参数的表,而不是示例。请参阅表格作为此处步骤的多行参数: