Open aboqasem opened 1 month ago
@aboqasem I don't believe the navigator.locales
is settable here. See the thread about setting locales for testing: https://github.com/cypress-io/cypress/issues/7890
Ok thanks. But it's not only locales, the method is not being called at all.
Also I reported two issues here. Any response to the second one?
@aboqasem Can you provide an example of it not running at all? It running no code within there?
It's the same example but with a console.log("hi")
instead of setting locales. The log is ONLY happening when I navigate from within the Cypress app to another URL. The test case alone does NOT produce a log on the website within the Cypress app, which I believe it should be.
it("onBeforeLoad", () => {
cy.log("set localStorage")
.visit("/", {
onBeforeLoad(win) {
win.localStorage.setItem("foo", "bar");
},
})
.its("localStorage.foo", { timeout: 1000 })
// FAILS, `onBeforeLoad` IS NOT BEING CALLED
.should("deep.equal", "bar");
});
This code works when visiting our example site with my running on Chrome 129, Cypress 13.14.2. Is the issue isolated to the URL you are visiting? Or a specific browser?
it("onBeforeLoad", () => {
cy.log("set localStorage")
.visit("https://example.cypress.io", {
onBeforeLoad(win) {
win.localStorage.setItem("foo", "bar");
},
})
.its("localStorage.foo", { timeout: 1000 })
// FAILS, `onBeforeLoad` IS NOT BEING CALLED
.should("deep.equal", "bar");
});
Ok I need to create a reproducible example. I was trying to do so on Codesandbox but couldn't install required dependencies there. Will get back with more info.
May I know if the other issue regarding retry on failure is a valid issue?
Ok I tried again and onBeforeLoad
is working, I've probably missed something previously so that it was not running.
But this is still not working:
describe.only("onBeforeLoad and visit failures", () => {
it.only("failOnStatusCode + retryOnStatusCodeFailure", () => {
cy.visit(
"https://www.cypress.io//non-existing",
// KEEPS RETRYING FOR LONG TIME
// { failOnStatusCode: false },
// KEEPS RETRYING FOR LONG TIME, SHOULD NOT RETRY NOR FAIL
// { failOnStatusCode: false, retryOnStatusCodeFailure: false },
// CypressError: These options are incompatible with each other.
// - To retry on non-2xx status codes, pass { failOnStatusCode: true, retryOnStatusCodeFailure: true }.
// - To not retry on non-2xx status codes, pass { failOnStatusCode: true, retryOnStatusCodeFailure: true }.
// - To fail on non-2xx status codes without retrying (the default behavior), pass { failOnStatusCode: true, retryOnStatusCodeFailure: false }
// { failOnStatusCode: false, retryOnStatusCodeFailure: true },
// MAKES THE TEST FAIL
// {},
{ failOnStatusCode: true },
// { failOnStatusCode: true, retryOnStatusCodeFailure: false },
// { failOnStatusCode: true, retryOnStatusCodeFailure: true },
)
.url({ timeout: 1000 })
.should("eq", "https://www.cypress.io/");
});
});
Current behavior
onBeforeLoad
not running andfailOnStatusCode + retryOnStatusCodeFailure
has weird behaviour.Desired behavior
1. To be able to run code before page load.To have correct behaviour for
{ failOnStatusCode: false, retryOnStatusCodeFailure: false }
.Error message should be fixed.
Test code to reproduce
Cypress Version
13.15.0
Node version
18.17.1
Operating System
macOS 14.6.1
Debug Logs
No response
Other
No response