是否可以将Java-Enum作为参数从黄瓜功能文件传递 [英] Is it possible to pass Java-Enum as argument from cucumber feature file

查看:141
本文介绍了是否可以将Java-Enum作为参数从黄瓜功能文件传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将硒与Java配合使用,并希望实现黄瓜来提高测试脚本的可读性。
在将参数传递给java方法(其中以Enum作为参数)时当前面临的问题。
我还想知道在迁移当前框架之前,黄瓜java是否还有其他已知的局限性。

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.

推荐答案

答案是:是的

您可以在方案中使用所有类型的不同类型:原始类型,自己的类(POJO),枚举,...

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

场景:

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"

步骤定义代码:

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.

这篇关于是否可以将Java-Enum作为参数从黄瓜功能文件传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆