# Scripting Web Tests

with Watir and Ruby

Workbook / Labs / 5. Making Assertions

## Lab 5: Assertions

Printing out test results works well when you are automating one test, but printing out PASS or FAIL is no longer an effective testing strategy when running multiple tests. You need your tests to know for themselves whether they pass or fail. The way to do this is with assertions. Assertions directly check a value. If it’s as expected, nothing happens. When it isn’t, an exception is raised, which terminates the script. When we add the tests to a harness, any test failures will automatically be collected and reported.

Several assertion methods are included in the Watir Cheat Sheet. You may also want to refer to the complete Assertions Library Reference.

Update your existing scripts to use assertions.

1. Start The Day. Use assertions to verify that the day was started and the background job is running.
2. Start, Stop and Pause. Start, stop, pause, and restart a job. Use assertions to verify that each action worked correctly.

### Solutions to Lab 4

See the following for solutions to Lab 4:

1. solutions/lab4_1.rb
2. solutions/lab4_2.rb