Scripting Web Tests

Lab 6: Harnessing Tests

You’ve written a number of tests. Now it’s time to put them all together with a test harness. This will allow them to run in sequence and automatically report whether any of the tests fail.

The following code demonstrates how to create a simple test harness that loads one test script.

  require 'watir'
  require 'test/unit'
  class LoadTestScript < Test::Unit::TestCase
    def test_login_start
      load 'login-start.rb'
    end
    def teardown
      ie = Watir::IE.attach(:title, /Timeclock/)
      ie.close if ie
    end
  end 

You can add additional tests, by defining additional methods to the class whose names begin with ‘test_’ that load the desired scripts.

  1. Test Harness. Create a test harness that executes all of your test scripts. Each of your scripts should include assertions to verify the test results. If you haven’t added assertions to them, now is the time.

Bonus Exercises. If you have time, you may want to try the following:

  1. Record Check. Write another test script. Start with a user that has no time records. Record time sessions for two separate jobs, one session for each. Verify that two time records appear.
  2. Test Strategy. Look over the test ideas you developed in Lab 1. Write a test script for one or more of your ideas.

Solution to Lab 5

See the following for solutions to Lab 5:

  1. solutions/lab5_1.rb
  2. solutions/lab5_2.rb