0

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?

  • Which version of cucumber are you using? Which online example have you followed? – Marit Jun 26 '18 at 11:04
  • 2
    Sidenote: the easiest way for me to skip failing ones is to just comment them out. Not proper usage, but will work in a pinch. – Marit Jun 26 '18 at 11:05
  • Where is this '@test1' annotation mentioned in the feature file? – Grasshopper Jun 26 '18 at 11:09
  • @Marit My version of cucumber in build.gradle is 3.0.2. This is the example I've been following: https://github.com/cucumber/cucumber-js/issues/305. Also, I've been commenting them out also, but I've been asked to implement this tagging now, rather than commenting them out –  Jun 26 '18 at 11:14
  • @Grasshopper Apologies, that was a typo. It actually references **@passing** –  Jun 26 '18 at 11:14
  • @user9847788 What is the cucumber version? – Grasshopper Jun 26 '18 at 11:18
  • @Grasshopper 3.0.2 –  Jun 26 '18 at 11:20
  • 1
    @user9847788 This technique works on 3.0.2. Just tried it to confirm. You can look at this post similar to this. Maybe this helps. -> https://stackoverflow.com/questions/40131538/execute-only-specific-examples-in-a-scenario-outline/40131705#40131705 – Grasshopper Jun 26 '18 at 11:29
  • @user9847788 Why are the columns of the two tables different? – Grasshopper Jun 26 '18 at 11:29
  • @Grasshopper I've looked at that question you posted. It matches mine, but the error message mentioned in my question is still appearing. Also, I've fixed the column names in my code, they should match –  Jun 26 '18 at 12:56
  • @user9847788 I copied the scenario in the question and it works perfectly. Added dummy steps for given etc. Maybe ur IDE is adding some extraneous characters. Try writing this in a notepad instead of IDE. – Grasshopper Jun 26 '18 at 13:33
  • @Grasshopper It's also not allowing me to add 2 examples tables to a scenario outline. When I add the second Examples table, the second `Examples:` header is underlined, and te error message is **Missing EOF at Examples:** –  Jun 26 '18 at 13:59
  • Which IDE are u using? Anyways errors in feature file highlighted by IDE does not matter. Just ignore them... – Grasshopper Jun 26 '18 at 14:27
  • @Grasshopper Eclipse –  Jun 26 '18 at 14:27
  • Works for me on eclipse – Grasshopper Jun 26 '18 at 16:11

1 Answers1

0

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)
SubOptimal
  • 22,518
  • 3
  • 53
  • 69