Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want to run the exact same test code for the tests you will need to externalize the browser type, either as an environment variable, or a YAML file or somesuch. </p> <p>Ruby has some stuff that makes dealing with yaml files super easy (I need to write a blog posting on this) so you can put something at the top of your script that calls a method to get the config info and then set the browser type accordingly.</p> <p>In my <code>testconfig.yml</code> YAML file I have: </p> <pre><code>global: browser: ie #possible values: ie, ff, chrome </code></pre> <p>note I don't currently test against opera (market segment too small) or it would be in the list of possible values. The comment is just there to make life easy on whoever might have to edit that file.</p> <p>I have a <code>read_config</code> method defined in a <code>readconfig.rb</code> file which looks (in part) like this</p> <pre><code>require 'yaml' def read_config config = YAML.load_file('testconfig.yml') $browser_type = config['global']['browser'] end </code></pre> <p>And at the top of my tests there is code like this</p> <pre><code>require 'rubygems' require 'readconfig' require 'watir-webdriver' read_config $browser = Watir::Browser.new $browser_type.to_sym </code></pre> <p>This way I can have a different config file on each system (which also sets up a lot of other things like the current passwords (changed on a regular basis), which test environment to use, and settings for each environment for stuff like the test server URL's, database server and name, etc. When developing tests a simple change to the config file lets me run all the tests facing a given browser. or if I want to run in parallel I can have the systems setup with their own customized config file, let them pull the current scripts from source control, and then run them against whatever browser, server etc is configured in the config file.</p> <p>This is probably dirt simple stuff to any accomplished ruby dev, but it's like magic for any of us new to ruby, and especially for getting hard-coded values OUT of my scripts and into one single place where I can control and change them. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload