Canoo Webtest WebTest Canoo

Core Step invoke

Description

This step executes a request to a particular URL.

If the URL starts with a protocol (e.g. http://...) then the URL is treated is being fully qualified and invoked directly. Otherwise, the URL is treated as a relative suffix and the URL to invoke is determined from the settings specified with the config element, including port, protocol and basepath.

The result of the request is internally stored and its contents can be verified with one or more <verify...> steps. If the saveresponse option in the config element is enabled, the result (HTML source) will be written to a file for later viewing.

Note: If the URL contains an ampersand character (&), e.g. for parameter separation, it must be expressed using the XML element notion with "&amp;".

Parameters

url
Required? yes
A complete URL or the 'relative' part of an URL which will be appended to the 'static' parts created from the configuration information defined with the <config> step.
content
Required? no
Form data in 'application/x-www-form-urlencoded' format, which will be sent in the body of a POST request. Ignored for GET requests. Only one of content and contentFile should be set.
contentFile
Required? no
Filename to extract request contents from. Ignored for GET requests. Only one of content and contentFile should be set.
description
Required? no
The description of this test step.
method
Required? no, default is GET
Sets the HTTP Method, i.e. whether the invoke is a GET or POST.
password
Required? no
A password that can be provided for pages that require basic authentication. Required if username is specified.
save
Required? no
A shorthand: save='prefixName' is the same as savePrefix='prefixName' saveResponse='true'.
savePrefix
Required? no, default is the 'savePrefix' parameter as specified in <config>.
A name prefix can be specified for making a permanent copy of received responses. A unique number and the file extension (depending on the MIME-Type) will be appended. The resultpath attribute of the <config> element is used for determining the location of the saved result.
saveResponse
Required? no
Whether to make a permanent copy of received responses. Overrides the default value set in the <config> element.
soapAction
Required? no
If the HTTP method is POST and is in fact a SOAP POST request, this allows the SOAP Action header to be set. Ignored for GETs.
username
Required? no
A username that can be provided for pages that require basic authentication. Typically only needed on the first step of any webtest accessing a secure site. Required if password is specified.

Inline Text

The inline text is all the text between the start tag ( <invoke> ) and the end tag ( </invoke> ), including blanks, tabs or newlines. Using a pair of start/end tags ( <invoke> </invoke> ) has not the same behavior than the seemingly equivalent empty element tag ( <invoke/> )! See this issue for an example.

Required? no
An alternative way to set the 'url' or the 'content' attribute. When the 'url' attribute is not specified the nested text is considered as the url value. Otherwise this is used to set the 'content' attribute for e.g. large content (properties get evaluated in this content).

Details

Here is an example of a normal invoke:

invoke
<webtest name="Visit all pages without update">
  <config ... />
  <steps>
    <invoke  description="Start the main controller"
      url="KycController?partnerId=012345678912&amp;portal=RM"
      save="myResultPage"/>
    ...
  </steps>
</webtest>

Here is an example of a SOAP invoke:

invoke
<steps>
    <invoke method="POSTcontentFile="AustralianPostcodeByLocationRequest.xml"
        soapAction="http://www.webserviceX.NET/GetAustralianPostCodeByLocation"
        url="http://httpwww.webservicex.com/AustralianPostCode.asmx?op=GetAustralianPostCodeByLocation"/>
    <verifyText text="Karalee"/>
    <verifyText text="QLD"/>
    <verifyText text="4306"/>
</steps>

Note: the soapAction attribute is only needed for SOAP Web Service requests. For RESTful web services or to do an invoke of a tricky form normally submitted through JavaScript you can leave it out.

Here is what the AustralianPostcodeByLocationRequest.xml file contents might look like:

invoke
<soap:Envelope
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetAustralianPostCodeByLocation
        xmlns="http://www.webserviceX.NET">
      <Location>Karalee</Location>
    </GetAustralianPostCodeByLocation>
  </soap:Body>
</soap:Envelope>

And the result might look something like:

invoke
<?xml version="1.0encoding="utf-8"?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetAustralianPostCodeByLocationResponse
    xmlns="http://www.webserviceX.NET">
<GetAustralianPostCodeByLocationResult>
&lt;NewDataSet&gt;
  &lt;Table&gt;
    &lt;Location&gt;Karalee&lt;/Location&gt;
    &lt;PostCode&gt; QLD 4306&lt;/PostCode&gt;
  &lt;/Table&gt;
&lt;/NewDataSet&gt;
</GetAustralianPostCodeByLocationResult>
</GetAustralianPostCodeByLocationResponse>
</soap:Body>
</soap:Envelope>

news

Latest build: R_1823
Posted: 20-Feb-2013 12:26

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