10.0+50.6 WebAPI scripting API
QF-Test provides a scripting API for sending HTTP(S) requests and validating the responses received during execution of a Web request node.
Scripts placed inside a Pre-request handler node typically operate on a WebRequest object that
is initialized from the currently executing Web request. This object is automatically bound as
qw.request during execution of the Pre-request handler nodes, so scripts can modify parameters
before the request is sent.
When the response is received, it is made available to scripts placed inside a Post-request handler node in
the form of a WebResponse object automatically bound as qw.response.
The implementation is based on the Java package
java.net.http and several of its interfaces are directly exposed as shown below. For
convenience, standard getters and setters were added to WebRequest and
WebResponse enabling simplified script expressions such as qw.request.uri or
qw.response.body.
HTTP headers are also a special case. Typically, they can be treated as a simple key:value map of
strings, but the specification specifies case-insensitive keys and multiple values
per key. The
HttpHeaders class implements that behavior. Again, QF-Test provides access to this
implementation while also offering various convenience methods for scripts that provide direct access to
single-value headers, among other features.
10.0+50.6.1 The QF-Test WebAPI module (qw)
Through qw.request and qw.response this module provides access to the request and
response sent and received during the most recent execution of a Web request. Primary use is during
execution of the Pre-request handler and Post-request handler nodes, but they remain bound even after
the Web request completes to enable analysis of the most recent request and
response in QF-Test's script consoles and to access response values in steps following a Web request.
The qw module also contains the following methods:
10.0+50.6.2 The WebRequest class (qw.request)
The class WebRequest extends
HttpRequest and also implements its own
HttpRequest.Builder, so you can use the methods of both classes directly. These methods are not
documented here; please refer to the official documentation linked above.
For simplified scripting, the QF-Test classes provide alternative getters and setters. They are mostly identical to their counterparts, with two important exceptions:
-
The
getHeaders()method does not return anHttpHeadersobject likeheaders(), but returns a simplifiedMapwith case-insensitive keys and a single value, the last value defined for the given name in the originalHttpHeaders. -
The
get...()methods never return anOptional, but the contained value or a default value - usuallynull- if theOptionalis empty.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
10.0+50.6.3 The WebResponse class (qw.response)
The qw.response object is bound in all scripting languages during execution of a
Post-request handler. It can be used to read and validate response data.
This object remains valid until another Web request is executed, which means it can also be
used in scripts outside the WebAPI nodes.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||