[Webtest] ScriptStep custom task added to Community Site

Paul King webtest@lists.canoo.com
Tue, 10 Aug 2004 15:15:42 +1000


 From the description:

This custom step provides a wrapper around the ANT script task which 
makes it easier to invoke scripting and make use of it within your 
steps. Before providing the supplied script to the ANT script task, 
scriptStep expands any webtest dynamic properties. Results from running 
the script can be made available for subsequent steps to use.

The ANT script task is powered by the Bean Scripting Framework (BSF) 
which supports languages such as Javascript, Jython, Tcl, NetRexx, XSLT 
Stylesheets, Java, Ruby, Groovy, ObjectScript and others. Note: You need 
to copy additional JARs into your environment depending on the languages 
you wish to use. See ANT and BSF documentation for details.

I imagine that the principal language used will be Javascript (and you 
can do things like "new java.util.Date()" straight from JavaScript. To 
support JavaScript you need to include bsf.jar and js.jar (should 
already be there) in your classpath. You can get bsf.jar from the Apache 
site if you are using ANT > 1.6 but for ANT 1.5.x you need to get the 
IBM version of bsf.jar which is no longer supported by IBM but can be 
found in downloads such as Xalan-J.

Here is an example (which makes use of another custom step - see website 
for details):

<target name="testScript" depends="init">
<property name="image_id" value="traffic_light"/>
<testSpec name="testScript">
     <invoke stepid="Load Initial Page" url="/"/>
     <storexpath stepid="check image name"
       xpath="//img[@id='${image_id}']/@src" property="imagename"/>
     <scriptStep stepid="calculate alt text" language="javascript">
       name = "#{imagename}";
       var alttext = new Array();
       alttext["red.gif"] = "stop";
       alttext["orange.gif"] = "wait";
       alttext["green.gif"] = "go";
       project.setProperty("altvalue", alttext[name]);
         stepid="make dynamic" to="dyn_altvalue" from="altvalue" />
     <verifyxpath stepid="check alt value"
       text="#{dyn_altvalue}" />