简体   繁体   English

仅在选定的黄瓜方案之后如何运行挂接?

[英]How to run a hook only after selected Cucumber scenarios?

I've written a hook to capture a screenshot of a successful test: 我写了一个钩子来捕获成功测试的屏幕截图:

After do |scenario|
  if scenario.passed?
    screenshot_pass = "/VVR_Browser_BDD/Test Pass/#{scenario.name}.jpeg"
    page.save_screenshot screenshot_pass
  end
end

This element works very well at the moment, but as my test suite grows, I'll be overrun by screenshots. 此元素目前效果很好,但是随着我的测试套件的增长,我会被屏幕截图所淹没。 I want to pick and choose when this hook is used. 我想选择并选择何时使用此挂钩。

I know with a feature file, you can tag it like: 我知道使用功能文件,您可以将其标记为:

@happypath
When /^I log into a page$/ do

etc etc. 等等等

Can that same tag mechanism be used to call the hook? 可以使用相同的标记机制来调用挂钩吗?

I only want to run screenshots for new tests that I've written to satisfy me they're working correctly before they're integrated into my full test suite. 我只想为我编写的新测试运行屏幕截图,以使它们在集成到我的完整测试套件中之前能够正常工作。

If you are calling the code as part of a hook, you should be able to perform the action for tagged scenarios 如果您将代码作为挂钩的一部分进行调用,则应该能够对标记的场景执行操作

@take_screenshot
When /^I log into a page$/ do

Then your hook could be called 然后你的钩子可以叫

After('@take_screenshot') do |scenario|
   if scenario.passed?
     screenshot_pass = "/VVR_Browser_BDD/Test Pass/#{scenario.name}.jpeg"
      page.save_screenshot screenshot_pass
  end
end

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

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