简体   繁体   中英

Cucumber 6 undefined custom step

I am upgrading Cucumber version in my project and custom configuration changed between versions 4 and 6.

I've registered a custom keyword for Parameter Type.

Everything works, step passes and the value is generated but the step is still marked as undefined .

I use Intellij IDEA and Cucumber plugin for Java Is it a plugin problem or somewhere in y code?

Cucumber step:

When generate uniqueRandom(5) for test

在此处输入图片说明

Java step:

@When("generate {unique_random} for test")
public void testStep(int randomNumber) {
    log.info(String.valueOf(randomNumber));
}

Parameter Type registry:

@ParameterType(name = "unique_random", value = "uniqueRandom\\([0-9]+\\)")
public Integer randomNumber(String original) {
    return ... // some logic of creation
}

Cucumber version: 6.8.1

Is it possible from my side to do something with this warning?

Looks like there is an issue with Cucumber API and Cucumber Plugin.

I changed my Parameter Type registration method

from:

@ParameterType(name = "unique_random", value = "uniqueRandom\\([0-9]+\\)")
public Integer randomNumber(String original) {
    return ... // some logic of creation
}

to

@ParameterType(value = "uniqueRandom\\([0-9]+\\)")
public Integer unique_random(String original) {
    return ... // some logic of creation
}

This solution is described in the documentation of @ParameterType.name()

Name of the parameter type. This is used as the type name in typed expressions. When not provided this will default to the name of the annotated method.

The plugin doesn't resolve the parameter name in the annotation but as a method name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM