How to glue step definitions from a .jar file

3,208 views
Skip to first unread message

Van

unread,
Sep 29, 2015, 5:36:45 PM9/29/15
to Cukes

Hello!


How can we glue step definition from a .jar file? 


For example, i have couple of projects with different feature files. Most of the step definitions are common. Can i keep these step definitions in a .jar file and pass the package name to cucumber "--glue" option?  I tried doing it but it says steps are undefined. Is there anyway to use these step definitions as a common library? so that i do not have to maintain the same code in different projects?

BTW - I am running them as a Maven command.


Appreciate your help! Please feel free to bug me for more details.


Thanks,
V

Paolo Ambrosio

unread,
Sep 30, 2015, 2:23:10 AM9/30/15
to cu...@googlegroups.com
On Tue, Sep 29, 2015 at 10:31 PM, Van <pavan...@gmail.com> wrote:

> Hello!
>
>
> How can we glue step definition from a .jar file?
>
>
> For example, i have couple of projects with different feature files. Most of
> the step definitions are common. Can i keep these step definitions in a .jar
> file and pass the package name to cucumber "--glue" option? I tried doing
> it but it says steps are undefined. Is there anyway to use these step
> definitions as a common library? so that i do not have to maintain the same
> code in different projects?
>
> BTW - I am running them as a Maven command.

Did you try adding the JAR as a dependency and specifying the
classpath (not the jar) in the glue command? Can you paste the pom.xml
snippet you are using?

> Appreciate your help! Please feel free to bug me for more details.
>
>
> Thanks,
> V
>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> 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/d/optout.

Roberto Lo Giacco

unread,
Sep 30, 2015, 12:04:25 PM9/30/15
to Cukes
Il giorno martedì 29 settembre 2015 23:36:45 UTC+2, Van ha scritto:

Hello!


How can we glue step definition from a .jar file? 



As Paolo said we need more details, but I can assure you it is working for me. 

Van

unread,
Oct 2, 2015, 9:33:05 AM10/2/15
to Cukes
Thanks Roberto ... nice to hear that :)

Like i replied to Paolo ... I have added the jar as a dependency and that jar along with its packages is shown in Maven dependency in package explorer view.

For example, i have a project with a package "com.project.stepdefs" then the below command works fine:
mvn clean install -Dtest=RunTest test -Dcucumber.options="--tags @xyz --glue com.project.stepdefs"

But, if i point to same step definitions in a jar (common.jar) under package "com.common.stepdefs" and try to run with below command:
mvn clean install -Dtest=RunTest test -Dcucumber.options="--tags @xyz --glue com.common.stepdefs"
It says steps are undefined. 

The common.jar file is in my local .m2 repository. 
Can you please suggest on what i am missing?

Thanks,
V

Van

unread,
Oct 2, 2015, 10:15:01 AM10/2/15
to Cukes
Hello Paolo,

I have added the jar as a dependency and that jar along with its packages is shown in Maven dependency in package explorer view.

For example, i have a project with a packages "com.project.stepdefs" then the below command works fine:
mvn clean install -Dtest=RunTest test -Dcucumber.options="--tags @xyz --glue com.project.stepdefs"

But, if i point to same step definitions in a jar (common.jar) under package "com.common.stepdefs" and try to run with below command:
mvn clean install -Dtest=RunTest test -Dcucumber.options="--tags @xyz --glue com.common.stepdefs"
It says steps are undefined. 

How to specify the classpath in glue command? The common.jar file is in my local .m2 repository.

Thanks,
V

Van

unread,
Oct 2, 2015, 10:46:33 AM10/2/15
to Cukes

Hi Paolo,

Sorry, here is the dependency snippet from POM file:

<dependency>

        <groupId>com.automation.common</groupId>

<artifactId>common</artifactId>

<version>0.0.1</version>

</dependency>


Thanks,
V

George Dinwiddie

unread,
Oct 2, 2015, 11:42:50 AM10/2/15
to cu...@googlegroups.com
Van,

On 10/2/15 3:47 AM, Van wrote:
> Thanks Roberto ... nice to hear that :)
>
> Like i replied to Paolo ... I have added the jar as a dependency and
> that jar along with its packages is shown in Maven dependency in package
> explorer view.
>
> For example, i have a project with a package "com.project.stepdefs" then
> the below command works fine:
> mvn clean install -Dtest=RunTest test -Dcucumber.options="--tags @xyz
> --glue com.project.stepdefs"
>
> But, if i point to same step definitions in a jar (common.jar) under
> package "com.common.stepdefs" and try to run with below command:
> mvn clean install -Dtest=RunTest test -Dcucumber.options="--tags @xyz
> --glue com.common.stepdefs"
> It says steps are undefined.

Did you change the package statement in the source code of the step
definitions? If not, then the argument to the '--glue' parameter should
not change. The name of the jar is of no consequence, as long as it's
included in the classpath.

- George

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

Van

unread,
Oct 2, 2015, 12:13:05 PM10/2/15
to Cukes
Yes George .. Package name is different in jar file hence i changed in the "--glue" parameter.

Thanks,
V

Roberto Lo Giacco

unread,
Oct 3, 2015, 7:32:25 AM10/3/15
to Cukes
Please find the attached projects

To have it working I run mvn install within the stepdefs project, then I move into the project project and run

mvn test -Dcucumber.options="--tags @xyz --glue org.agileware.stepdefs" -Dtest=JUnitWrapper

I tried to keep it as simple as possible.
setup.7z

Roberto Lo Giacco

unread,
Oct 6, 2015, 2:31:57 PM10/6/15
to Cukes
Did my last email solve your problem?

Van

unread,
Oct 7, 2015, 3:57:17 PM10/7/15
to Cukes
Hey Roberto,

I am sorry ... just saw your message. Still no luck :(
I am not able to download your attachment ... it shows just 1KB. Is it possible to share the code in JUnitWrapper?

Thanks,
V

Roberto Lo Giacco

unread,
Oct 7, 2015, 4:09:39 PM10/7/15
to Cukes
Il giorno mercoledì 7 ottobre 2015 21:57:17 UTC+2, Van ha scritto:
Hey Roberto,

I am sorry ... just saw your message. Still no luck :(
I am not able to download your attachment ... it shows just 1KB. Is it possible to share the code in JUnitWrapper?


It shows 1kB because it is very small...

Anyway, this is my very complex JUnitWrapper

package org.agileware;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features="src/test/resources")
public class JUnitWrapper {

}



this is my feature file

Feature: feature description
@xyz
Scenario: test
Given something
When an event occurs
Then something else happens



and this is my StepDef

package org.agileware.stepdefs;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class StepDef {

@Given("something$")
public void given() {
System.out.println("Given");
}
@When("an event occurs")
public void when() {
System.out.println("When");
}
@Then("something else happens")
public void then() {
System.out.println("Then");
}
}



Van

unread,
Oct 8, 2015, 5:43:31 AM10/8/15
to Cukes
Hi Roberto,

Every thing is same like mine. Not sure what is wrong here. Just for re-confirmation, your JUnitWraper and Feature files are in one project and Stepdefs are in a different jar correct?

Thanks,
Pavan

Roberto Lo Giacco

unread,
Oct 8, 2015, 6:28:12 AM10/8/15
to cu...@googlegroups.com
On Thu, Oct 8, 2015 at 11:43 AM, Van <pavan...@gmail.com> wrote:
Hi Roberto,

Every thing is same like mine. Not sure what is wrong here. Just for re-confirmation, your JUnitWraper and Feature files are in one project and Stepdefs are in a different jar correct?


Yes Pavan, if you download the file you will find the whole directory structure and the poms as well. I build and install the stepdefs using one POM and use the stepdefs in the other project. Obviously the stepdefs project is a dependency of the features project.

The file I've attached is not a ZIP, but a 7Z, you can use 7Zip to open it. I double checked and it can be downloaded and opened, the size is correct as it contains a few text files only.

 

--
Posting rules: http://cukes.info/posting-rules.html
---
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/Rd83aDHSgMA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cukes+un...@googlegroups.com.

Van

unread,
Oct 10, 2015, 11:52:45 PM10/10/15
to Cukes
Hi Roberto,
Thanks for your time.  I am still facing same issue :( I guess some version or configuration my machine is causing the problem.
Here are the steps i followed:
Downloaded the code.
Built stepdefs-0.0.1-SNAPSHOT.jar 
Did a mvn install 
Ran it

Please find the output of each command pasted below. Please correct me if i am doing anything wrong.

******************************************************************************************************************************************************************************
mvn install:install-file -Dfile=/Users/Van/Downloads/sample/stepdefs-0.0.1-SNAPSHOT.jar -DgroupId=org.agileware.cucumber -DartifactId=stepdefs -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing /Users/Van/Downloads/sample/stepdefs-0.0.1-SNAPSHOT.jar to /Users/Van/.m2/repository/org/agileware/cucumber/stepdefs/0.0.1-SNAPSHOT/stepdefs-0.0.1-SNAPSHOT.jar
[INFO] Installing /var/folders/4d/hys7608d4b1_3p0zd9n0_pm8jp3v4w/T/mvninstall5662068565063637057.pom to /Users/Van/.m2/repository/org/agileware/cucumber/stepdefs/0.0.1-SNAPSHOT/stepdefs-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.386 s
[INFO] Finished at: 2015-10-10T18:04:44-07:00
[INFO] Final Memory: 7M/245M
[INFO] ------------------------------------------------------------------------

******************************************************************************************************************************************************************************

mvn test -Dcucumber.options="--tags @xyz --glue org.agileware.stepdefs" -Dtest=JUnitWrapper
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building project 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ project ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ project ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ project ---
[INFO] Surefire report directory: /Users/Van/Downloads/sample/project/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.agileware.JUnitWrapper

1 Scenarios (1 undefined)
3 Steps (3 undefined)
0m0.000s


You can implement missing steps with the snippets below:

@Given("^something$")
public void something() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^an event occurs$")
public void an_event_occurs() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^something else happens$")
public void something_else_happens() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

Tests run: 5, Failures: 0, Errors: 0, Skipped: 4, Time elapsed: 0.332 sec

Results :

Tests run: 5, Failures: 0, Errors: 0, Skipped: 4

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.492 s
[INFO] Finished at: 2015-10-10T20:02:07-07:00
[INFO] Final Memory: 9M/245M
[INFO] ------------------------------------------------------------------------

******************************************************************************************************************************************************************************

mvn --version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T09:29:23-08:00)
Maven home: /Users/Van/Documents/apache-maven-3.2.5
Java version: 1.7.0_71, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.5", arch: "x86_64", family: "mac"
******************************************************************************************************************************************************************************


Thanks,
Pavan

Roberto Lo Giacco

unread,
Oct 11, 2015, 5:35:53 AM10/11/15
to cu...@googlegroups.com


Il domenica 11 ottobre 2015, Van <pavan...@gmail.com> ha scritto:
Hi Roberto,
Thanks for your time.  I am still facing same issue :( I guess some version or configuration my machine is causing the problem.


If this is the case than you should run Maven with the -X option and capture all the console contents in a file, then attach the file 

Van

unread,
Oct 11, 2015, 10:59:33 AM10/11/15
to Cukes
Please find it attached.
log.txt

Van

unread,
Jan 25, 2016, 2:52:59 AM1/25/16
to Cukes
Hi Roberto,

I did not look into this for a while. I just tried on a new mac ... It is working now. Like i mentioned there might be some configuration issue on my old mac.

Many thanks for all your help!

Thanks,
Pavan

sat...@xurmo.com

unread,
Aug 23, 2016, 2:20:41 AM8/23/16
to Cukes
Roberto/Van,

I stumbled upon the same exact issue. However, it does not work the setpdef is from a different project when I run via Maven profile it says no matching steps.  But there is another baseclass from that jar which I use and that works fine for setting up the webdriver.

Anything that I have missed in the pom configuration. Please hep


Xurmo Technologies Pvt. Ltd., Silver Software Tech Park, Plot No. 23 & 24, II Floor, EPIP 1st Phase, KIADB, Whitefield,
Bangalore - 560 066 | +918040314000 [T]

www.xurmo.com

 Disclaimer: This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake, please delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission.

Mahiteja Bollojula

unread,
Aug 13, 2018, 5:29:38 PM8/13/18
to Cukes
Hi ,

Can you please let me know how you executed the feature file by reading the step definitions classes from jar file, Thanks in advance for your support and help

Thanks
Mahiteja 

On Monday, January 25, 2016 at 1:22:59 PM UTC+5:30, Van wrote:

Cleber Baldan Jr

unread,
Aug 28, 2018, 10:05:06 AM8/28/18
to Cukes
Hello.

I just had this idea, to have common step definitions stored in a jar file.
Anyone had any luck on making this work?

Thanks!

Cleber Baldan Jr

unread,
Aug 28, 2018, 10:20:14 AM8/28/18
to Cukes
I'm not actively working on this, but this guy seems to know what he is talking about:



On Tuesday, September 29, 2015 at 4:36:45 PM UTC-5, Van wrote:

Bill Wright

unread,
Aug 29, 2018, 9:24:45 AM8/29/18
to Cukes
I've been doing this sort of thing for years and it's quite easy. First, you need to have the jar file on your class path (or in your dependencies, if you use Maven or Gradle to build). Then you just need to reference the package in your glue parameter that you pass to the CucumberRunner.
Reply all
Reply to author
Forward
0 new messages