2

I am trying to run Cucumber runner class using Selenium Webdriver in AWS Lambda. So far I have been able to run selenium in the AWS handler function, but how do I call the Cucumber Runner from my handleRequest so I can run the tests in Lambda?

Here is Snippet of my code:

// following class is entry point for AWS, I need to call Cucumber runner from this function.
public class **LambdaFunctionHandler** implements RequestHandler<Object, String> {

    private AmazonS3 s3 = AmazonS3ClientBuilder.standard().build();

    @Override
    public String handleRequest(Object input, Context context) {        
        context.getLogger().log("Input: " + input);
        try {

            runner();  // how do I call my Cucumber Runner Class to execute my tests?

        catch (Exception e) {
            e.printStackTrace(System.out);
            context.getLogger().log(e.getMessage());
        }

        return "request done";
    }

The following is the runner class
package runner;

import cucumber.api.CucumberOptions;

import cucumber.api.junit.Cucumber;

import org.junit.runner.RunWith;

@RunWith(Cucumber.class)

@CucumberOptions(
        features = "src\\test\\resources\\features"
        ,glue={"com.smallcomp.abc.steps"}
        ,format = {"json:target/cucumber.json","html:target/cucumber-pretty"}
        ,dryRun = false
        ,tags = {"@smoke"}
)


public class runner {

}
Ray Prusia
  • 21
  • 4

1 Answers1

0

In the handleRequest method, you can use "io.cucumber.core.cli.Main.run" to execute cucumber test. See below:

 String[] args = {
    "-p","pretty",
    "-p","json:target/cucumber-reports/Cucumber.json",
    "-p", "html:target/cucumber-reports",
    "-m",
    "src/test/resources/APIFeatures/",
    "--glue",
    "org.yourorg.yourpackage.stepDefinitions",
    "--glue",
    "org.yourorg.yourpackage.hooks",
    "--tags",
    "@Test"
};
io.cucumber.core.cli.Main.run(args, Thread.currentThread().getContextClassLoader());