Search code examples
seleniumcucumbercucumber-java

Cucumber Example Table Not Delimiting Properly


I have an example table

Examples:
| UserName         | Group    | NotifyUser | ReadOnlyPermission |
| testing@test.com | new test | no         | no                 |

for the step

And User fills out User Info Form with <UserName> <Group> <NotifyUser> <ReadOnlyPermission>

and the step definition of

@And("^User fills out User Info Form with (.*) (.*) (.*) (.*) $")
public void fillUserInfoForm(String username, String group, String notifyUser, String readOnlyPermission)

But for some reason the variable username is being imported as "testing@test.com new" instead of just "testing@test.com".

I've looked all over but I can't seem to find out why its not delimiting correctly. Is there any way I can fix this?


Solution

  • Becasue you have whitespace in your "Group". After Cucumber substities your example data to the step it looks like:

    enter image description here

    You can rewrite your step definition to separate your items with say comma, so that:

    And User fills out User Info Form with <UserName>,<Group>,<NotifyUser>,<ReadOnlyPermission>
    

    and

    @And("^User fills out User Info Form with (.*),(.*),(.*),(.*)$")
    public void fillUserInfoForm(String username, String group, String notifyUser, String readOnlyPermission)
    

    This should resolve your issue:

    enter image description here

    P.S. - This fix will encounter problems if you have commas in your example data. However you can consider this when prepare your regular expressions.