Load Testing Example
Below is a complete example and re-usable method which allows existing Watir scripts/test to be executed concurrently to simulate a load or performance test.
| |
Name |
Size |
Creator |
Date |
Comment |
|
 |
googleSearch.rb |
0.8 kb |
David Brown |
Mar 15, 2007 |
Example script file for load test (uses Watir::IE.new_process)
|
|
 |
LoadTester.rb |
3 kb |
David Brown |
Mar 15, 2007 |
Runs a given test Script for a given number of iterations using a specified number of users or threads, with a specific delay between users. Results are logged to a log file.
|
|
Example Usage
#Here we are going to run 5 itterations of the 'googleSearch.rb' script with four concurent threads/users, using a 2 second delay between the start of each user.
#We will save/append the results to a file: 'myLoadTest.log'
loadTestRunner(Dir.pwd + '/googleSearch.rb',5,4,2,Dir.pwd + '/myLoadTest.log')
Sample Output
*********************************
**Load Test Configuration: numItterations=5, numUsers=4, delayBetweenUsers=2 seconds.
**Begining Itteration 1 - 03/15/07 @ 08:42:14
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 10.359seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 8.593seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 10.797seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 15.249seconds
**Finished Itteration 1. 4 out of 4 tests Passed - 03/15/07 @ 08:42:30
**Begining Itteration 2 - 03/15/07 @ 08:42:30
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 10.719seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 10.485seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 9.782seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 8.86seconds
**Finished Itteration 2. 4 out of 4 tests Passed - 03/15/07 @ 08:42:44
**Begining Itteration 3 - 03/15/07 @ 08:42:44
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 9.406seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 16.093seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 15.562seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 15.171seconds
**Finished Itteration 3. 4 out of 4 tests Passed - 03/15/07 @ 08:43:04
**Begining Itteration 4 - 03/15/07 @ 08:43:04
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 15.172seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 11.625seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 16.313seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 18.047seconds
**Finished Itteration 4. 4 out of 4 tests Passed - 03/15/07 @ 08:43:26
**Begining Itteration 5 - 03/15/07 @ 08:43:26
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 22.125seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 19.546seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 23.953seconds
Thread 4 executed T:/Dev/googleSearch.rb Successfully - Duration = 23.0seconds
**Finished Itteration 5. 4 out of 4 tests Passed - 03/15/07 @ 08:43:53
**Load Test complete. 20 out of 20 tests Passed
Script File Requirements
When using this loadTestRunner() method to run a Watir test script concurrently, it is highly recommended that one uses the Watir::IE.new_process method when obtaining an IE instance. This will cause the scripts to be executed using separate IE processes which prevents the scripts from sharing session variables.
Watir::IE.new_process began shipping with watir version '1.5.1.1100' available here: 'http://wiki.openqa.org/display/WTR/Development+Builds'
Here's an example of using Watir::IE.new_process:
require 'watir'
require 'watir/contrib/ie-new-process'
ie = Watir::IE.new_process
ie.goto('google.com')
Note: Some complex web applications which rely on cookies may not work properly when tested concurrently even when using separate IE processes because all the IE processes share the same cookies. I don't know of a work-around for this at this time.
You can use
numUsers.times do |i|
instead of
numUser.times do
that way 'i' is automatically initialized and incremented.