Reputation: 1105
How do I use an ENV variable in a hook?
I have some driver configs set in the my env.rb file that work on an if statement.
if ENV['headless_phantom']
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, window_size: [1280, 1024], js_errors: false, debug: false)
end
Capybara.default_driver = :poltergeist
elsif ENV['headless_chrome']
Capybara.register_driver :headless_chrome do |app|
opts = Selenium::WebDriver::Chrome::Options.new
opts.add_argument '--start-maximized'
opts.add_argument '--disable-infobars'
opts.add_argument '--headless'
Capybara::Selenium::Driver.new(app, browser: :chrome, options: opts)
end
Capybara.default_driver = :headless_chrome
...
Usually to invoke a driver other than the default, I add the following in the runner options in my IDE or command line:
headless_chrome = true
I'm looking to do the following to save me going into the runner options all the time to allow a quick change of driver when initially writing the tests.
before('@chrome_headless') do
ENV['headless_chrome'] = true
end
Upvotes: 0
Views: 1827
Reputation: 656
Why not use cucumber profiles and then set the ENV var there. See https://github.com/cucumber/cucumber/wiki/cucumber.yml for details on how to use profiles.
Keep It Super Simple! Otherwise it will grow into a nightmare to maintain.
Upvotes: 1