Skip to content

Support programmatically skipped scenarios (e.g if a scenario has a dependency failure) #691

Closed

Description

@serhatozdursun

I am working on an API product. Some endpoints are associated with 3rd party endpoints. Sometimes we may receive an error that does not belong to our product. In this case, I should be able to bypass this scenario without failing the whole feature.

If there was a feature which allow me skip the scenario with certain case , it would be awesome. It could be static method like Gauge.skip("skip reason");

Activity

  1. changed the title [-]I need a feature that skip the scenario, if the scenario have failure[/-] [+]Support programmatically skipped scenarios (e.g if a scenario has a dependency failure)[/+] on Oct 14, 2024
  2. chadlwilson commented on Oct 14, 2024

    @chadlwilson
    Contributor

    This is possible to be implemented now with the support for getgauge/gauge#2502 , modeled off gauge-dotnet or gauge-python. Help welcome :-)

  3. serhatozdursun commented on Oct 14, 2024

    @serhatozdursun
    ContributorAuthor

    I'll have a look at the first availble time.

  4. chadlwilson commented on Oct 14, 2024

    @chadlwilson
    Contributor

    See getgauge/gauge-python#397 and getgauge/gauge-python#390 for some discussion of how to implement it.

    Although more similar to Java the gauge-dotnet one is a bit harder to unpack as an example as the logic is spread into a shared library which other plugins don't have.

    Basic steps for consistency

    • create a SkipScenarioException type available to users to throw in the plugins API which includes a reason/message for the skip.
    • emit the message back to Gauge.
    • catch these exceptions during step execution and hooks.
    • instead of failing the scenario set the step to passed and set executionResult.skipScenario flag to true (it should default to false)
  5. serhatozdursun commented on May 11, 2025

    @serhatozdursun
    ContributorAuthor

    👋 Hi @chadlwilson ,

    I’ve implemented a feature to allow skipping scenarios programmatically using:

    Gauge.skip("reason for skipping");

    🔧 What I’ve added:

    1. New Exception Type:
      SkipScenarioException
    2. New API Method in Gauge.java:
    public static void skip(String reason) {
        throw new SkipScenarioException(reason);
    }
    1. In MethodExecutor.java:
    • Unwrapped Throwable.getCause() to check for SkipScenarioException
    • Introduced the following method:
    private Spec.ProtoExecutionResult createSkipExecResult(long execTime, SkipScenarioException e) {
        return Spec.ProtoExecutionResult.newBuilder()
            .setSkipScenario(true)
            .addMessage("SKIPPED: " + e.getMessage())
            .setRecoverableError(false)
            .setExecutionTime(execTime)
            .build();
    }
    1. In AbstractExecutionStage.java:
      Updated merging logic:
    boolean skip = execResult.getSkipScenario() | previousStageResult.getSkipScenario();
    builder.setSkipScenario(skip);

    ⚠ Problem:

    Although SkipScenarioException is caught and a proper ProtoExecutionResult with skipScenario = true is returned, the scenario continues executing, and the final report still shows 0 skipped scenarios.

    This makes it behave more like a silent "pass" than a proper skip.

    I believe this behavior may need to be handled in the Gauge core engine (gauge/gauge) or via changes in the message definitions (Messages.proto) so that:

    Execution is halted after skip

    The skipped scenario is counted correctly in the report

    It reflects accurately in CLI output and HTML reports

    🙋 Request:

    Could you please advise where to hook into the core behavior to support early exit on skipScenario = true?

    Do we need corresponding changes in the Gauge engine or the message handling layer?

  6. chadlwilson commented on May 11, 2025

    @chadlwilson
    Contributor

    I don't follow what you're saying about a silent pass, sorry. You might want to review the behaviour with the other language plugins already implementing this noted above and see if yours is different. Or may need to be more explicit with an example.

    The HTML report not noting the scenario as skipped is a separate issue at getgauge/html-report#320 however different than core behavior.

    I thought it reflected accurately in CLI output though? Are you sure this is also affected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions