How to write numbers in cucumber scenarios

允我心安 提交于 2019-12-11 05:47:59

问题


I would like to write a number in cucumber page. Please let me know How can I write this.

Scenario Outline: Enter an invalid URL

Given the context "Invalid URL" is open on "Market" 
  When user is on the error 404 page
  Then page not found message is displayed

But i have observed that 404 is taken as a parameter.


回答1:


Sure, you just have to handle it as a regular expression (regex) in your step definitions. Your step definition could read as following:

@When("^When user is on the error \"(\\d+)\" page$")
public void When_user_is_on_the_error_page(int errorNum) throws Throwable {

...

}

That'll handle 1 or more digits. The \d represents a digit and the + sign represents "1 or more".

I personally like wrapping my parameters in double quotes ("") because then the IDE understands it's a parameter and can help you out with autocomplete, etc.

If you want to restrict it to more specific numbers (say only three digits) you can refine your regex to something like [\d]{3}. Oracle have lessons on Java regex here.



来源:https://stackoverflow.com/questions/32475031/how-to-write-numbers-in-cucumber-scenarios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!