Running Cucumber-JVM from a command line

4,797 views
Skip to first unread message

Alex

unread,
May 15, 2012, 9:50:30 PM5/15/12
to Cukes
I am having trouble to run cucumber-jvm from a command line. The
command is executed from a directory containing cucumber JAR files.
Having said that, I have no problem running Cucumber-JVM from IntelliJ
by running the test class (RunCukesTest) annotated with
@RunWith(Cucumber.class).

The command is as follows:
java -classpath gherkin-2.9.3.jar:cucumber-junit-1.0.6.jar:cucumber-
java-1.0.6.jar:cucumber-core-1.0.6.jar: cucumber.cli.Main --glue ~/
application/out/test/Acceptance/com/gap/scms/mp/acceptance ~/
application/out/test/Acceptance/com/gap/scms/mp/acceptance/
invoiceresource.feature

The directory "~/application/out/test/Acceptance/com/gap/scms/mp/
acceptance/" contains the following files (everything in one
directory):
InvoiceResourceStepdefs.class
RunCukesTest.class
invoiceresource.feature

The following is the contents of invoiceresource.feature:
https://gist.github.com/2706621

The following is the contents of RunCukesTest class:
https://gist.github.com/2706631

The following is the contents of InvoiceResourceStepdefs class:
https://gist.github.com/2706638

The response that I get is as follows (I see the auto-generated
stepdefs message):
https://gist.github.com/2706587

From what I see, the cucumber-jvm cannot locate the
InvoiceResourceStepdefs class. Can you please advise where I am going
wrong? Thank you

Alex

aslak hellesoy

unread,
May 16, 2012, 2:35:50 AM5/16/12
to cu...@googlegroups.com
On Wed, May 16, 2012 at 2:50 AM, Alex <azagn...@gmail.com> wrote:
> I am having trouble to run cucumber-jvm from a command line. The
> command is executed from a directory containing cucumber JAR files.
> Having said that, I have no problem running Cucumber-JVM from IntelliJ
> by running the test class (RunCukesTest) annotated with
> @RunWith(Cucumber.class).
>
> The command is as follows:
> java -classpath gherkin-2.9.3.jar:cucumber-junit-1.0.6.jar:cucumber-
> java-1.0.6.jar:cucumber-core-1.0.6.jar: cucumber.cli.Main --glue ~/
> application/out/test/Acceptance/com/gap/scms/mp/acceptance ~/
> application/out/test/Acceptance/com/gap/scms/mp/acceptance/
> invoiceresource.feature
>
> The directory "~/application/out/test/Acceptance/com/gap/scms/mp/
> acceptance/" contains the following files (everything in one
> directory):
> InvoiceResourceStepdefs.class
> RunCukesTest.class
> invoiceresource.feature
>
> The following is the contents of invoiceresource.feature:
> https://gist.github.com/2706621
>
> The following is the contents of RunCukesTest class:
> https://gist.github.com/2706631
>
> The following is the contents of InvoiceResourceStepdefs class:
> https://gist.github.com/2706638
>

This class needs to be in a package. You placed it in the top-level
package (no package).
It also shouldn't extend from ResourceTest. In fact it shouldn't
extend anything. See recent discussions about inheritance.

> The response that I get is as follows (I see the auto-generated
> stepdefs message):
> https://gist.github.com/2706587
>
> From what I see, the cucumber-jvm cannot locate the
> InvoiceResourceStepdefs class. Can you please advise where I am going
> wrong?

The java backend expects the --glue argument to be either a package
name or a classpath path (not a file system path). So after you have
moved your InvoiceResourceStepdefs class to a package, for example
com.yammer.dropwizard.testing, cucumber will pick it up with:

--glue com.yammer.dropwizard.testing

Or alternatively

--glue classpath:com/yammer/dropwizard/testing

Other backends, such as the jruby backend would be happy to use a file
system path. Different backends want different ways to specify a glue
location.

If you look at the history
(https://github.com/cucumber/cucumber-jvm/blob/master/History.md)
you'll see that 1.0.2 introduced "Don't convert paths to package names
- instead throw an exception. This helps people avoid mistakes." If
you had been on 1.0.2 you would have received an exception!

However, this introduced another problem:
https://github.com/cucumber/cucumber-jvm/issues/299 so you'll no
longer get this warning if you pass a file system path.

I'll try to come up with a way for cucumber to detect bad glue while
avoiding #299 to break again.

HTH,
Aslak

> Thank you
>
> Alex
>
> -- There are two rules:
>
> 1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows people to filter messages.
> 2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
>
> You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en

Alex

unread,
May 16, 2012, 7:03:53 PM5/16/12
to Cukes
Hi Aslak,

Thank you for the pointers. I got it working now. My stepdefs class
now not extending anything as per your pointer,
but uses class that extends ResourceTest.

My command now looks as follows (I am running it from my project libs
dir):

java -classpath *:[system_path_to_compiled_classes]:
[system_path_to_compiled_test_classes] cucumber.cli.Main \
--glue [package_name] classpath:[system_path_to_features] --tags
[some_tag_name_starting_with_@]

Thank you for your help and the quick feedback.

Alex

On May 15, 11:35 pm, aslak hellesoy <aslak.helle...@gmail.com> wrote:
> However, this introduced another problem:https://github.com/cucumber/cucumber-jvm/issues/299so you'll no
> longer get this warning if you pass a file system path.
>
> I'll try to come up with a way for cucumber to detect bad glue while
> avoiding #299 to break again.
>
> HTH,
> Aslak
>
>
>
>
>
>
>
> > Thank you
>
> > Alex
>
> > -- There are two rules:
>
> > 1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows people to filter messages.
> > 2) Please use interleaved answershttp://en.wikipedia.org/wiki/Posting_style#Interleaved_style

walenchie9ja

unread,
May 28, 2016, 11:00:36 PM5/28/16
to Cukes
Hi Alex, I have the issue of not able to run Cucumber jvm from command line and this has been causing me sleepless night.
Can you please help with the right format/order to run from command line?

So here is how i have tried:

C:\>java -classpath "location of jars" "location of cucumberRunner class that has main"
cucumber.api.cli.Main --glue "package of stepdefinition" "feature file location"

but i am having error that cucumberRunner class can't be found or loaded.

Please Help
Sheriff

George Dinwiddie

unread,
May 29, 2016, 10:33:33 AM5/29/16
to cu...@googlegroups.com
Sheriff,

On 5/28/16 10:43 PM, walenchie9ja wrote:
> Hi Alex, I have the issue of not able to run Cucumber jvm from command
> line and this has been causing me sleepless night.
> Can you please help with the right format/order to run from command line?
>
> So here is how i have tried:
>
> C:\>java -classpath "location of jars" "location of cucumberRunner class
> that has main"
> cucumber.api.cli.Main --glue "package of stepdefinition" "feature file
> location"
>
> but i am having error that cucumberRunner class can't be found or loaded.

Java needs the list of jars (or location of directory tree of classes). Try

java -classpath "list of jars" cucumber.api.cli.Main --glue "package
of stepdefinition" "feature file location"

The "list of jars" should be separated by semicolons.

Alternatively, you can set the CLASSPATH environment variable so you
don't have to specify all your jars every time you run it. See
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html
for details on both.

- George

--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------

Justin Radcliffe

unread,
May 31, 2016, 9:37:18 AM5/31/16
to Cukes
In Eclipse I creates a maven project that is building my JARs will all the dependacys. So I have that plug the lib folder in the project on my classpath.

Automation_Framework - is my eclipse java project.
com.justin.testcases has more package levels with other cucumber test files. Just using tags to know which one to use. Let me know if you need more details.

C:\ALM\Automation_Framework>java -cp lib\*;target\62100_Automation-0.0.1-SNAPSHOT-jar-with-dependencies.jar cucumber.api.cli.Main --glue com.justin.testcases C:\ALM\Automation_Framework\src\test\resources\com\justin\testcases\testsuite\gccx --tags @hfc --plugin pretty

Sneha Kalgutkar

unread,
Aug 19, 2018, 7:28:13 AM8/19/18
to Cukes
Hi Aslak,

I have a framework which uses Spring alongwith Cucumber and Maven with selenium as well. I tried all of the options to execute my jar, but it failes with a null pointer exception at a line where i am trying to load properties file with @Autowire annotation of Spring and use it. The files are getting loaded at run time, i verified it in logs but the Environment(of org.springframework.core.env.Environment) is not getting initialised. 

The proejct executes perfectly fine with mvn test, mvn package, but the execution via jar fails.

Any help/ pointers in this will be of great help.
Reply all
Reply to author
Forward
0 new messages