问题
In my Cucumber Scenario Outline, some of the examples in my examples table are passing, and some are failing.
I am trying to add tags to these, so I can run those which pass, & skip those which are failing currently.
I have tried to copy some examples I've found online, but I am getting an error.
Below is my latest attempt:
Scenario Outline: BR001 test
Given...
When...
Then...
@passing
Examples:
| errorCode |
| BRS002 |
| BRS003 |
| BRS004 |
| BRS005 |
| BRS008 |
| BRS010 |
| DE19716 |
| BRS006 |
| BRS009 |
@failing
Examples:
| errorCode |
| DE19716 |
| BRS006 |
| BRS009 |
But, there is an error with @passing. Here is the error message appearing:
mismatched input '@passing' expecting 'Examples:'
I've copied an online example, so I don't know why this is throwing an error?
回答1:
Maybe you should check again your dependencies.
assume following structure
src/test/java/features/userdata.feature
src/test/java/glue/StepPojo.java
src/test/java/myRunner/TestRunner.java
pom.xml
pom.xml dependendencies
<properties>
<version.cucumber>3.0.2</version.cucumber>
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
</dependencies>
userdate.feature - amended the Scenario Outline for the example
Scenario Outline: BR001 test Given something When happen Then result ""
... your both tagged 'Examples:' sections
StepPojo.java
package glue;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class StepPojo {
@Given("^something$")
public void something() throws Throwable {
System.out.println("something");
}
@When("^happen$")
public void happen() throws Throwable {
System.out.println("happen");
}
@Then("^result$")
public void result() throws Throwable {
System.out.println("result");
}
@Then("^result \"([^\"]*)\"$")
public void result(String errorCode) throws Throwable {
System.out.println("result = " + errorCode);
}
}
TestRunner.java
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/java/features/userdata.feature",
glue = {"glue"},
tags = {"@failing"}
)
public class TestRunner {
}
output of mvn test
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running myRunner.TestRunner
something
happen
result = DE19716
something
happen
result = BRS006
something
happen
result = BRS009
3 Scenarios (3 passed)
9 Steps (9 passed)
来源:https://stackoverflow.com/questions/51041171/cucumber-tagging-with-multiple-examples-tables-in-a-scenario-outline