[Webtest] New step: "sleep"

Scot Hale webtest@lists.canoo.com
Fri, 02 May 2003 13:52:03 -0700


This is very nice, and I think it is a very nice example of how to extend 
canoo webtest.

Alternatively, I think there might be a way to have the TestSpec inherit the 
Ant "sleep" task.  This would be nice.

Unfortunately I am not sure exactly how to inherit the core tasks.  I will 
start looking, but if anyone else knows I would appreciate the help.

Scot Hale

----Original Message Follows----
From: John Willemin <jjw@templarcorp.com>
Reply-To: webtest@lists.canoo.com
To: webtest@lists.canoo.com
Subject: [Webtest] New step: "sleep"
Date: Fri, 02 May 2003 16:41:16 -0400

Hey - Been using Canoo for about a week now and there was something I had to 
add in order to test our webapp. So in the spirit of open source, I'm 
throwing it out for criticism and in the hopes someone else will find it 

In our web application, a person runs a query, and these queries always take 
2 minutes to complete. So rather than aimlessly refresh for 2 minutes, I 
just wanted to write a sleep task to have the tests wait until the query 
would be complete. So, here it is. It gets called like this:

                 <sleep stepid="wait for completion"
                     sleepTime="20000" />

Where sleepTime is the amount of time to sleep, in milliseconds. It probably 
makes more sense to have that in seconds, and sleepTime could be renamed 
"seconds" to make things more intuitive. That's easy to change, so if that's 
better, I can send out "version 2" :)

Tell me what you think. It might be that I'm the only person who finds this 


Changes to TestStepSequence.java - I just had to add this:

     public void addSleep(Sleep step) {


package com.canoo.webtest.steps;

import com.canoo.webtest.engine.Context;
import com.canoo.webtest.engine.StepExecutionException;

import java.util.HashMap;

  *  The sleep task is pretty simple. All it does is call Thread.sleep() for 
a specified time so that your webapp
  *   can finish what it's doing.
  * @author John Willemin
public class Sleep
     extends Step

      * This is how long we're sleeping for. Has to be an object, can't be a 
primitive, since it's getting put
      *  into a HashMap later.
     private Integer fSleepTime = null;

     public void setSleepTime(String sleepTime)
         fSleepTime = new Integer( Integer.parseInt( sleepTime ) );

     public void doExecute(Context context)
         throws StepExecutionException
         logText(context, " sleeping for " + fSleepTime.intValue() );

             Thread.sleep( fSleepTime.longValue() );
         catch( InterruptedException ie )
             // can't do much here

     public void expandProperties()

     protected void verifyParameters()
         if(fSleepTime == null)
             throw new StepExecutionException("Attribute sleepTime must be 

      * Collect parameters for reporting. Our our parameters to the ones 
      * from super.
      * @return a HashMap containing paramter names (key) and their 
      * values
     public HashMap getParameterDictionary()
          HashMap map = super.getParameterDictionary();
          if(fSleepTime != null)
              map.put("sleepTime", fSleepTime);
          return map;

WebTest mailing list

Protect your PC - get McAfee.com VirusScan Online