If you've built a complicated application and you want to make sure it works, you perform acceptance testing. This three-part article series will show you how to automate the process. It is excerpted from chapter 11 of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).
Acceptance Testing - Installing Selenium (Page 2 of 4 )
Before installing the plugin, you need to install Selenium itself, as follows:
$ sudo gem install selenium
-------------------------------------------- Attempting local installation of 'selenium' Local gem file not found: selenium*.gem Attempting remote installation of 'selenium' Updating Gem source index for: http://gems.rubyforge.org Successfully installed selenium-0.7 --------------------------------------------
Note The RubyGems repository might not contain the latest version. If you want the latest version of Selenium, download Selenium Core from http://www.openqa.org/selenium-core and extract it to vendor/selenium.
The Selenese format uses the Textile markup format (introduced in Chapter 3), which requires that you have RedCloth installed on your machine. To verify that you have RedCloth installed, execute the following command:
$ gem list
--------------------------------------------... RedCloth (3.0.4) RedCloth is a module for using Textile and Markdown in Ruby. Textile and Markdown are text formats. A very simple text format. Another stab at making readable text that can be converted to HTML. ... --------------------------------------------
If you don't see RedCloth in the list of installed RubyGem packages, execute the following command:
$ sudo gem install redcloth
Next, install the Selenium plugin directly from the Subversion repository:
This installs the latest version of the plugin in the vendor/plugins/selenium-on-rails directory. Execute the rake command in the plugin directory to verify that the installation works:
$ cd vendor/plugins/selenium_on_rails $ rake
The rake script executes all tests. You should see them pass without errors.
Note On Windows, if you want to use rake to run your acceptance tests, you need to install win32open3. See the Selenium on Rails homepage (http://www.openqa.org/selenium-on-rails/) for details.
When using Selenium Core, you start the acceptance tests by opening the Selenium test runner in your browser and executing the Selenium test suite. With Selenium on Rails, these steps have been automated and can all be executed with the following command:
$ cd /home/projects/george/emporium $ rake test:acceptance
If you execute the command now, Selenium on Rails will complain that you haven't specified the path to the browser executables. To specify the path, you need to modify the Selenium on Rails configuration file (vendor/plugins/selenium_on_rails/config.yml). The configuration file allows you to specify where browser executables are located on your system and the environments for which Selenium should be enabled. Create the configuration by renaming vendor/plugins/selenium_on_rails/config.yml. example to config.yml. Update the paths to match your system's configuration, as in the example shown here:
# Enable Selenium for the following environments environments: - test # - development # - production
Tip Selenium on Rails runs the acceptance tests in all browsers that have been listed in the configuration file. This makes it easy to test that your application works on multiple browsers. Selenium supports most browsers and platforms, including Windows, Mac OS X, and Linux. Check the Selenium documentation (http://www.openqa.org/selenium-core) to verify that your setup is supported.
Selenium and Selenium on Rails are now installed, which means you can start writing Selenium tests.