-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Prevent/Stub network request #1370
Comments
Similar situation, I think: I ended up blacklisting the host in my cypress.json, and then mocking it during the Edit: although your local scripts may not work with this solution. |
This feature is part of part of our large rewrite of the network layer that's actively being worked on - and you'll be able to fully stub all network requests including ones for script tags. Read this issue: #687 For today - you could either blacklist these requests, or you could use some combination of You have native access to everything in Cypress - and you can use that to alter your scripts before they are fetched. |
Okay, I would blacklist my |
@tschaka1904 Can you rephrase your question I don't really understand it. Are you asking: "how do I access the application's window from my test?" You have all kinds of way - you have native access to the window. If you want to do something before any of your code runs: Cypress.on("window:before:load", (win) => {
win.foo = "bar"
})
// or ...
cy.visit("/app", {
onBeforeLoad: (win) => {
win.foo = "bar"
}
})
// or ...
cy.window().then((win) => { win.foo = "bar" }) |
Can you elaborate a little bit more on this approach? I've tried listening to the "window:before:load" event, but when trying to get the document page scripts, it seems i'm getting the cypress window content and not the apps: cy.on("window:before:load", win => {
console.log(win.document.documentElement.outerHTML)
const scripts = win.document.getElementsByTag("script") // 1
console.log("scripts => ", scripts.length) // showing 1, which I assume is the singular script element in the output below
})
If I use the onLoad instead, potentially in the cy.visit config options, I get the right dom content, but by then it's too late: onLoad(win) {
console.log("doc => ", win.document.documentElement.outerHTML) // shows complete page
console.log("elems =>", win.document.getElementsByTag("script") // 54
} |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
The features requested in this issue are now possible as part of
Please see the If you encounter any issues or unexpected behavior while using |
Current behavior:
I've in my application several
<script>...</script>
like pulling in jQuery and also a few internal things. Cypress gets errors that it is not authorised to get certain things. Now this question would be answered (if authorised or not) by an external js file. But this fails, as the "cypress user" is unknown.Desired behavior:
A way of either overriding or mocking this
<script>...</script>
-tag to be able to influence the response.The text was updated successfully, but these errors were encountered: