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.
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.
Comments (1)
Jul 09, 2008
Alister Scott says:
You can use numUsers.times do |i| instead of numUser.times do that way 'i'...You can use
numUsers.times do |i|
instead of
numUser.times do
that way 'i' is automatically initialized and incremented.