New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not clear how to create wrapper and fail test with browser.mock #910
Comments
If you want to create a command, then yes, browser command can only resolve and reject, and resolved command can't reject afterwards. With webdriverio mock callbacks, i can offer you this approach:
In code, it would look like this: // .testplane.conf.ts
browser.mockRestoreAll()
module.exports = {
plugins: {
'@testplane/global-hook': {
beforeEach: async ({browser}) => {
const networkSpy = await browser.mock("**"); // create network spy
networkSpy.on('match', async ({statusCode, url}) => {
if (statusCode === 404) {
await browser.setMeta("notFoundUrl", url); // set meta property to check if in afterEach
// Note: we can't reject or throw errors inside "on" callback, because it would produce unhandled rejection
}
});
},
afterEach: async ({browser}) => {
await browser.mockRestoreAll(); // unsubscribe to browser mocks
const notFoundUrl = await browser.getMeta("notFoundUrl");
if (notFoundUrl) {
// but we can throw an error here
throw new Error("Not found at " + url);
}
}
},
// other testplane plugins
},
// other testplane settings...
}; As i mentioned, we can't throw errors inside of If you want to, you can overwrite
We can't tell if network request was called because of click. Click itself could be the reason and could not be the reason of that network request. Even wrapping With the url part, i can offer you It would wait for page to load and check for network errors. Notice how you still need to specify |
I am closing it due to inactivity. |
Verify latest release
Hermione version
8.0.4
Last Hermione version that worked
No response
Which area(s) of Hermione are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue or a replay of the bug
No response
Reproduction steps
I want to create custom command for browser.mock
The problem is that its not clear how to make it work.
Actual Behavior
In webdriverio docs there is one example. And as far as I understand they waiting for all requests are done and only after that they can be sure that mock.on will be called. But its very strange logic. What if i click to button in my test after page load and request will be 404. then this command will no work (e.g. it will not fail test). And with this logic we need to create mock every time we making some actions and not at the top level of test how I understand it, e.g
One more thing that looks strange to me is that statusCode handled separately. So if we want to mock request with some data and change status Code then we need to duplicate logic
Expected Behavior
I just want to get how to fail test if mock.respond returns error.
Which Node.js version are you using?
18.12.1
The text was updated successfully, but these errors were encountered: