Trying to apply Intercept in the webdriverIO test use WDIO CLI (testrunner)
describe('Main flow for order', () => {
if (browser.isChrome) {
it('should login with valid credentials', async () => {
await browser.url(`/`);
await browser.setupInterceptor()
await browser.expectRequest('GET', 'https://master.k.sollerstr.ru/api/orders/summary', 200);
await $('input[type="text"]').setValue('user@****.com');
await $('input[type="password"]').setValue('****');
await $('.el-button_primary').click();
// await browser.assertRequests();
await browser.assertExpectedRequestsOnly();
});
}
})
I know that this request is processed after clicking the button,because I have written a similar test in Cypress and it catches this api but i have error after run the test in my webdriverIO project: What am I doing wrong. Use webdriverIO Intercept Service.
2021-12-13T19:54:53.126Z INFO webdriver: COMMAND elementClick("f4a2ea9c-737b-4893-bffa-3263d5d2cf22")
[1-0] 2021-12-13T19:54:53.126Z INFO webdriver: [POST] http://localhost:4444/session/c96a4af66042283314f35b1ed3e00746/element/f4a2ea9c-737b-4893-bffa-3263d5d2cf22/click
[1-0] 2021-12-13T19:54:53.162Z INFO webdriver: COMMAND assertExpectedRequestsOnly()
[1-0] 2021-12-13T19:54:53.162Z INFO webdriver: COMMAND executeScript(<fn>, <object>)
[1-0] 2021-12-13T19:54:53.162Z INFO webdriver: [POST] http://localhost:4444/session/c96a4af66042283314f35b1ed3e00746/execute/sync
[1-0] 2021-12-13T19:54:53.163Z INFO webdriver: DATA {
[1-0] script: 'return (function getRequest(index, options) {\n' +
[1-0] " var NAMESPACE = '__webdriverajax';\n" +
[1-0] " var PKG_PREFIX = '[wdio-intercept-service]: ';\n" +
[1-0] '\n' +
[1-0] ' function getFromSessionStorage() {\n' +
[1-0] ' var rawData = window.sessionStorage.getItem(NAMESPACE);\n' +
[1-0] ' var parsed;\n' +
[1-0] ' if (rawData) {\n' +
[1-0] ' try {\n' +
[1-0] ' parsed = JSON.parse(rawData);\n' +
[1-0] ' } catch (e) {\n' +
[1-0] ' throw new Error(\n' +
[1-0] " PKG_PREFIX + 'Could not parse sessionStorage data: ' + e.message\n" +
[1-0] ' );\n' +
[1-0] ' }\n' +
[1-0] ' }\n' +
[1-0] ' return parsed;\n' +
[1-0] ' }\n' +
[1-0] ' function getAllRequests() {\n' +
[1-0] ' // Session storage will always return an array that can be mutated freely.\n' +
[1-0] ' if (window.sessionStorage && window.sessionStorage.getItem) {\n' +
[1-0] ' return getFromSessionStorage() || [];\n' +
[1-0] ' }\n' +
[1-0] ' // But if we have to use the active namespace array, then return a copy of it.\n' +
[1-0] ' var shouldClone = window[NAMESPACE].requests;\n' +
[1-0] ' return shouldClone ? shouldClone.slice() : [];\n' +
[1-0] ' }\n' +
[1-0] ' function isComplete(r) {\n' +
[1-0] " return typeof r.__fulfilled === 'number';\n" +
[1-0] ' }\n' +
[1-0] '\n' +
[1-0] ' var requests = getAllRequests();\n' +
[1-0] '\n' +
[1-0] " var shouldSortByEnd = String(options.orderBy).toUpperCase() !== 'START';\n" +
[1-0] ' if (shouldSortByEnd) {\n' +
[1-0] ' // Sort ascending by time of fulfillment. If not fulfilled yet, sort to the end!\n' +
[1-0] ' requests.sort(function (a, b) {\n' +
[1-0] ' var hasA = isComplete(a);\n' +
[1-0] ' var hasB = isComplete(b);\n' +
[1-0] ' if (hasA && hasB) return a.__fulfilled - b.__fulfilled;\n' +
[1-0] ' if (hasA) return -1; // Only A is fulfilled, so order A before B\n' +
[1-0] ' if (hasB) return 1; // Only B is fulfilled, so order A after B\n' +
[1-0] ' return 0; // Preserve ordering of A & B.\n' +
[1-0] ' });\n' +
[1-0] ' }\n' +
[1-0] '\n' +
[1-0] ' var includePending = Boolean(options.includePending);\n' +
[1-0] ' if (index == null) {\n' +
[1-0] ' return includePending ? requests : requests.filter(isComplete);\n' +
[1-0] ' }\n' +
[1-0] '\n' +
[1-0] ' if (!includePending) {\n' +
[1-0] ' // Filter out the pending requests and index only into the completed requests.\n' +
[1-0] ' return requests.filter(isComplete)[index];\n' +
[1-0] ' }\n' +
[1-0] ' return requests[index];\n' +
[1-0] ' }).apply(null, arguments)',
[1-0] args: [ undefined, {} ]
[1-0] }
[1-0] 2021-12-13T19:54:53.169Z INFO webdriver: RESULT []
[1-0] Error in "Main flow for order.should login with valid credentials"
Error: Expected request was not found. method: GET url: https://master.k.sollerstr.ru/api/orders/summary statusCode: 200
at /home/pavel/WebstormProjects/new_design/node_modules/wdio-intercept-service/index.js:213:15
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Browser.wrapCommandFn (/home/pavel/WebstormProjects/new_design/node_modules/@wdio/utils/build/shim.js:131:29)
[1-0] 2021-12-13T19:54:53.170Z INFO webdriver: COMMAND deleteSession()
[1-0] 2021-12-13T19:54:53.170Z INFO webdriver: [DELETE] http://localhost:4444/session/c96a4af66042283314f35b1ed3e00746
[1-0] FAILED in chrome - /test/testwd2.js