2

I have run into a problem that my custom cucumber configuration works in the same test project, but doesn't work as a dependency in other test project

CustomTypeRegistry class:

public class CustomTypeRegistry {

    @ParameterType("customEx\\([0-9]+\\)")
    public Integer custom(String original) {
        return new Random().nextInt();
    }
}

Java glue step:

@When("generate {custom} for test")
public void testStep(int randomNumber) {
    System.out.println(randomNumber);
}

Scenario step:

When generate customEx(5) for test

When I create tests in the same project where cucumber configurations are present this works perfectly.

When I pack project to a jar and add it as dependency to another test project it recognizes the step but in runtime I got the error:

17-11-2021 14:15:55.592 [main] ERROR io.cucumber.core.runtime.Runtime.log - Exception while executing pickle java.util.concurrent.ExecutionException: io.cucumber.core.exception.CucumberException: Could not create a cucumber expression for 'generate {custom} for test'. It appears you did not register a parameter type. at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191) at io.cucumber.core.runtime.Runtime.run(Runtime.java:93) at io.cucumber.core.cli.Main.run(Main.java:92) at io.cucumber.core.cli.Main.main(Main.java:34) Caused by: io.cucumber.core.exception.CucumberException: Could not create a cucumber expression for 'generate {custom} for test'. It appears you did not register a parameter type. at io.cucumber.core.stepexpression.StepExpressionFactory.registerTypeInConfiguration(StepExpressionFactory.java:101) at io.cucumber.core.stepexpression.StepExpressionFactory.crateExpression(StepExpressionFactory.java:95) at io.cucumber.core.stepexpression.StepExpressionFactory.createExpression(StepExpressionFactory.java:61) at io.cucumber.core.stepexpression.StepExpressionFactory.createExpression(StepExpressionFactory.java:49) at io.cucumber.core.runner.CachingGlue.lambda$prepareGlue$3(CachingGlue.java:244) at java.base/java.util.ArrayList.forEach(ArrayList.java:1540) at io.cucumber.core.runner.CachingGlue.prepareGlue(CachingGlue.java:243) at io.cucumber.core.runner.Runner.runPickle(Runner.java:68) at io.cucumber.core.runtime.Runtime.lambda$execute$5(Runtime.java:110) at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:117) at io.cucumber.core.runtime.Runtime.lambda$execute$6(Runtime.java:110) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at io.cucumber.core.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:233) at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118) at io.cucumber.core.runtime.Runtime.lambda$run$2(Runtime.java:86) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.base/java.util.stream.SliceOps$1$1.accept(SliceOps.java:199) at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1631) at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127) at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) at io.cucumber.core.runtime.Runtime.run(Runtime.java:87) ... 2 common frames omitted Caused by: io.cucumber.cucumberexpressions.UndefinedParameterTypeException: Undefined parameter type {custom}. Please register a ParameterType for {custom}. at io.cucumber.cucumberexpressions.CucumberExpression.processParameters(CucumberExpression.java:103) at io.cucumber.cucumberexpressions.CucumberExpression.(CucumberExpression.java:35) at io.cucumber.cucumberexpressions.ExpressionFactory.createExpression(ExpressionFactory.java:34) at io.cucumber.core.stepexpression.StepExpressionFactory.crateExpression(StepExpressionFactory.java:88)

Cucumber version: 6.8.1

Build tool: Maven

What can cause the problem?

1 Answer 1

1

The likely reason you can observe such behavior is that there is a thing called "glue path" that is basically a package where Cucumber looks up the code (including custom parameter definitions).

By default cucmber uses glue path taken as the package that contains your runner class. So I assume that when you were having your code in original project that condition was met.

But when you made a library and used it as a dependency in another project Cucumber stopped seeing that since conditions stopped being met.

You need to specify glue path manually like it is mentioned in cucumber docs

By default Cucumber-JVM will search in the package (or sub-packages) of the runner class. You can also tell Cucumber-JVM explicitly which packages (and sub-packages) to search, with:

 @CucumberOptions(glue = {"<package>", "<package>", "<etc>"})
 public class RunCucumberTest{}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.