简体   繁体   English

禁止某些黄瓜步骤的输出

[英]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. https://github.com/aslakhellesoy/cucumber/wiki/custom-formatters包含有关如何执行此操作的信息。 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". 基于快速浏览,我想您应该实现step_name函数,然后在获得的步骤名称(请参阅TwitterFormatter的链接示例)中不包含“保存屏幕截图”的情况下写出结果。

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. 这也将有助于使您的方案专注于用户实际将要执行的操作,而不会使它们陷入与执行测试有关的步骤中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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