开发者

Suppress output of certain cucumber steps

I'm using cucumber and selenium for integration testing and have defined a cucumber step that takes a screen shot of the current page, like so:

Then /^save screenshot as "(.+)"$/ do |name|
  embed_screenshot name
end

(See this blog post for how the screen shot embedding works if interested.)

For example, part of a scenario might look like this:开发者_运维百科

...
When I go to the login page
And save screenshot as "authentication_1_login_page"
...

All works perfectly fine, but of course the screen shot step itself is included in the output of cucumber, which is a bit distracting since it has nothing to do with the actual tests. Is there a way to define this step as "silent", so that just does what it's supposed to do but is not included as a distinct step in the output?

Thanks!


If you need finer-grained control, then it looks like you probably need to write your own custom formatter. https://github.com/aslakhellesoy/cucumber/wiki/custom-formatters has information on how to do this. Based on a quick perusal, I'd say you should implement a step_name function and then write out results if the step name you get (see the example at that link for the TwitterFormatter) does not contain "save screenshot".


I don't know of a way to suppress a step like you describe, but if you want to take a screenshot in all or most of your tests, taking the screenshot step out of the scenarios and using a hook might be a good solution. See here for more information. This would also help keep your scenarios focused on what a user would actually be doing and not clutter them up with steps related to doing the test.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜