'How to pass "plugin" parameters during runtime to @CucumberOptions

Objective: Our projects uses Cucumber+Java+Slenium+Junit-Maven module on Eclipse to perform UI automation. After the entire test runs, an automatic mail will be trigger with the status report.

Goals: Cucumber Extents reports to be saved in a temporary location from where the sendReport(path) method will fetch the report and send over mail. I need to pass the temporary folder's location into @CucumberOptions(plugin= ""), so that the report is created in that location.

Problems/Issues: Unable to set the temporary folder's location into the @CucumberOptions

Please review the below code and any help is appreciated. Thanks.

@RunWith(Cucumber.class)
@CucumberOptions(
    format = { "html:target/cucumber-report", "json:target/uiauto-report/1.json" },
    features = "features/icg-uiauto-test-features",
    glue = "uiauto/common/glue",
    tags = {"@uiauto-status-report"}, 
    plugin = { "com.vimalselvam.cucumber.listener.ExtentCucumberFormatter:UIAUTO-Report/uiauto-status-report.html"}
)
public class UiAutoTest {

public RunWebapiTest() {}    

@Rule
public static TemporaryFolder folder = new TemporaryFolder();
private static String reportPath;


@BeforeClass
public static void tempFolder() throws IOException, IllegalStateException {
     TemporaryFolder folder = new TemporaryFolder();
     
     log.info("Creating test folder...");
     folder.create();
     File createdFolder= folder.newFolder("UITestReport");
     
   if (createdFolder.exists()) {
    log.info("Test Folder Created...");
    File testFile = folder.newFile(uiautotest); 
    testFile.createNewFile();
    reportPath = testFile.getAbsolutePath();
    
    log.info(uiautotest+"'s path : "+reportPath);
   } else {
    log.info("Folder unavailable.");
   }      
}

 @AfterClass
public static void prepareExtentReport() {      
     
    try {
        Reporter.loadXMLConfig(new File("src/main/resources/extent-config.xml"));
        Reporter.getExtentHtmlReport();
        log.info("Report preparation completed!");
        SendSanityReport.sendReport(reportPath);    // Sends report over mail
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}



Solution 1:[1]

You can create an additional step in your pipeline to trigger a maven command and pass in your options:

mvn test -Dcucumber.options="--plugin classpath:your path"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 procrastinator