Is it possible to pass Java-Enum as argument from cucumber feature file

牧云@^-^@ 提交于 2019-12-10 15:15:38

问题


I am currently using selenium with Java,And want to implement cucumber to make test script more readable. Currently facing issue while passing argument to java method where Enum is expected as parameter. I would also like to know if there are any other known limitaions of cucumber-java befor migrating current framework.

As i'm new on cucumber If any one knowing good source for learing cucumber in details please give me a link.


回答1:


The answer is: Yes

You can use all kind of different types in your scenario: primitive types, own classes (POJOs), enums, ...

Scenario :

Feature: Setup Enum and Print value
      In order to manage my Enum
      As a System Admin
      I want to get the Enum

      Scenario: Verify Enum Print
      When I supply enum value "GET"

Step definition code :

import cucumber.api.java.en.When;

public class EnumTest {

    @When("^I supply enum value \"([^\"]*)\"$")
    public void i_supply_enum_value(TestEnum arg1) throws Throwable {
        testMyEnum(arg1);
    }

    public enum TestEnum {
        GET,
        POST,
        PATCH
    }

    protected void testMyEnum(TestEnum testEnumValue) {

        switch (testEnumValue) {
            case GET:
                System.out.println("Enum Value GET");
                break;
            case POST:
                System.out.println("Enum Value POST");
                break;
            default:
                System.out.println("Enum Value PATCH");
                break;
        }

    }

}

Let me know how you are doing. I could try to help you.




回答2:


This is no more supported in latest io.cucumber maven group https://github.com/cucumber/cucumber-jvm/issues/1393



来源:https://stackoverflow.com/questions/34718083/is-it-possible-to-pass-java-enum-as-argument-from-cucumber-feature-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!