Skip to content

Cannot dynamically skip scenario during BeforeScenario hook #926

@cedric-crouzet-penbase

Description

@cedric-crouzet-penbase

Describe the bug
Throwing SkipScenarioException in @BeforeScenario hook doesn't mark the scenario as skipped as expected.

To Reproduce
My goal is to use a custom skip tag to explicitly skip a scenario from a suite.

Here is a minimal example.

Using this implementation:

public class GaugeConfig {

    @BeforeScenario(tags = "skip")
    public void skipScenario() {
        System.out.println("skip " + context.getCurrentScenario().getName() + "...");
        throw new SkipScenarioException("Tagged to skip");
    }

    @Step("Print <message>")
    public void print(String message) {
        System.out.println("running " + message);
    }

}

And this spec:

# My spec

## Scenario 1
* Print "scenario 1"

## Scanario 2
Tags: skip
* Print "scenario 2"

Extract of pom.xml

    <dependencies>
        <dependency>
            <groupId>com.thoughtworks.gauge</groupId>
            <artifactId>gauge-java</artifactId>
            <version>0.12.0</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>2.0.17</version>
        </dependency>
    </dependencies>

Logs

C:\Gauge\bin\gauge.exe run --machine-readable --hide-suggestion --simple-console C:/test-gauge-java/specs/MySpec.spec
Testing started at 14:04 ...
[pool-1-thread-1] INFO org.reflections.Reflections - Reflections took 106 ms to scan 1 urls, producing 2 keys and 2 values
[pool-2-thread-1] INFO org.reflections.Reflections - Reflections took 3 ms to scan 1 urls, producing 0 keys and 0 values
running scenario 1
skip Scanario 2...
running scenario 2
Successfully generated html-report to => C:\test-gauge-java\reports\html-report\index.html

Specifications:	1 executed	1 passed	0 failed	0 skipped
Scenarios:	2 executed	2 passed	0 failed	0 skipped

Total time taken: 217ms

Process finished with exit code 0

Expected behavior
In my example the scenario 2 should be marked as skipped and not executed.

Versions:

  • Java 21
gauge -v

Gauge version: 1.6.18
Commit Hash: d6e10a4

Plugins
-------
flash (0.0.2)
html-report (4.3.3)
java (0.12.0)
json-report (0.5.0)
screenshot (0.3.2)
spectacle (0.2.1)
xml-report (0.5.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions