I'm trying to write a cucumber test for part of our application (I'm completely new to cucumber, and writing acceptance tests really), and I have a step in the test, which I want to do one of 2 different things. I want it to either check for a specific value, or check for a system default value.
This is what I came up with
Scenario Outline: English News
Given with the locale is set to '<language>'
When a user views the page
Then they see the <image> image
Examples:
| language | image |
| en-gb | default |
| fr | "french.png" |
This then hits one of 2 different step definitions,
@And("^they see the default image$")
public void defaultImage() throws Throwable {
// check for system default
}
@And("^they see the \"(.*)\" image$")
public void customImage(String image) throws Throwable {
// check for specific value from the input
}
Is this the correct way to do this? My TL has suggested that I should actually only have the one step def, and pass "default" as the input, and then do a conditional check inside the step def, like this:
@And("^they see the \"(.*)\" image$")
public void checkImage(String image) throws Throwable {
if ("default".equals(image)){
// check for system default
} else {
// check for specific value from the input
}
}
Which is the correct way to do this? Any help is greatly appreciated.
答案 0 :(得分:0)
您的默认图片必须有真实姓名,对吗?那么为什么不验证它的真名呢?因为“默认”可能是任何东西所以不是每个人都可以理解同样的事情。
如果你这样做,确实你只需要一步def。我不会做一个if检查,我会断言真实的名字。您可以在示例表中添加注释,说明第一个值是默认值,以便团队中的每个人都清楚。