Search code examples
javaseleniumgetgauge

How do you get the current scenario and/or spec name when running selenium with gauge


I am working with gauge and trying to get the current spec and/or scenario name. Currently my code is structured similarly to the java-maven-selenium example that gauge has put up in github.

Thanks for the help!


Solution

  • You could use the BeforeScenario hook and ExecutionContext to get this information.

    An example:

    @BeforeScenario
    public void beforeScenario(ExecutionContext context){
        System.out.println("Current Spec: " + context.getCurrentSpecification().getName());
        System.out.println("Current Scenario: " + context.getCurrentScenario().getName());
    }