对于黄瓜中的相同业务逻辑,我有不同的字符串。 因此,我试图找到一种方法来用一个函数标记多个Gherkins字符串。
我在下面尝试,但是我不明白用黄瓜来配制它
Using @Repeatable while mainaining support for Java 7
示例:
Scenario Outline: Looking up the definition of fruits
the user is on the Wikionary home page for fruits
When the user looks up the definition of the word <name>
Then they should see the definition 'An edible fruit produced by the pear tree, similar to an apple but elongated towards the stem.'
Examples:
| name |
| pear |
Scenario Outline: Looking up the definition of orange
Given the user is on the Wikionary home page for orange
When the user looks up the definition of the word <name>
Then they should see the definition 'An edible fruit produced by the pear tree, similar to an apple but elongated towards the stem.'
Examples:
| name |
| pear |
在上述陈述中,给定是不同的,但业务功能是相同的。 我如何用Java的重复性标记它。
或除|| p以外的任何其他方式
任何变通办法都会有所帮助!!!
答案 0 :(得分:1)
具有这样的步骤定义-它应与任何相似的步骤匹配并且也不能捕获
@Given("^the user is on the Wikionary home page for (?:\\w+)$")
public void given() {
System.out.println("givn");
}
@Given("^should go to given (?:,*) $")
@Given("^should go to given - (.*?) - (?:,*) $")
@Given("^should go to given - (.*?) - (.*?) - (?:,*) $")
这将采用不同的参数。但这将完全破坏小黄瓜步骤文本,使其完全乱码。使用它会非常不舒服。
答案 1 :(得分:0)
对于以上两种情况,您只能编写一次“步骤定义Java”代码,它将为两种不同的情况自动运行相同的步骤定义代码:
Scenario Outline: Looking up the definition of fruits
Given the user is on the Wikionary home page for "fruits"
Scenario Outline: Looking up the definition of orange
Given the user is on the Wikionary home page for "orange"
对于上面的@Given语句,您只能编写一个步骤定义方法,它将根据不同的参数配置在两种情况下自动执行:
@Given("the user is on the Wikionary home page for (.*))
public void given(String fruitName)
{
System.out.println(fruitName);
}