简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM