If you want to run the same test code for tests, you will need to supplant the browser type as an environment variable, or a YAML file or something similar.
There are some things in Ruby that simplify working with yaml files (I need to write a blog entry on this) so that you can place something at the top of your script that calls the method to get configuration information, and then set the type accordingly browser.
In my testconfig.yml YAML file, I have:
global: browser: ie #possible values: ie, ff, chrome
note. I am not currently testing the opera (the market segment is too small) or it will be on the list of possible values. Commentary is just to make life easier for those who could edit this file.
I have a read_config method defined in readconfig.rb file that looks (partially) like this
require 'yaml' def read_config config = YAML.load_file('testconfig.yml') $browser_type = config['global']['browser'] end
And at the top of my tests there is such code
require 'rubygems' require 'readconfig' require 'watir-webdriver' read_config $browser = Watir::Browser.new $browser_type.to_sym
Thus, I can have a different configuration file in each system (which also sets many other things, such as current passwords (changes regularly), the testing environment used and settings for each environment for others, for example, the URL of the test server, the base server data and name, etc. When developing tests, a simple change in the configuration file allows me to run all the tests facing this browser.If I want to work in parallel, I can configure the systems using their own custom th configuration file, let them pull the current scripts from the source control, and then run them against any browser, server, etc. it is configured in the configuration file.
This is probably simple stuff for any folded ruby developer, but it looks like magic for any of us new to rubies, and especially for getting hard-coded values outside of my scripts and in one place where I can control and modify them.