Scripting Web Tests
Lab 3: Writing Scripts
Now that you’ve used IRB to drive Internet Explorer, it is time to create a script. Actually, you’ll create several. Create each script using Scite, the ruby editor. You may wish to try the commands in IRB first, to make sure they are right.
There are three ways to run scripts:
- The simplest method is to type F5 while editing the script in
Scite. This will save the file and then execute it. The output will
be displayed in a side window.
- A second method is to run a script from the system command
line. Type “ruby script-name.rb” at the DOS prompt. (Actually, just
“script-name.rb” usually works too.) This is the most
reliable method. Use it you are having trouble using F5 in Scite.
- A third method is to load the script into IRB. Type “load
‘script-name.rb’” at the IRB prompt. The advantage of this method is
that you can interact with the IE Controller
after the script has run, using the Watir::IE.attach() method. This
gives you a method for debugging your
scripts.
When you automate tests, you need to be able to repeat tests much more precisely than when you are testing manually. The ‘ensure_no_user_data’ method has been specifically provided as a testability feature for timeclock. You may find it useful.
Create and execute scripts for each of the following procedures. As you complete each script, demonstrate it to your instructors.
- Start The Day. Log in and navigate to the main time
clock page, and then start the day.
- Start, Stop and Pause. Start, stop, pause, and
restart a job. Choose a suitable order for these actions.
- Job Switching. Creates two jobs and then switch
back and forth between them every few seconds.
Solution to Lab 2
See solutions/lab2.rb for an example of a solution to Lab 2 converted to a script.