如何获得标题中的黄瓜情景变量? [英] How can i get cucumber scenario variables in title?
本文介绍了如何获得标题中的黄瓜情景变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过使用标题本身中的示例,我希望能够使我的场景大纲标题具有更多信息:
I would expect to be able to have my scenario outline title have more information by using the examples within the title itself:
Scenario Outline: A <some> step is <result>
When a <some> step
Then I get <result>
Examples:
| some | result |
| passing | passed |
| failing | skipped |
Then my scenario titles end up very useful:
Scenario: A passing step is passed
Scenario: A failing step is skipped
推荐答案
Then
关键字必须在 Examples
上方.
Feature: Scenario outline with variables
Scenario Outline: A "<some>" step is "<result>"
When a "<some>" step
Then I get "<result>"
Then my scenario titles end up very useful
Examples:
| some | result |
| passing | passed |
| failing | skipped |
使用胶水 ScratchSteps.java
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class ScratchSteps {
private String step;
private String result;
@Then("^my scenario titles end up very useful$")
public void myScenarioTitlesEndUpVeryUseful() throws Throwable {
System.out.printf("step: %s result: %s%n", step, result);
}
@When("^a \"([^\"]*)\" step$")
public void aStep(String step) throws Throwable {
this.step = step;
}
@Then("^I get \"([^\"]*)\"$")
public void iGet(String result) throws Throwable {
this.result = result;
}
}
输出为
Feature: Scenario outline with variables
Scenario Outline: A "<some>" step is "<result>" # features/scratch.feature:3
When a "<some>" step
Then I get "<result>"
Then my scenario titles end up very useful
Examples:
Scenario Outline: A "passing" step is "passed" # features/scratch.feature:9
When a "passing" step # ScratchSteps.aStep(String)
Then I get "passed" # ScratchSteps.iGet(String)
step: passing result: passed
Then my scenario titles end up very useful # ScratchSteps.myScenarioTitlesEndUpVeryUseful()
Scenario Outline: A "failing" step is "skipped" # features/scratch.feature:10
When a "failing" step # ScratchSteps.aStep(String)
Then I get "skipped" # ScratchSteps.iGet(String)
step: failing result: skipped
Then my scenario titles end up very useful # ScratchSteps.myScenarioTitlesEndUpVeryUseful()
2 Scenarios (2 passed)
6 Steps (6 passed)
这篇关于如何获得标题中的黄瓜情景变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文