Passing feature file as a parameter while running tests with Maven and Cucumber JVM

2,107 views
Skip to first unread message

shivi malviya

unread,
Sep 11, 2013, 2:09:18 AM9/11/13
to cu...@googlegroups.com
Hi All,
Please help me how to pass features files as parameters while running my tests through Maven in command line .
I am using command :
mvn clean install -Dcucumber.options ="--glue classpath:features/featurefilename.feature

But it is running all the features files.

Kindly answer if anybody has used this.

Thanks in advance.
Shivi

aslak hellesoy

unread,
Sep 11, 2013, 2:30:15 AM9/11/13
to Cucumber Users
On Wed, Sep 11, 2013 at 7:09 AM, shivi malviya <malviy...@gmail.com> wrote:
Hi All,
Please help me how to pass features files as parameters while running my tests through Maven in command line .
I am using command :
mvn clean install -Dcucumber.options ="--glue classpath:features/featurefilename.feature


Try this:

mvn clean install -Dcucumber.options ="features/featurefilename.feature"

--glue is for telling cucumber where your stepdefs and hooks are.
Telling it where features are is done without an option.

Aslak

But it is running all the features files.

Kindly answer if anybody has used this.

Thanks in advance.
Shivi

--
-- Rules --
 
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
 
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
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

shivi malviya

unread,
Sep 11, 2013, 3:07:24 AM9/11/13
to cu...@googlegroups.com
Hi,

I tried using this but it is giving me initialization error, no such directory found. Do we need to define classpath anywhere to run this ?
Also, when we give only directory path like mvn clean install -Dcucumber.options ="directorypath/featurefilename.
feature" then it provides all definitions present in feature files.


Thanks,
Shivi

aslak hellesoy

unread,
Sep 11, 2013, 3:44:44 AM9/11/13
to Cucumber Users
Shivi,

Please read the list rules at the bottom of the email, especially rule 2.


On Wed, Sep 11, 2013 at 8:07 AM, shivi malviya <malviy...@gmail.com> wrote:
Hi,

I tried using this but it is giving me initialization error, no such directory found.
Do we need to define classpath anywhere to run this ? 
Also, when we give only directory path like mvn clean install -Dcucumber.options ="directorypath/featurefilename.
feature" then it provides all definitions present in feature files.


You can tell cucumber to load feature files in two ways:

a) Relative to your current directory:
    mvn clean install -Dcucumber.options ="path/to/your/features/featurefilename.feature"

b) From the classpath:
    mvn clean install -Dcucumber.options ="classpath:features/featurefilename.feature"

The same applies to glue code.

Makes sense?

Aslak

aslak hellesoy

unread,
Sep 11, 2013, 6:38:57 AM9/11/13
to Cucumber Users
Shivi, please do not email me privately - keep the discussion on the mailing list. I brought it back there. 

On Wed, Sep 11, 2013 at 10:04 AM, shivi malviya <malviy...@gmail.com> wrote:
Hi,

Thanks for letting me know the options to try this out.
As per the options, please find my findings :


You can tell cucumber to load feature files in two ways:

a) Relative to your current directory:
    mvn clean install -Dcucumber.options ="path/to/your/features/featurefilename.feature"
[Shivi ] : Tests are not run, I am asked to implement the steps of the feature file which I have already done.(though it runs when I run with only mvn clean install)

b) From the classpath:
    mvn clean install -Dcucumber.options ="classpath:features/featurefilename.feature"
[Shivi] : With this, I am still facing Initialization error. Where should I define classpath value in my code?


The JVM classpath is defined by maven, based on your pom.
 
Please suggest.


I have tried to answer your questions by updating the README in the java-helloworld example:

Hope that helps.

Aslak
 
Thanks,
Shivi

Roberto Lo Giacco

unread,
Sep 11, 2013, 9:54:10 AM9/11/13
to cu...@googlegroups.com
You can find a quite comprehensive setup project on https://bitbucket.org/rlogiacco/atdd/wiki/Home, it includes:

# Maven
# Custom feature selection by file/tag
# Jacoco code coverage
# Web application testing through Selenium WebDriver
# Container deployment (Tomcat by default)
# Continuos integration profile

I created it as my own personal template project so you will have to modify some parameters, but should provide you enough information to avoid some hassle.
 

Thanks in advance.
Shivi

shivi malviya

unread,
Sep 13, 2013, 2:59:54 AM9/13/13
to cu...@googlegroups.com
Hi,

Thanks for the README. I updated my cucumber versions and now it works fine.
I still wonder can we pass multiple feature files as parameters with :
mvn test -Dcucumber.options="classpath:featurename.feature"

Thanks,
Shivi

aslak hellesoy

unread,
Sep 13, 2013, 3:29:32 AM9/13/13
to Cucumber Users
On Fri, Sep 13, 2013 at 7:59 AM, shivi malviya <malviy...@gmail.com> wrote:
Hi,

Thanks for the README. I updated my cucumber versions and now it works fine.
I still wonder can we pass multiple feature files as parameters with :
mvn test -Dcucumber.options="classpath:featurename.feature"


Sure:

    mvn test -Dcucumber.options="classpath:featurename.feature classpath:otherfeaturename.feature"

You can also specify a directory on the classpath

    mvn test -Dcucumber.options="classpath:somedir"

Aslak

shivi malviya

unread,
Sep 13, 2013, 8:08:34 AM9/13/13
to cu...@googlegroups.com
Hi Roberto,
I looked into the framework provided by you. I have a query how can we handle multiple stepdefinition files in this case and what about the methods @Before and @After tests, where they will be defined, in each stepdef file?
Also, how would I manage stepdefinitions which are used in more than one feature file?

Thanks,
Shivi


--

Roberto Lo Giacco

unread,
Sep 13, 2013, 9:06:47 AM9/13/13
to cu...@googlegroups.com


Il giorno venerdì 13 settembre 2013, shivi malviya ha scritto:
Hi Roberto,
I looked into the framework provided by you. I have a query how can we handle multiple stepdefinition files in this case and what about the methods @Before and @After tests, where they will be defined, in each stepdef file?

You can define such methods in whichever class you like, I usually define a specific class (Environment or Hooks) where I place those methods. Remember such annotated methods are valid for each and every feature run, no matter what class is bound to the steps. If you want to include/exclude @Before/@After you have to manipulate the glue option.
 
Also, how would I manage stepdefinitions which are used in more than one feature file?

There is no relationship between Java file and feature file other than the regexp annotation mapping: if you write a feature containing a step then cucumber-jvm will scan all the classes contained in the glue code and executes the matching one (multiple matches are treated as an error).

In other words what you have downloaded and looked at is not a replacement for cucumber-jvm, it is a template project using cucumber-jvm and providing a usage example that includes those elements that I find most useful in conjunction with cucumber-jvm, like WebDriver and Jacoco.

You can use it as it is or strip it down to match your needs: if you don't have a web app then you are probably not really interested to it at all.
 
You received this message because you are subscribed to a topic in the Google Groups "Cukes" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cukes/-sltUaDmYtY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cukes+un...@googlegroups.com.

aslak hellesoy

unread,
Sep 13, 2013, 9:27:43 AM9/13/13
to Cucumber Users
On Fri, Sep 13, 2013 at 2:06 PM, Roberto Lo Giacco <rlog...@gmail.com> wrote:


Il giorno venerdì 13 settembre 2013, shivi malviya ha scritto:

Hi Roberto,
I looked into the framework provided by you. I have a query how can we handle multiple stepdefinition files in this case and what about the methods @Before and @After tests, where they will be defined, in each stepdef file?

You can define such methods in whichever class you like, I usually define a specific class (Environment or Hooks) where I place those methods. Remember such annotated methods are valid for each and every feature run, no matter what class is bound to the steps. If you want to include/exclude @Before/@After you have to manipulate the glue option.
 

 
Also, how would I manage stepdefinitions which are used in more than one feature file?

There is no relationship between Java file and feature file other than the regexp annotation mapping: if you write a feature containing a step then cucumber-jvm will scan all the classes contained in the glue code and executes the matching one (multiple matches are treated as an error).


Yes, Step Definitions are global. They are not tied to a particular Feature.

Roberto Lo Giacco

unread,
Sep 13, 2013, 9:52:58 AM9/13/13
to cu...@googlegroups.com


Il giorno venerdì 13 settembre 2013, aslak hellesoy ha scritto:



On Fri, Sep 13, 2013 at 2:06 PM, Roberto Lo Giacco <rlog...@gmail.com> wrote:


Il giorno venerdì 13 settembre 2013, shivi malviya ha scritto:

Hi Roberto,
I looked into the framework provided by you. I have a query how can we handle multiple stepdefinition files in this case and what about the methods @Before and @After tests, where they will be defined, in each stepdef file?

You can define such methods in whichever class you like, I usually define a specific class (Environment or Hooks) where I place those methods. Remember such annotated methods are valid for each and every feature run, no matter what class is bound to the steps. If you want to include/exclude @Before/@After you have to manipulate the glue option.
 


Wasn't aware of this feature, anyway, as you state in the doc itself, Before/After hooks should be used carefully: use them only to encode those developers tricks you want to completely hide from your business partners as they are completely opaque!

Every time you use those hooks you are somehow betraying cucumber goal and benefit over other testing frameworks: provide a clear, non technical, human readable test suite.
Reply all
Reply to author
Forward
0 new messages