Write pre-request scripts and build tests.
pw
objectpw
object provides access to request and response data and variables in your Postdata instance.
The pw
object houses the following methods:
pw.env.set("variable", "value")
pw.env.set()
can be used directly for quick and convenient environment variable definition.
pw.env.set()
to encode and decode strings with Base64:
pw.env.set("variable", atob("value"))
atob()
function to decode a Base64 encoded string and set it as an environment variable.
pw.env.set("variable", btoa("value"))
btoa()
function to encode a regular string into Base64 and set it as an environment variable.
pw.env.unset("variable)
pw.env.unset()
can be used to remove the value of the variable present in the current active environment
pw.env.get("variable")
pw.env.getResolve("variable")
pw.env.resolve("variable")
pw.expect(value)
toBe
on the expectation object that is returned by calling pw.expect
with the response id, pw.response.body.id
as an argument.
Use pw.expect
directly for quick and convenient testing. Every pw.expect
statement will generate a line on the test report.
pw.test(name, function)
pw.test
to the group and describe related statements.
pw.expect
nor a pw.test
statement is present, no test reports will be generated.
pw.toBe(value)
toBe
.
toBe
uses strict equality and is recommended for primitive data types.
pw.not()
.not
before calling the matcher function.
pw.toBeLevelxxx()
toBeLevel2xx()
toBeLevel3xx()
toBeLevel4xx()
toBeLevel5xx()
200
and 299
inclusive to pass toBeLevel2xx()
.
expect()
is a non-numeric value, it is first parsed with parseInt()
.
pw.toBeType(type)
.toBeType(type)
for type checking. The argument for this method should be either of the following string
, boolean
, number
, object
, undefined
, bigint
, symbol
, or function
.
pw.toHaveLength(number)
.toHaveLength(number)
to check that an object has a .length
property and it is set to a certain numeric value.
pw.toInclude(value)
.toInclude(value)
to check that a string/array has a value entry.
pw.response
pw.response
object.
status
: -number- The status code as an integer.headers
: -object- The response headers.body
: -object- the data in the response. In many requests, this is the JSON sent by the server.access_token
and id_token
as part of a JSON response.
idToken
accessToken
<<variableName>>
syntax as usual.