W3cubDocs

/CodeceptJS

REST

Extends Helper

REST helper allows to send additional requests to the REST API during acceptance tests. Unirest library is used to perform requests.

Configuration

  • endpoint: API base URL
  • timeout: timeout for requests in milliseconds. 10000ms by default
  • defaultHeaders: a list of default headers
  • resetHeaders: set to true to reset headers between requests. Disabled by default
  • followRedirect: set to true to enable automatic redirect. Disabled by default

Parameters

  • config

_cleanRequestHeaders

Changes headers to default if reset headers option is true

_executeRequest

Executes unirest request

Parameters

  • request any

_url

Generates url based on format sent (takes endpoint + url if latter lacks 'http')

Parameters

  • url any

amFollowingRequestRedirects

Set response auto-redirects ON

I.amFollowingRequestRedirects(); // To enable auto-redirects

amNotFollowingRequestRedirects

Set response auto-redirects OFF

I.amNotFollowingRequestRedirects(); // To disable auto-redirects

haveRequestHeaders

Set headers for the request

I.haveRequestHeaders({
   'Accept': 'application/json',
   'User-Agent': 'Unirest Node.js'
});

Parameters

  • customHeaders any

resetRequestHeaders

Reset headers for the request to default state

I.resetRequestHeaders();

sendDeleteRequest

Sends DELETE request to API.

I.sendDeleteRequest('/api/users/1');

Parameters

  • url any
  • headers object (optional, default {})

sendGetRequest

Send GET request to REST API

I.sendGetRequest('/api/users.json');

Parameters

  • url any
  • headers object (optional, default {})

sendPatchRequest

Sends PATCH request to API.

I.sendPatchRequest('/api/users.json', { "email": "user@user.com" });

Parameters

sendPostRequest

Sends POST request to API.

I.sendPostRequest('/api/users.json', { "email": "user@user.com" });

Parameters

  • url any
  • payload any (optional, default {})
  • headers object (optional, default {})

sendPutRequest

Sends PUT request to API.

I.sendPutRequest('/api/users.json', { "email": "user@user.com" });

Parameters

setRequestTimeout

Set timeout for the request

I.setRequestTimeout(10000); // In milliseconds

Parameters

  • newTimeout

© 2015 DavertMik <davert@codegyre.com> (http://codegyre.com)
Licensed under the MIT License.
https://codecept.io/helpers/REST/