Cross Browser Config with Thor

easy env.rb edits

Problem:

Manually tweaking your features/support/env.rb cucumber file can be a tedious task when testing in multiple browsers.

Solution:

Use custom thor comamnds with the Thor RubyGem.

Below is a stock features/support/env.rb file for running cukes with selenium-webdriver in :chrome.

In order to run scenarios in :firefox one has to:

  1. Opening features/support/env.rb in a Text Editor
  2. Changing line:11 to :firefox
  3. Save the file
  4. Launch cukes

At CukeHub we use this browsers.thor file to streamline browser swapping. Adding it to the root of our repository allows us to run this single command.

  1. thor set:firefox
  2. Launch cukes

See ^^ what it did there?

thor set:firefox justs copies (cp) the features/support/envs/env.rb.firefox

into the live slot features/support/env.rb

( you may want to .gitignore features/support/env.rb since it changes so often )

Now thor list from the root of the repository will show you a list of broswer config options.

This becomes extremely helpful if you are using Saucelabs or Browserstack and their extra config code.

Conclusion:

  1. Add this browsers.thor file to the root of your cuke repository.
  2. Add featuers/support/envs/ directory with browser specific env.rb(s)