简体   繁体   中英

How can I run Cucumber Test runner from CLI without using Maven

I have seen the posts -

How to run cucumber file from command line

Cucumber java project without maven - how to run from command prompt if i am having Runner class

But the solutions given there are not very clear.

My CucumberRunner.java looks like -

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/resources/features",
        tags="@Regression",
        monochrome = false,
        plugin = {"pretty",
                "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:",
                "timeline:test-output-thread/",
                "json:target/cucumber-reports/jsonReports/Cucumber.json",
                "html:target/cucumber-reports/Cucumber.html"}
      
)


public class CucumberRunner {

   
}

Unfortunately because of security reasons I can not install maven on Linux machine. So I want to run this CucumberRunner file from CLI.

As suggested in the previous posts I tried below in my Cucumber class

public class CucumberRunner {

    public static void main(String[] args){
        Main.main(new String[]{"-g", "src/test/java/stepdefinitions", "src/test/resources/features/Validate.feature"});
    }

}

But it gives me exception

Exception in thread "main" java.lang.NoClassDefFoundError: io/cucumber/core/cli/Main
        at CucumberRunner.main(CucumberRunner.java:29)                              
Caused by: java.lang.ClassNotFoundException: io.cucumber.core.cli.Main              
        at java.net.URLClassLoader.findClass(URLClassLoader.java:387)               
        at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
        ... 1 more

But This also doesn't give any solution to run on the basis of Cucumber tags.

Any solution or pointer is appreciated.

Kind Regards,

Abhi

In order to run a Java application, you need to be able to resolve ALL dependencies at runtime. This means that, every single library referenced on the POM under the dependencies tag, must be somewhere in the machine where Selenium (Cucumber) is running. Likewise, if those libraries have dependencies of their own, you must also download them somewhere in the machine.

You have a few choices to access the dependent libraries. You need to reference all dependencies as external JARs (reside outside your application JAR) or you need to package them inside your application JAR. You can use a build tool like ANT to build your JAR and map your dependencies similar to how is done in Maven. Obviously the difference is that you need to do what I described before (your build tool will need to know where these JARs are physically located).

To execute, you will obviously need a main method. Because this is using Selenium (Cucumber), your Runner class is ran by JUnit or TestNG (depending on what you are using). After that, the rest is up to you. For example, you could simply create a batch file to launch your application, or you could use a tool like Launch4J to create an executable. Of course, the latter required creating an executable JAR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM