简体   繁体   中英

Cucumber step definition with asterisk

We have feature files that have long tests that validate multiple things written in non-english language, the Given -> When -> Then structure doesn't make sense. I tried replacing feature file keywords with * , and that works just fine, however here are the problems:

  1. When writing a new step in a form of * Some step , and using Alt->Enter shortcut to generate a step definition, IntelliJ IDEA does... Nothing. It only opens the file where I wanted to put the definition without any added code. I've updated IDE and plugins to be latest.
  2. There doesn't seem to be any way to have a "universal" annotation to use for asterisk steps, only Given , When , Then , And , But exists. It's not very logical to have a * Some step feature and @Given("Some step") definition.

Is there any workaround that I might use?

I think you can achieve this with few coding steps.

  1. Say you have the scenario like this:
Feature: Generic annotation

  Scenario: Testing annotations
    * having asterix
    * use custom generic annotation
  1. Add custom annotation to your sources
package click.webelement.cucumber;

import io.cucumber.java.StepDefinitionAnnotation;
import io.cucumber.java.StepDefinitionAnnotations;
import org.apiguardian.api.API;
import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@StepDefinitionAnnotation
@Documented
@Repeatable(MyStep.MySteps.class)
@API(status = API.Status.STABLE)
public @interface MyStep {

    String value();

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @StepDefinitionAnnotations
    @Documented
    @interface MySteps {
        MyStep[] value();
    }
}
  1. Now use it in your Step Definition
package click.webelement.cucumber;

public class StepDef {

    @MyStep("having asterix")
    public void doOne(){
        System.out.println("Running having asterix");
    }

    @MyStep("use custom generic annotation")
    public void doTwo(){
        System.out.println("Running use custom generic annotation");
    }

}

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