Hierarchy

  • Ability
    • UseAPI

Properties

alias?: string
name: string

Name with which the ability is identified internally on actor level.

Methods

  • Verify if the given body is equal or unequal to the given response's body.

    Parameters

    • response: Response

      the response to check.

    • body: ResponseBodyType

      the body to check.

    • mode: "equal" | "unequal"

      the result to check for.

    Returns Promise<boolean>

    true if the body equal/unequal as expected.

    Example

    // json response
    UseApi.as(actor).checkBody(response, { text: 'test' }, 'equal');
    // text response
    UseApi.as(actor).checkBody(response, 'test', 'unequal');
    // buffer response
    UseApi.as(actor).checkBody(response, Buffer.from('abc'), 'equal');
  • Verify if the reponse (including receiving body) was received within a given duration or not.

    Parameters

    • response: Response

      the response to check

    • duration: number

      expected duration (in milliseconds) not to be exceeded

    • mode: "lessOrEqual" | "greater"

      the result to check for.

    Returns Promise<boolean>

    true if response was received within given duration, false otherwise

    Example

    // check if response was received within 2s
    UseApi.as(actor).checkDuration(response, 2000, 'lessOrEqual');
  • Verify if the given headers are included/excluded in the given response. (headers should be a subset of response.headers)

    Parameters

    • response: Response

      the response to check.

    • headers: {
          [key: string]: string | undefined;
      }

      the headers to check.

      • [key: string]: string | undefined
    • mode: "included" | "excluded"

      the result to check for.

    Returns Promise<boolean>

    true if the headers are is included/excluded as expected.

    Example

    // check only keys
    UseApi.as(actor).checkHeaders(response, { contentType: undefined }, 'included');
    // check key and value
    UseApi.as(actor).checkHeaders(response, { contentType: 'application/json' }, 'excluded');
  • Verify if the given status is equal or unequal to the given response's status.

    Parameters

    • response: Response

      the response to check.

    • status: number

      the status to check.

    • mode: "equal" | "unequal"

      the result to check for.

    Returns Promise<boolean>

    true if the status is equal/unequal as expected.

    Example

    UseApi.as(actor).checkStatus(response, 200, 'equal');
    
  • Get the request context object

    Returns APIRequestContext

    requestContext the api request context

  • Send a HTTP request (GET, POST, PATCH, PUT, HEAD or DELETE) to the specified url. Headers and data can also be sent.

    Parameters

    • method: RequestMethod

      GET, POST, PATCH, PUT, HEAD or DELETE.

    • url: string

      the full URL to the target.

    • Optional headers: any

      (optional) the headers object.

    • Optional responseFormat: ResponseBodyFormat

      (optional) specify the desired format the response body should be in.

    • Optional data: any

      (optional) the data to be sent.

    Returns Promise<Response>

    Promise a Response object consisting of status, body and headers.

    Example

    UseApi
    .as(actor)
    .sendRequest(
    REQUEST_METHOD.POST,
    '/items', { authorization: 'Bearer dfh.dasgeq65qg.eyjkhf' },
    'json', { title: 'new item' });
  • Parameters

    • name: string

    Returns this

  • Use the Ability as an Actor. Used by Actions to get access to the ability functions.

    Parameters

    • actor: Actor

      the actor object

    Returns UseAPI

    UseAPI the actor with the ability to use the API

  • Initialize this Ability by passing an already existing Playwright APIRequestContext object.

    Parameters

    • requestContext: APIRequestContext

      the Playwright APIRequestContext that will be used to send REST requests.

    Returns UseAPI

    UseApi object

Generated using TypeDoc