Payload Objects
Oat provides several payload objects that all implement the interface for a PayloadObject
. These objects can be passed into a withPayloads
function. Oat will create individual test for every payload object passed into withPayloads
.
Oat supports the following payloads:
- URL query parameter via
QueryParam
class - URL path parameter via
URLParam
class - Body payload via
BodyPayload
class - Combined payload objects via
CombinedPayload
class
Methods
skip
If called on the object, all test containing this security object will be skipped.
import { Testplan, APIKeyAuth } from 'oat'
const urlParam = new URLParam({ id: '39f07889-1072-48df-8ca6-9d6726b5e525' })
urlParam.skip()
const plan = new Testplan(specification)
plan.runTest('delete', '/api/specifications/{id}')
.withPayloads([urlParam]) // test will be skipped
Payload Object Classes
QueryParam
Extends from PayloadObject
.
A payload object to define query parameters.
import { Testplan, QueryParam } from 'oat'
const queryParam = new QueryParam({
name: 'foobar',
type: 'token'
})
const plan = new Testplan(specification)
plan.runTest('delete', '/api/specifications/{id}')
.withPayloads([queryParam]) // creates a request to "/api/specifications/{id}?name=foobar&type=token"
URLParam
Extends from PayloadObject
.
A payload object to define parameters within the url.
import { Testplan, URLParam } from 'oat'
const urlParam = new URLParam({ id: '39f07889' })
const plan = new Testplan(specification)
plan.runTest('delete', '/api/specifications/{id}')
.withPayloads([urlParam]) // creates a request to "/api/specifications/39f07889"
BodyPayload
Extends from PayloadObject
.
Sets a request body payload. If your request payload is a JSON you can define object properties through the Faker.js API via #/faker/<module>/<type>
, e.g. a field with #/faker/internet/email
will be replaced with a random email.
import { Testplan, BodyPayload } from 'oat'
const jsonBody = new BodyPayload({
type: 'user',
/**
* will be replaced with the value returned by `faker.internet.username()`, e.g. "Nettie_Zboncak40"
*/
name: '#/faker/internet/username',
/**
* will be replaced with the value returned by `faker.date.birthdate()`, e.g. "1977-07-10T01:37:30.719Z"
*/
birthday: '#/faker/date/birthdate'
})
const streamBody = new BodyPayload(Buffer.from('...'))
const plan = new Testplan(specification)
plan.runTest('delete', '/api/specifications/{id}')
.withPayloads([jsonBody, streamBody])
CombinedPayload
Extends from PayloadObject
.
Allows to combine multiple payload objects for a single test, e.g. when an endpoint contains an url parameter and body payload.
import { CombinedPayload, URLParam, BodyPayload } from 'oat'
const jsonBody = new BodyPayload({ some: 'payload' })
const urlParam = new URLParam({ id: '39f07889' })
const combinedPayload = new CombinedPayload([ jsonBody, jsonBody ])