7

How can I reuse Cucumber-JVM Step Definitions in other projects to test some typical web actions. The point is that I've created some java project just with Step Definition Implementations of the typical scenario actions like:

When I follow the link "*some_link*"
Then I should see following content "*some_content*" on page

And I want to reuse these definitions in other projects (include in classpath), just to write their own simple scenarios. But when I run the scenario (as JUnit test), Cucumber cant find Step Definitions. And when I try to extend Step Definitions class it gives me an error, that I can't extent Step Definition class. So, is it possible to reuse Step Definitions and if so than how?

Raedwald
  • 46,613
  • 43
  • 151
  • 237
kazakovs
  • 379
  • 1
  • 3
  • 9

1 Answers1

12

Well, I've found solution. It appears quite easy.

There is annotation @CucumberOptions which has parameter "glue". Pointing with this parameter to the base package that has the step definitions forces Cucumber to search in that base package. The test runner will look like:

@RunWith(Cucumber.class)
@CucumberOptions(glue = { "com.example.stepdefspackage" })
public class Run{
}
Lance Kind
  • 949
  • 12
  • 32
kazakovs
  • 379
  • 1
  • 3
  • 9
  • Thanks for updating this info. I am also using Cucumber and am pretty sure I am going to hit this issue (maybe today) – noplay Oct 15 '12 at 13:33
  • you'd be better off with "classpath:" to let it search the classpath for it – Matt Oct 15 '12 at 14:43
  • Notice that you're not able to mention the *class name* of the step, but only the package. This strategy, although not hard to do, has some drudgery. More about this here: http://confessionsofanagilecoach.blogspot.com/2017/05/teaching-cucumbers-about-boundaries.html – Lance Kind May 03 '17 at 21:23