Webtest WebTest GitHub Home

Core Step storeResponseCode

Description

Provides the ability to store the HTTP Response Code value for later checking.

Normally, you can safely ignore HTTP response codes while using webtest. Any response other than '200' automatically triggers a test failure.

Sometimes however, it is useful to retrieve the response code, e.g. to distinguish between server errors (typically code '500'), missing resources (code '404') and security issues (typically codes 401 or 403). Or perhaps to verify the messages which these kind of errors display to the user. This step allows you to achieve this requirement. In order for webtest to forward non-'200' status codes as an error, you need to set an HtmlUnit option (see below).

Parameters

property
Required? yes
The name of the property in which to store the Response Code value.
description
Required? no
The description of this test step.
propertyType
Required? no, default is the "defaultPropertyType" as specified in the "config" element is used.
The type of the property in which to store the retrieve value. Either "ant" or "dynamic".

Details

NOTE: the ThrowExceptionOnFailingStatusCode option setting in the config element needs to be set to false. You don't need to set this option if you want to test for return status codes of '200' but if the step doesn't fail, you already know it is a '200' status code.

For these reasons, it is considered bad practice to store and check response code = 200.

storeResponseCode Example
<webtest name="httpResponseCode: confirm error page">
    <config ...>
        <option name="ThrowExceptionOnFailingStatusCodevalue="false"/>
    </config>
    <steps>
        <invoke description="Load Imageurl="missing.gif"/>
        <storeResponseCode description="store response codeproperty="status" />
        <verifyProperty description="should be errorname="statustext="404"/>
    </steps>
</webtest>