@luminati-io/webdriverio8
Version:
Next-gen browser and mobile automation test framework for Node.js
57 lines (52 loc) • 2.67 kB
JavaScript
export {};
/**
* Only respond once with given overwrite. You can call `respondOnce` multiple
* consecutive times and it will start with the respond you defined last. If you
* only use `respondOnce` and the resource is called more times a mock has been
* defined than it defaults back to the original resource.
*
* <example>
:respondOnce.js
async function getToDos () {
await $('#todo-list li').waitForExist()
return $$('#todo-list li').map(el => el.getText())
}
it('should demonstrate the respondOnce command', async () => {
const mock = await browser.mock('https://todo-backend-express-knex.herokuapp.com/', {
method: 'get'
})
mock.respondOnce([{
title: '3'
}, {
title: '2'
}, {
title: '1'
}])
mock.respondOnce([{
title: '2'
}, {
title: '1'
}])
mock.respondOnce([{
title: '1'
}])
await browser.url('https://todobackend.com/client/index.html?https://todo-backend-express-knex.herokuapp.com/')
console.log(await getToDos()) // outputs [ '3', '2', '1' ]
await browser.url('https://todobackend.com/client/index.html?https://todo-backend-express-knex.herokuapp.com/')
console.log(await getToDos()) // outputs [ '2', '1' ]
await browser.url('https://todobackend.com/client/index.html?https://todo-backend-express-knex.herokuapp.com/')
console.log(await getToDos()) // outputs [ '1' ]
await browser.url('https://todobackend.com/client/index.html?https://todo-backend-express-knex.herokuapp.com/')
console.log(await getToDos()) // outputs actual resource response
})
* </example>
*
* @alias mock.respondOnce
* @param {MockOverwrite} overwrites payload to overwrite the response
* @param {MockResponseParams=} params additional respond parameters to overwrite
* @param {Object=} params.header overwrite specific headers
* @param {Number=} params.statusCode overwrite response status code
* @param {Boolean=} params.fetchResponse fetch real response before responding with mocked data
*/
// actual implementation is located in packages/webdriverio/src/utils/interception
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVzcG9uZE9uY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY29tbWFuZHMvbW9jay9yZXNwb25kT25jZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBcURHO0FBQ0gsa0ZBQWtGIn0=