3

I am new to cucumber and regex . I am currently using cucumber core 7.2.0 for a project.

For some reason I cannot seem to get regular expressions to work in the step definition.

For example I have the following

Scenario: User tries to login

When I enter valid credentials for [email protected] 


 

Then on step definition class

@When("I enter (.*) credentials for {word}")
 public void iEnterMyCredentialsAsUser(String email) {
      System.out.println(email);

}

While the feature finds the step definition found just fine, when executing I get the following

io.cucumber.junit.UndefinedStepException: The step 'I enter valid credentials for testa30' is undefined. You can implement this step using the snippet(s) below:

   @When("I enter valid credentials for testa30")
   public void i_enter_valid_credentials_for_testa30() {
   // Write code here that turns the phrase above into concrete actions
   throw new io.cucumber.java.PendingException();
 }

Basically I want to only care about the email as a parameter and not care about "valid"

1 Answer 1

8

To let Cucumber know you are using regular expressions, start your definition with ^ and end with $. See details here.

More over do not mix up regular expressions and cucumber expressions. Syntax like {word} is not supported when you use regular expression approach.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, got it to work with your suggestion , will make sure not to combine both regex and cucumber expressions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.