Extension Step antWrapper
Description
DEPRECATED as native ant tasks are handled transparently. Behaves just like the group step
Parameters
- description
- Required? no
- The description of this test step.
Nested Parameters
- step
- Required? yes
- A webtest step.
Details
The following example illustrates how to use the antWrapper step to invoke an ANT task (in this case loadFile) within a webtest test specification:
<steps>
<antWrapper>
<loadFile property="message" srcFile="message.txt"/>
</antWrapper>
<invoke url="http://mysite/news/"/>
<setInputField name="message" value="${message}/>
</steps>
</webtest>
If you need to test whether your application correctly stores information in a database, you can use the ANT sql task or the SQLUnit task if you have more elaborate requirements. Here is an example using sql:
<antWrapper>
<echo>Using SQL to check precondition: test name doesn't exist</echo>
<sql ... output="items.txt">select * from names</sql>
</antWrapper>
<invoke url="items.txt"/>
<not description="should not be found">
<verifyText text="testvalue"/>
</not>
<invoke url="http://mysite/adduser.jsp"/>
<setInputField name="name" value="testvalue"/>
<clickButton name="add"/>
<antWrapper>
<echo>Using SQL to check name added</echo>
<sql ... output="items.txt">select * from names</sql>
</antWrapper>
<invoke url="items.txt"/>
<verifyText text="testvalue"/>
<antWrapper>
<echo>Using SQL to do post test cleanup (remove test name)</echo>
<sql ...>delete from names where name='testvalue'</sql>
</antWrapper>
</steps>
You can also leave out the antWrapper step if you wish and one will be added for you behind the scenes. You can also experiment with using ANT Macros. Here is an example showing implicit antWrapper usage and Macros. See the ANT documentation for more details on Macros.
<property name="testurl" value="file:///${testfile}"/>
<-- macro containing an ant task -->
<macrodef name="echoMacro">
<attribute name="message" default="X"/>
<sequential>
<echo append="true" message="@{message}" file="${testfile}"/>
</sequential>
</macrodef>
<-- macro containing webtest steps -->
<macrodef name="verifyMacro">
<attribute name="text" default="X"/>
<attribute name="length" default="0"/>
<sequential>
<storeLength property="foundLength"/>
<verifyProperty name="foundLength" text="@{length}"/>
<verifyText text="@{text}"/>
</sequential>
</macrodef>
<target name="testMacros">
<webtest name="antWrapper: test antWrapper with macros">
<steps>
<echoMacro/>
<echoMacro message="Y"/>
<repeat count="2">
<echoMacro message="Z"/>
</repeat>
<echoMacro message="Y"/>
<invoke url="${testurl}"/>
<verifyMacro length="5" text="XYZZY"/>
</steps>
</webtest>
<delete file="${testfile}" quiet="true"/>
</target>