I need to run selenium-cucumber (Junit) project from command prompt.

I tried using the statement in command prompt:

java -cp E:\Workspace2\AP\Jars\*;E:\Workspace2\AP\src\stepDefinition\ cucumber.api.cli.Main --glue E:\Workspace2\AP\src\cucumberTest\ E:\Workspace2\AP\Feature\LogIn_Test.feature

but it is showing me following output: enter image description here

And My eclipse folder structure is as follows:

enter image description here


enter image description here

Test_steps.java file:

enter image description here

TestRunner.java file:

enter image description here

I referred this:


but nothing works. My code didin't ran.

Can anyone guide me to resolve it?

3 Answers 3


Well at last the Issue is been resolved.

All I have did is in eclipse, just renaming the file "TestRunner" to "TestRunnerTest".

Command Line:

java -cp "E:\Workspace2\AP\Jars\*;E:\Workspace2\AP\bin" cucumber.api.cli.Main --glue stepDefinition E:\Workspace2\AP\Feature\LogIn_Test.feature

Thanks to Koen Prins answer, Reference here: https://groups.google.com/forum/#!topic/cukes/vE_85FW0zks

Also one can refer: https://www.youtube.com/watch?v=Z8gm4hFsivI

  • Well According to the reference link provided "Depending on your JUnit setup, the default is that JUnit will run only those classes which end in *Test.java"
    – Sandeep
    Dec 19, 2017 at 8:51

The steps look good so perhaps it is not finding / using the step definition file.

Maybe the part from the instructions about:

"Your feature files can be added to the end of the command line:

$ java -cp "/Users/jreijn/.m2/repository/info/cukes/cucumber-core/1.2.5/cucumber-core-1.2.5.jar:/Users/jreijn/.m2/repository/info/cukes/gherkin/2.12.2/gherkin-2.12.2.jar:/Users/jreijn/.m2/repository/info/cukes/cucumber-java/1.2.5/cucumber-java-1.2.5.jar:/Users/jreijn/.m2/repository/info/cukes/cucumber-jvm-deps/1.0.5/cucumber-jvm-deps-1.0.5.jar" cucumber.api.cli.Main Developer/sources/github/cucumber-jvm-extentreport/src/test/resources/cucumber/feature_one.feature

This will probably result in the following message:

3 Scenarios (3 undefined)
6 Steps (6 undefined)
You can implement missing steps with the snippets below:

This means it can’t find the step definitions, hooks, etc that correspond to your feature file.

Let’s add the glue code required for running the tests. In the below example I’ll use my maven projects target directory, which contains my step definitions in the test-classes directory. You can do that by adding the directory to your classpath, and with the argument --glue com.sitture.definitions, provide the Java package that contains step definition Java classes.

$ java -cp "/Users/jreijn/.m2/repository/info/cukes/cucumber-core/1.2.5/cucumber-core-1.2.5.jar:/Users/jreijn/.m2/repository/info/cukes/gherkin/2.12.2/gherkin-2.12.2.jar:/Users/jreijn/.m2/repository/info/cukes/cucumber-java/1.2.5/cucumber-java-1.2.5.jar:/Users/jreijn/.m2/repository/info/cukes/cucumber-jvm-deps/1.0.5/cucumber-jvm-deps-1.0.5.jar:/Users/jreijn/Developer/sources/github/cucumber-jvm-extentreport/target/test-classes/" cucumber.api.cli.Main --glue com.sitture.definitions Developer/sources/github/cucumber-jvm-extentreport/src/test/resources/cucumber/feature_one.feature

The other part that caught my eye was all steps throwing stuff but I don't know java

  • 1
    --glue is already added in my command line followed by feature file. But still the command line is not fetching the step definition file.
    – Sandeep
    Dec 16, 2017 at 17:11
  • What about your classpath, did you update that ? Dec 16, 2017 at 17:19
  • Yes, tried with that too but did not helped. Do we need to provide Testrunner class anywhere.
    – Sandeep
    Dec 16, 2017 at 17:25
  • So you added it per docs.oracle.com/javase/tutorial/essential/environment/… ? Dec 16, 2017 at 17:27
  • Kindly check again my code: E:\Workspace2\AP> java -cp E:\Workspace2\AP\Jars\*;E:\Workspace2\AP\src\stepDefinition\ cucumber.api.cli.Main --glue E:\Workspace2\AP\bin\stepDefinition\ E:\Workspace2\AP\Feature\LogIn_Test.feature
    – Sandeep
    Dec 16, 2017 at 17:42

The --glue should point to the java package in which your glue code resides.

Which in your case, based on the above screenshots, should be “--glue stepDefinition”

One other important aspect is that you will need to add the compiled output of the stepdefinitions to your classpath, which in you case should be the full path to the ‘bin’ directory, but you should leave the ‘stepDefinition’ part off.

So try with

E:\Workspace2\AP>java -cp "E:\Workspace2\AP\Jars\*;E:\Workspace2\AP\bin" cucumber.api.cli.Main --glue stepDefinition E:\Workspace2\AP\Feature\LogIn_Test.feature

Note the quotes around the classpath values.

  • This code is giving me: Error: Could not find or load main class cucumber.api.cli.Main
    – Sandeep
    Dec 18, 2017 at 17:54
  • What if you try this without the quotes? I'm not sure if this is needed on windows and be sure to check out that they are regular quotes. I've modified my post, since it seems my phone added non default quotes.
    – Jeroen
    Dec 18, 2017 at 19:42
  • Without quotes it will show the output which is mentioned in the question but with quotes it will display Error: Could not find or load main class cucumber.api.cli.Main
    – Sandeep
    Dec 18, 2017 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.