Cleanup steps for Cucumber scenarios

2019-03-15 02:16发布

Is there a way to define the cleanup steps for all of the scenarios for a feature in Cucumber? I know that Background is used to define the setup steps for each scenario that follows it, but is there a way to define something like that to happen at the end of each scenario?

标签: cucumber
2条回答
Luminary・发光体
2楼-- · 2019-03-15 02:50

should also notice that 'Before' and 'After' is global hooks i.e those hooks are run for every scenario in your features file

If you want the setup and teardown to be run for just few testcases ( grouped by tags) then you need to use taggedHooks, where the syntax is

Before('@cucumis, @sativus') do
# This will only run before scenarios tagged
# with @cucumis OR @sativus.
end


AfterStep('@cucumis', '@sativus') do
# This will only run after steps within scenarios tagged
# with @cucumis AND @sativus.
end

For more info : https://github.com/cucumber/cucumber/wiki/Hooks

查看更多
\"骚年 ilove
3楼-- · 2019-03-15 02:53

You can use an After hook that will run after each scenario:

After do
  ## teardown code
end

There's also a Before hook that will allow you to set up state and/or test data prior to the scenario:

Before do
  ## setup code
end

The Before and After hooks provide the functionality of setup and teardown from Test::Unit, and they are generally located in hooks.rb in the features/support directory.

查看更多
登录 后发表回答