Reusing Cucumber-JVM Step Definitions in Other Projects

How can I use Cucumber-JVM step definitions in other projects to test some typical web actions. The fact is that I created some Java project only by implementing the definition of steps of typical scripts, such as:

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 (including the classpath), just to write my own simple scripts. But when I run the script (as a JUnit test), Cucumber cannot find the definition of the steps. And when I try to extend the Step Definitions class, I get an error that I cannot extend the Step Definition class. So, is it possible to reuse step definitions, and if so, how?

+6
source share
1 answer

Ok, I found a solution. It looks pretty easy.

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

 @RunWith(Cucumber.class) @CucumberOptions(glue = { "com.example.stepdefspackage" }) public class Run{ } 
+12
source

Source: https://habr.com/ru/post/927606/


All Articles