id
with the value of say 123456
. Here is what your test would look like:apic.try
whenever possible as specified below in this document$response
that has below properties.$response {object}
- This is the main response object which is created when the run is complete.body {string}
- The raw string response data received in the response.data {object}
- If the response can be converted to JSON then apic converts it to a JSON object and stores it under the data property of $response
. If the response cant be converted to JSON then $response.data
will be undefined
. If the API response looks like {"msg":"Todo created", "id":"1oFrKEGzoSX2raFHR8xR", "name":"SEo378VnqzdVsCF"}
then you can access name
by using $response.data.name
in your scripts. Same for $response.data.id
and $response.data.msg
.headers {object}
- $response.headers
object holds the list of all headers received in the response as properties and header values as the values for the properties. For example to get the value of Content-Type use $response.headers['Content-Type']
.headersStr {string}
- The raw string of headers received in the response (by default headers are received as a string separated with '\n').status {number}
- The http status code for the response. Ex: 200, 404.statusText {string}
- The http status text for the response. Ex OK, Not foundtimeTaken {number}
- Time taken for the request to complete in milliseconds.timeTakenStr {stri}
- String representation of time taken for the request to complete. Eg: 600 ms.respSize {string}
- String representation of response size. Eg: 20KB
.logs {string[]}
- List of log strings added.$request
variable in your tests. For example the final request url ($request.url
) or the value of a request body ($request.body.todoName
)$request {object}
- The object containing information about the request._id {string}
- The request id of saved requests.name {string}
- Name of the saved request, undefined if request is not saved.url {string}
- This is the final URL to which the request was sent.method {string}
- The HTTP method used to send the request.headers {object}
- An object containing information about the headers that were sent in the request. For exaample if your request have an authorization
header the you can access the value for that in the test with $request.headers['authorization']
queryParams {object}
- An object containing query parameters sent in the requestbody {object/string}
- If your request has a payload body then you can acces that by using $request.body
in your scripts.$request.body
object$request.body
will be a string.name=abcd
then $request.body
will be an object with value {name: "abcd"}
$request.body
will contain both the query
and variables
with properties of same name.$request.body = {query: "<graphql query string>", variables: {...variables json...}}
prescript {string}
- Pre-run script.postscript {string}
- Post-run script.respCodes
- Response schemas saved against each status codes.Test
while accessing it in the $request object you should be using test
like $request.headers['test']
validateSchema()
in yout test scripts to validate if the response is adhering to the specified schema or not. Know more about apic schema validation at https://apic.app/docs/tester/response-schema-validation.html​apic.randomStr(minLength/length, maxLength)
- returns a random string with length between minLength
and maxLength
.If maxLength is not specified the the returned string is exactly of length minLength
. If neither is specified, default 1 character string.apic.randomNum(min, max, isFloat)
- generates a random integer number between the min and max value. Sending the third argument isFloat as true will return float/decimal number.apic.randomEmail()
- generates valid random email id.apic.randomInList(list)
- if you want some random values from a list then you can use this function. This will accept a list of anything and will return one entry from the list randomly. Ex: apic.randomInList([1, 2, 1.111, 'some text', 'etc..'])
.apic.time()
- returns the current timestamp?.
) to read the value of a property located deep within a chain of connected objects without having to check that each reference in the chain is valid. Object.has(property, strictMode)
- This function can be called on any Object to check if the specified property exists in the object ot not. Returns true
or false
. By default the check is done by ignoring the case of the property. If you want to make the check case sensitive pass the second argument strictMode
as true
. This can be useful to check if a specific header is present in the response or notObject.getValue(property, strictMode)
- This function can be called on any Object to get the value of a specific property. By defaulte value is retrived by ignoring the case but to force case sensitive check send the second parameter striceMode as true. This can be useful to het the value of any specific header or getting values from the response data.