Skip to main content
Version: 1.15

FetchRequest

This API is used for Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare environment or the service to your e2e test. When used on Page or a BrowserContext, this API will automatically use the cookies from the corresponding BrowserContext. This means that if you log in using this API, your e2e test will be logged in and vice versa.

fetchRequest.dispose()#

All responses received through fetchRequest.fetch(urlOrRequest[, options]), fetchRequest.get(urlOrRequest[, options]), fetchRequest.post(urlOrRequest[, options]) and other methods are stored in the memory, so that you can later call fetchResponse.body(). This method discards all stored responses, and makes fetchResponse.body() throw "Response disposed" error.

fetchRequest.fetch(urlOrRequest[, options])#

  • urlOrRequest <string|Request> Target URL or Request to get all fetch parameters from.#
  • options <Object>
    • data <string|Buffer|Serializable> Allows to set post data of the fetch. If the data parameter is an object, it will be serialized the following way:#
      • If content-type header is set to application/x-www-form-urlencoded the object will be serialized as html form using application/x-www-form-urlencoded encoding.
      • If content-type header is set to multipart/form-data the object will be serialized as html form using multipart/form-data encoding.
      • Otherwise the object will be serialized to json string and content-type header will be set to application/json.
    • failOnStatusCode <boolean> Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.#
    • headers <Object<string, string>> Allows to set HTTP headers.#
    • method <string> If set changes the fetch method (e.g. PUT or POST). If not specified, GET method is used.#
    • params <Object<string, string>> Query parameters to be send with the URL.#
    • timeout <number> Request timeout in milliseconds.#
  • returns: <Promise<FetchResponse>>#

Sends HTTP(S) fetch and returns its response. The method will populate fetch cookies from the context and update context cookies from the response. The method will automatically follow redirects.

fetchRequest.get(urlOrRequest[, options])#

Sends HTTP(S) GET request and returns its response. The method will populate fetch cookies from the context and update context cookies from the response. The method will automatically follow redirects.

fetchRequest.post(urlOrRequest[, options])#

  • urlOrRequest <string|Request> Target URL or Request to get all fetch parameters from.#
  • options <Object>
    • data <string|Buffer|Serializable> Allows to set post data of the fetch. If the data parameter is an object, it will be serialized the following way:#
      • If content-type header is set to application/x-www-form-urlencoded the object will be serialized as html form using application/x-www-form-urlencoded encoding.
      • If content-type header is set to multipart/form-data the object will be serialized as html form using multipart/form-data encoding.
      • Otherwise the object will be serialized to json string and content-type header will be set to application/json.
    • failOnStatusCode <boolean> Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.#
    • headers <Object<string, string>> Allows to set HTTP headers.#
    • params <Object<string, string>> Query parameters to be send with the URL.#
    • timeout <number> Request timeout in milliseconds.#
  • returns: <Promise<FetchResponse>>#

Sends HTTP(S) fetch and returns its response. The method will populate fetch cookies from the context and update context cookies from the response. The method will automatically follow redirects.