Reputation: 1593
We're looking at a cloud-based automation framework that plays well with Cucumber and Selenium, which we use at my job.
In reading over the docs I need to modify our env.rb
file to put in some setup code.
Would it be possible to put this initialization code in a different file instead? If so, how would that work?
Reason being is I'd rather not complicate env.rb
any more than it already is, and we're not sure we're going to use this particular framework and would like to keep things simple in case we need to back out.
Ideally I'd like to put this initialization in a separate file and only call it for specific feature files, but will take what I can get.
Upvotes: 3
Views: 2568
Reputation: 17480
Yes. You can put it in any file under the features/support directory and it will be loaded automatically.
You might have something like:
features/support/env.rb
features/support/capybara_config.rb
features/support/hooks.rb
etc
I have found in practice that anything you need to run only once should go into env.rb, or you should provide some flagging mechanism such as a global variable to make sure you don't do it twice.
Looking a little closer at your question, sounds like you have some setup that needs done sometimes. You can do this with HOOKS
features/support/hooks.rb
Before('@myspecialtest') do
SetupObject.do_the_thing
end
feature/support/setup_object.rb
class SetupObject
def self.do_the_thing
# perform setup
end
end
features/my.feature
@myspecialtest
Scenario: My Scenario
Upvotes: 7