Canoo Webtest WebTest Canoo

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:

antWrapper simple example
<webtest>
  <steps>
    <antWrapper>
      <loadFile property="messagesrcFile="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 macro example
<steps>
  <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="namevalue="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.

antWrapper macro example
    <property name="testfilelocation="antWrapperDummy.txt"/>
    <property name="testurlvalue="file:///${testfile}"/>

    <-- macro containing an ant task -->
    <macrodef name="echoMacro">
        <attribute name="messagedefault="X"/>
        <sequential>
            <echo append="truemessage="@{message}file="${testfile}"/>
        </sequential>
    </macrodef>

    <-- macro containing webtest steps -->
    <macrodef name="verifyMacro">
        <attribute name="textdefault="X"/>
        <attribute name="lengthdefault="0"/>
        <sequential>
            <storeLength property="foundLength"/>
            <verifyProperty name="foundLengthtext="@{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="5text="XYZZY"/>
            </steps>
        </webtest>
        <delete file="${testfile}quiet="true"/>
    </target>

news

Latest build: development
Posted: 19-Jul-2016 17:36

WebTest 3.0 released, featuring upgrades to Java 5, Groovy 1.6, and HtmlUnit 2.4.
The release includes support for maven integration, IDE-integration like for unit tests, capturing of background JavaScript errors, new steps for mouseOver and mouseOut events, better parallel execution of tests and - as usual - lots of handling improvements.
Posted: 5 March 2009

WebTest @ JavaOne
Dierk König presented "Functional testing of web applications: scaling with Java" on Wed May 7, 13:30 at JavaOne 2008 in the Tools and Scripting Languages track.
Posted: 8 May 2008

New WebTest screencast available:
Data Driven WebTest
Posted: 13 November 2007

First WebTest screencast available:
Creating a first Webtest Project

Extend WebTest with Groovy! Groovy in Action is available in every good bookstore.
Groovy in Action
Posted: 29 January 2007