I am using a Cypress.io for end to end testing in our team, but we have a problem with function cy.visit() very often.
The website has many resources from our server (css files, js files,....) and some external resources (js files). If you open our website, sometimes it happens that external js file is pending (browser is waiting).
Cypress during the execution of cy.visit() is probably waiting until all resources are loaded. And this is a problem. I dont need to wait for all resources, because for example this external js is for an advert and it is not important for our test.
Can i tell to Cypress something like: "After a few seconds after start loading a page you can exec this test without all resources loaded"?
I have tried onBeforeLoad combine with setTimeout and reload, but it failed :(
cy.visit('https://www.example.org', {
onBeforeLoad: (win) => {
setTimeout(function() {cy.reload(); }, 10000);
}
})
I am so crazy a I dont know what do next. Please help me and sorry for my english :) Thank you! :)
Wait for API responsewait() command. Test will only continue once that command is finished. Finding the right request to intercept is a great way to make sure that Cypress will wait until page loads with all the right data loaded.
Cypress automatically waits for the network call to complete before proceeding to the next command. // Anti-pattern: placing Cypress commands inside . then callbacks cy. wait('@alias') .
click() command, Cypress ensures that the element is able to be interacted with (like a real user would). It will automatically wait until the element reaches an "actionable" state by: Not being hidden. Not being covered.
You can block unnecessary domains from loading with the blacklistHosts: []
option in your cypress.json
. Just add the domain name of the advertiser (and potentially anything else you don't need, like Google Analytics) to the blacklistHosts
array:
{
// the rest of your cypress.json...
"blacklistHosts": [
"cdn.my-advertiser.com"
]
}
More information about blacklistHosts
is available in the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With