Skip to content
MauravdL edited this page Sep 13, 2010 · 3 revisions

Use the watircraft command to create your project. Your project will contain your tests, your libraries, your configuration files, and all the glue code necessary to allow it all to work together. Let’s create a project for testing Google.

  > watircraft google

This will create a directory called “google” and populate it with a bunch of directories and files.

You’ll need to edit the config\environments.yml file to point to you base url of your project.

  test:
    url: http://google.com

By default, your tests will run in the “test” environment, but you can specify additional environments later. When you run your tests, you can specify which environment to use on the command line.

Use the script\generate command to populate your project with project files. This command must be run from the top of your project.

  > cd google

Create a test. WatirCraft uses the RSpec test harness and therefore calls a test a “spec”.

  > script\generate spec search

This creates a bare template for a test. Edit the file that was just created (test/specs/search_spec.rb) and add the following lines.

  browser.text_field(:name, 'q').set 'WatirCraft'
  browser.button(:name, 'btnG').click
  browser.text.should include('Test automation for web applications')

The WatirCraft framework will automatically start the browser at the configured url when you run it.

After you have added these lines to the template, the complete file will look like this.

        $LOAD_PATH.unshift File.dirname(__FILE__) unless
          $LOAD_PATH.include? File.dirname(__FILE__)
        require 'spec_helper'

        describe "Search" do

          it "should find WatirCraft" do
            browser.text_field(:name, 'q').set 'WatirCraft'
            browser.button(:name, 'btnG').click
            browser.text.should include('Test automation for web applications')
          end

        end

Use the rake command to run the tests for your project(only one so far). This needs to be run from the base of your project.

  > rake spec

By default, your test runs with Internet Explorer, but you can also run it with Firefox.

  > rake spec BROWSER=firefox

You can also just run individual files.

  > ruby test/specs/search_spec.rb

Note that many editors will do this automatically for you. For example the Scite editor will do this when you hit “F5”.

Clone this wiki locally