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 test@test.com
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"
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.