3

I have multiple projects using similar step definition across the different projects. Hence using all step definition in single project and added as dependency jar in maven. When I run using maven command it says :

You can implement missing steps with the snippets below:

@When("^Import a canvas from \"(.*?)\" to project \"(.*?)\"$")
public void import_a_canvas_from_to_project(String arg1, String arg2) throws Throwable {
 // Write code here that turns the phrase above into concrete actions
  throw new PendingException();
  }

but when I add package in same project it works fine. (Even in eclipse from different projects works). Is there any way to run such scenarios from maven and jenkins?

I am using eclipse IDE. maven command I used is : mvn -DprofileTest=cucumberID clean -P cucumberID test

cucumberID is my profile name.

Following profile I added in pom.xml

<profile>
<id>cucumberID</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <version>2.11</version>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                    <includes>
                                <include>step_definitions/LoginTest.java</include>
                    </includes>
                    <parallel>classes</parallel>
                    <threadCount>3</threadCount>
                    <useFile>true</useFile>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>
Komal
  • 31
  • 1
  • 3

3 Answers3

5

You haven't specified how are you running your test suite but assuming that you have @CucumberOptions somewhere, you can just point to other projects packages like this:

@CucumberOptions(. . . glue = {
        "com.company.test.package1", "com.company2.test.package2", . . .})
Eugene S
  • 6,709
  • 8
  • 57
  • 91
  • The problem is with glue option as the stepdefinition is part of different project which is added as a jar dependency. – Komal Aug 24 '16 at 05:09
  • @RunWith(Cucumber.class) @CucumberOptions( features = "classpath:features", glue = { "com.xurmo.bdd.stepdefinition.ui" }, plugin = {"pretty", "html:target/cucumber-html-report"}, tags = {} ) public class RunCukesTest{ } – Komal Aug 24 '16 at 05:10
  • I guess you'll need to add that package to your project. – Eugene S Aug 24 '16 at 05:18
  • Is this is a limitation of cucumber scanner? – Komal Aug 24 '16 at 05:24
  • @Komal I am sorry, I got it wrong. I mixed that up feature files location. Fixed my answer. – Eugene S Aug 24 '16 at 05:30
  • I used in similar way but giving error as specified in question. @CucumberOptions( features = "classpath:features", glue = { "com.company.bdd.stepdefinition.ui" }, – Komal Aug 24 '16 at 05:54
  • @Komal This setup works for me but I have both projects in my IDE. I do not import the jar file itself. – Eugene S Aug 24 '16 at 06:06
  • Yes, even for me it works fine from IDE but when we run through command line using maven or jenkins, it wont work. – Komal Aug 24 '16 at 06:15
  • @Komal In that case you should carefully inspect your command and make sure you do not miss some environment variables. It is hard to help as you didn't include neither your IDE runner nor command line command. – Eugene S Aug 24 '16 at 06:20
  • I am using eclipse IDE. maven command I used is : mvn -DprofileTest=cucumberID clean -P cucumberID test cucumberID is my profile name. – Komal Aug 24 '16 at 06:27
  • @Komal It is very hard to read that way. Just add that to your question. – Eugene S Aug 24 '16 at 06:30
2

use classpath: prefix for the package name to solve this.

for example: @CucumberOptions(glue = { "classpath:com.example.test.steps" })

Jon
  • 301
  • 4
  • 9
0

If you will use Maven's preferred way of creating packages, then "mvn package" your code, and "mvn install" this package, then you'll be able to run test from external library without changes in class annotated with @CucumberOptions.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459