Ir al Contenido Principal

request

Allows you do modify requests the browser makes during the session. This can be useful for the following use cases:

  • validating if your application sends correct request payloads
  • passing through authorization headers to test protected resources
  • setting session cookies to test user authentication
  • modifying requests to test edge cases
Usage
mock.request({ header, cookies, method, url, header, statusCode, fetchResponse })
Parameters
NameTypeDetails
overwritesMockOverwritepayload to overwrite the response
overwrites.headerRecord<string, string>overwrite specific headers
overwrites.cookiesRecord<string, string>overwrite request cookies
overwrites.methodstringoverwrite request method
overwrites.urlstringoverwrite request url to initiate a redirect
params
optional
MockResponseParamsadditional respond parameters to overwrite
params.header
optional
Objectoverwrite specific headers
params.statusCode
optional
Numberoverwrite response status code
params.fetchResponse
optional
Booleanfetch real response before responding with mocked data
Example
respond.js
it('adds an auth header to my API requests', async () => {
const mock = await browser.mock('https://application.com/api', {
method: 'get'
})

mock.request({
headers: { 'Authorization': 'Bearer token' }
})

await browser.url('https://application.com')
// ...
})

Welcome! How can I help?

WebdriverIO AI Copilot