Cucumber Stopping Execution after Time in Steps

青春壹個敷衍的年華 提交于 2019-12-24 04:56:10

问题


One of my tests waits until an event happens in the Then step. If the test works fine there is no issue but if the test is failing (i.e. no event is triggered) then it just hangs.

How can I set a timeout in Cucumber?

I know JUnit has a timeout parameter you can use in the @Test annotation, is there something similar for Cucumber?


回答1:


Cucumber has followed the JUnit pattern and offers a timeout parameter in its steps annotations. This takes a long value specifying the number of milliseconds after which the step is failed if it doesn't finish execution.

You can use it as follows:

@Then(value = "^verify (\\d+) events sent$", timeout = 5000)

This also works on the other step types (e.g. Given, When).

Don't forget to add value = before the steps definition string.



来源:https://stackoverflow.com/questions/47456589/cucumber-stopping-execution-after-time-in-steps

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