Cucumber Options Glue

Profile picture for user devraj
Submitted by devraj on

What is Glue in Cucumber?

Glue Option helps Cucumber to locate the step definition file. We specify the package to load glue code (step definitions or hooks) in the glue option. When no glue is provided, Cucumber will use the package of the annotated class. For example, if the annotated class is com.example.Runner then glue is assumed to be located in com.example.

Cucumber Glue Example

@RunWith(Cucumber.class)
@CucumberOptions(
		plugin = {"pretty", "html:target/cucumber"},
		features = {"src/test/resources/features" }, 
		glue = {"com.pb.cucumbertest.stepdefinitions"}, 
		)

public class Runner {

}

In example given above my step definitions files are inside package com.pb.cucumbertest.stepdefinitions. In case your test runner and step definitions files are in same package you can comment or remove glue line cucumber options.

In case your step definitions are in 2 different packages you can separate packages using comma:

glue = {"com.pb.cucumbertest.stepdefinitions", "com.pb.cucumbertest.util"}

and here you can see part of packages are common, so we can write like this

glue = {"com.pb.cucumbertest"}

Method Signature

  • String[] glue()
  • default {};
  • Returns: list of package names

Note: Your step definition and features files can contain subfolder as well. You do not need to make any additional changes; in that case, specifying the parent folder name is enough.