Webtest WebTest GitHub Home

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;".

invoke elements allow for special configuration of the HTTP request using nested httpHeader elements.

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.
contentType
Required? no, default is application/x-www-form-urlencoded
Sets the content-type HTTP header for POST, PATCH, and PUT requests
description
Required? no
The description of this test step.
method
Required? no, default is GET
Sets the HTTP Method. Currently, GET, POST, PUT, DELETE, and PATCH are supported.
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.
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.

Nested Parameters

httpHeader
Required? no
Add additional HTTP Headers to the current invoke.

Details

Here is an example of a normal invoke:

simple 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 with additional request headers defined:

invoke with headers
<invoke description="Get default pageurl="/service/index.jsp" />

<storeCookie name="JSESSIONIDproperty="csrf.session" />
<storeXPath description="Extract CSRF Token"
            xpath="//meta[@name='_csrf']/@content"
            property="csrf.token" />
<storeXPath description="Extract HTTP Header for CSRF"
            xpath="//meta[@name='_csrf_header']/@content"
            property="csrf.header" />

<invoke url="/service?${query.params}
        method="POST
        contentType="application/json"
        content='${content}'>
  <httpHeader name="${csrf.header}value="${csrf.token}" />
  <httpHeader name="Cookievalue="JSESSIONID=${csrf.session}" />
</invoke>

Another httpHeader example performing a SOAP invoke:

Passing SOAPAction HTTP header
<invoke method="POST
        contentFile="AustralianPostcodeByLocationRequest.xml"
        contentType="text/xml; charset=UTF-8"
        url="http://httpwww.webservicex.com/AustralianPostCode.asmx?op=GetAustralianPostCodeByLocation">
  <httpHeader name="SOAPAction
              value="http://www.webserviceX.NET/GetAustralianPostCodeByLocation" />
</invoke>
<verifyText text="Karalee"/>
<verifyText text="QLD"/>
<verifyText text="4306"/>

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

soap input
<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:

soap output
<?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>