我是Cucumber和Gherkin的新手,我想我会遇到这种情况。主页包含许多功能,当然您希望从家中启动并执行任务功能。
Given user logged into home page
When user performs feature 1
Then ...
Given user logged into home page
When user performs feature 2
Then ...
当你为第二个特征运行Cucumber时,它会抱怨Given步骤不明确。
如何解决此问题?您可以为第二个功能稍微更改Given步骤。通过这样做,你实际上在重复自己。思绪,有人吗?
答案 0 :(得分:1)
如果用户登录主页是您要在该功能中运行的测试的先决条件,那么将其置于后台:
Background:
Given user logged into home page
然后:
Scenario: 1
When user performs feature 1
Then ...
Scenario: 2
When user performs feature 2
Then ...
答案 1 :(得分:0)
我把我的情况略有不同,举个例子
Given user logged into home page
When user performs feature 1
Then ...
Given user logged into home page
When user performs feature 2
Then ...
在我相应的步骤文件中,我会在顶部有一个可重复使用步骤的部分(因为不要忘记所有匹配都在regexp上)
# Reusable Steps
Given(/^user logged into home page$/) do
# login steps here
end
# Feature 1
When(/^user performs feature 1$/) do
# steps here
end
# Feature 2
When(/^user performs feature 2$/) do
# steps here
end
个人偏好我想但我想我会分享