Search code examples
cucumber-jvm

How can we have cucumber recognise a ":" symbol after a scenario outline parameter?


When using CucumberJVM to write feature files, when passing in the variables from the scenario outline examples table, I am unable to get the steps to recognise a variable followed by ":".

Step definition:

 @Given("^the following (.*) (.*): (.*)$")

Successfully detects this:

Given the following standard user: <username>

Does not detect this:

Given the following standard <account-type>: <username>

I want the best of both worlds, but when passing a variable from this example table for the step is not recognised by cucumber.

Examples: | username | account-type | | Jason | user | | Martin | manager |

How can I have the ":" symbol, detected and working within the feature file for both of these scenarios? is an ENUM and cucumber seems like its failing to convert it in this situation


Solution

  • As suggested in the comments, modify the pattern in the stepdefinition class.

    @Given("^the following standard (.*?): (.*?)$")
    public void the_following_standard_user( AccountType usertype,String user) {
        System.out.println(user);
        System.out.println(usertype);
    }
    

    AccountType is the enumeration.

    public enum AccountType {
    
        USER("user"), MANAGER("manager");
    
        private final String type;
        private AccountType(String type) {
            this.type = type;
        }
    }