1

I code cucumber scripts for java

There is a following case for or selection

working  @When("^(chrome|firefox|edge) browser started")

don't work @When("(chrome|firefox|edge) browser started")

Also, I don't understand function of ^ char, because

don't work @When("^browser")    => feature    when browser started  
working @When("^browser started")    => feature    when browser started  
working @When("browser started")    => feature    when browser started  
2
  • The ^ anchor just means "at the very start of the string." If you omit it, the pattern might still work, because by default the search will start from the beginning on the string anyway. Commented Jul 1, 2022 at 8:43
  • In first case, for or statement, when it works with ^ car but it doesn't work without ^, I don't understand this logic Commented Jul 1, 2022 at 8:47

1 Answer 1

3

Cucumber supports two types of expressions which are mutually exclusive:

  • regular expressions (aka RegEx)
  • Cucumber expressions

Cucumber distinguishes which sort of expressions you are using with checking "anchors" symbols which for RegEx have to be ^ at the start and $ at the end of the string.

So while the syntax in your first example is valid for RegEx, it is working. But if your expressions misses anchors (like in your second example) it is treated as "Cucumber Expression" where that (chrome|firefox|edge) is not valid any more.

For cucumber expressions to work with your case you have to apply "Custom Pameter Types".

See details at cucumber github page.

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

Comments

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.