Search code examples
javacucumbercucumber-jvmcucumber-java

How to generate Cucumber Report using Main.run method?


I am using Cucumber for Java

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>6.1.1</version>
    </dependency>

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>6.1.1</version>
    </dependency>

I am not using Cucumber Options to configure the step or feature to use. I am using Main.run method

String feature = "/resources/service1/feature1.feature"
Main.run(new String[]{"--glue", "example.aop.testing.steps", feature}
            , Thread.currentThread().getContextClassLoader())

Everything it's working find but I would like to generate a report with the result. I was reading about it and to configura it I need to use Cucumber Options, like this:

@RunWith(Cucumber.class) 
@Cucumber.Options(format = {"pretty", "html:target/cucumber"}) 

public class runTest { }

How can I configure it using that approach??


Solution

  • You can use other options in the same array you are adding your glue and feature like below

     String[] commonOptions = {
                    "--glue",
                    "com.test.automation.stepdefinitions",
                    "--tags",
                    "@foo",                
                    "--plugin",
                    "pretty",
                    "--plugin",
                    "html:"+reportFolderPath+"/html",
                    "--plugin",
                    "json:"+reportFolderPath+"/cucumber.json",
                    FEATURE_FILE_PATH
            };