-
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
Ability to opt out of waiting for 'load' event before resolving cy.visit() - onload event takes too long to fire #788
Comments
Do you have ability to try same test on windows 10 for example?
…Sent from my iPhone
On Oct 22, 2017, at 18:52, JheeBz ***@***.***> wrote:
Operating System: Windows 7
Cypress Version: Beta 1.0.2
Browser Version: Version 61.0.3163.100 (Official Build) (64-bit)
Is this a Feature or Bug?
Bug
Current behavior:
Cypress runs extremely slowly. Run time for 2 tiny tests is ~60-65 compared to similar Protractor test suite which takes ~20-25 seconds to complete the same tests.
Desired behavior:
Significant improvement to run time.
How to reproduce:
Using test code below.
Test code:
Cypress code:
(I would set timeout as 15000 just like my Protractor code, but it times out when I do that)
describe('Attempt to log in', () => {
before(() => {
cy.visit('/')
})
it('without a username or password', () => {
cy.get('button', {timeout: 30000})
.contains('SIGN IN')
.should('be.visible')
.click()
cy.get('#error')
.should('have.text', 'Please enter your username')
})
it('without a password', () => {
cy.get('#username', {timeout: 30000})
.should('be.visible')
.type('example_username1')
cy.get('button')
.contains('SIGN IN')
.click()
cy.get('#error')
.should('have.text', 'Please enter your password')
})
afterEach(() => {
cy.reload(true)
})
})
Comparable Protractor code:
describe('Attempt to log in', () => {
const EC = protractor.ExpectedConditions;
beforeAll(() => {
browser.get('/');
browser.wait(EC.presenceOf($('#username')), 15000);
});
it('without a username or password', () => {
element(by.buttonText('SIGN IN').click();
expect($('#error').getText()).toBe('Please enter your username');
});
it('without a password', () => {
$('#username').sendKeys('example_username1');
element(by.buttonText('SIGN IN').click();
expect($('#error').getText()).toBe('Please enter your password');
});
afterEach(() => {
browser.executeScript('window.sessionStorage.clear();');
browser.executeScript('window.localStorage.clear();');
browser.refresh();
});
});
Cypress is really great and powerful, but it's a shame that it takes so long to execute these tests.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I tried to run the same test on Windows 10 (using my laptop) and it took about 37-40 seconds on average. That's still almost double the run time of Protractor. Cypress seems to take a long time to load the page and perform assertions. |
At work i run e2e tests under windows 7 with cypress 1.0.2 and chrome 61.0.3163.100 (Build officiel) (32 bits) and it is super fast, no problem at all. |
I am curious why you don't just move the |
Okay want to clarify a few things... Cypress has a completely different architecture than Selenium based automation tools. Whereas Selenium works by executing remote commands over the network - Cypress runs in the same run loop as the application. Because of this, very few commands are executed over the network (only the ones that require a higher privilege) and therefore in almost every circumstance Cypress will run faster. I am simplifying this quite a bit, but we have had a considerable number of users rewrite their protractor tests and they rerun much faster in Cypress. With that said - Cypress has a much different behavior and set of opinions than Selenium. For instance, our Most of the time the Your case seems pretty unique in that your application is taking (even in protractor) an average of 20-25s to run two tests. That is incredibly slow. Ideally your application loads in under a second or two. I'll also assume in this case you have a huge number of blocking scripts / css / images which are pushing the Because Cypress runs commands serially you don't need to add a timeout to the Lastly I'm also assuming these tests are also taking longer because of that There's almost never a reason to ever use My post makes a lot of assumptions based on the way your application works, so if I'm wrong there is of course room for more debate / suggestions. Another possible area is that because Cypress is a network proxy, it means all traffic gets routed through it locally. There are areas for performance improvements to this layer, but even with that, we have seen much better performance than any other Selenium based tool. You'd have to provide more details related to your specific application for us to make any changes or investigate further. |
@jennifer-shehane there didn't appear to be another way to clear the cache between tests but further reading seems to suggest that the cache is automatically cleared between each test. I've removed the afterEach hook and changed my before hook to a beforeEach, but it hasn't made a difference on the timing at all. I will note though that a similar change to my Protractor test has reduced the timing to 13 seconds. @brian-mann thanks for the information. As above the way I wrote my tests to check out Cypress was in an attempt to mirror a couple of existing tests. One limitation of Protractor is the lack of commands available within their API, so I've had to improvise a lot. Unfortunately I have to add a timeout to the |
Do you have a public URL that we can test against? It sounds like your application loads immediately and then lazily loads in the JS required to actually use the application. In that case, yes you would need to add the timeout to the first command so it blocks until that happens. Alternatively you could wait on an XHR to finish indicating to you that its done loading - or possibly check some other value like something local storage, etc. |
I'm facing similar issues on Windows 10 When I run a test file browser takes 12+ seconds to boot up, and simple tests (just checking html element existence) take 12 sec each as well. I'm guessing being on Windows could be a factor but this was the only issue I found on the matter. Here's a video of the experience: https://drive.google.com/file/d/1R9ADU7IMmLp-VmTYjbX18F8zmi4xsUEG/view?usp=sharing (ignore the flicker) Here's an example test: describe('login', () => {
beforeEach(() => {
cy.visit('/login')
})
it('has correct html', function() {
cy.contains('Login to your account').should('exist')
cy.contains('New here? Request early access.').should('have.attr', 'href', '/register')
})
}) |
I have the same experience as well. Booting up the headless browser takes 15-20 seconds longer on Windows 10 than the same exact set up in OSX. Again, this is just timing the startup process and not the running of the actual specs. Any ideas for improving the startup in Windows? |
@alidcastano @arfs That's pretty rough and definitely not what should be happening. We'll really need a reproducible example to test against - which I know is difficult if you can't share a public url - but if it's at all possible, we'd love to look at it. |
We had an issue where Cypress was really slow (45 ~ 50 sec each test). We found out the problem was due to Google Analytics. We change our server setting for the execution of our component test to deactivate it and now each test take arround 2 ~ 3 sec. |
Unfortunately we'll have to close this issue if no reproducible example is provided. Can anyone provide a way to reproduce this? |
I face same issue. Cypress is extremely slow when call cy.visit() because it waits all url is loaded. |
Same here unfortunately. I love the idea of Cypress but have been struggling with it for a couple of days now and am going to have to give up on it if I can't get the problem solved in short order. I almost wonder if a |
@jennifer-shehane With regard to a way to reproduce, as a generic example let's say a dev is working on an online media site such as bhg.com A Another possible way to address the issue beside the Totally understand that might not be feasible for any number of reasons; just thinking out loud 😄 |
Some of these comments are related to other slow running issues, but I'd like to focus this issue on the topic of Cypress waiting for the If your issue is still happening and not related to the time that the There has been some discussion of, instead of waiting for the The only way to get around this issue would be to perhaps listen to the DOMContentLoaded event, as @brian-mann suggested, or to have the ability to opt in and disable listening for the |
I'm recreating the same test in protractor and cypress in my app too and getting a similar result. I think the reasons for this happening have been already explained, but basically, my app is composed of very old pieces and very new ones using Angular 7. Testing around angular 7 it's quite fast but when testing the old pages which can have all sort of bad practices about blocking the load event... Hope we get the option to opt out soon |
OH God, i sold to my boss using Cypress for e2e testing, and i encountered this issue, i cant believe this is an issue reported over an yr and not been fixed or getting an work around, should i start pack up and looking for new interviews ? |
There are cases where DomContentLoaded and Load events can be fired at significantly different times, one case can be when the page needs to load very large images. Correct me if I'm wrong but the main difference between DomContentLoaded + Load is stylesheets and image loading. From #788 (comment) @brian-mann commented that using load event offers higher guarantees, why is that? At DOMContentLoaded all scripts are parsed and loaded (https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event) and I don't see what cypress commands generally rely on image being loaded. IMO using DomContentLoaded as the event that cy.visit waits on makes more sense to me in scenarios where static assets like images etc slow things down would be great if that was an option. |
Is there really no update/progress on any of the potential solutions in this thread. |
I forgot this thread until rossjwaddell revived it. So per my previous comment I wrote more than 2 years ago I had the same issues as everyone where my tests were taking a long time to run even when it was just 1 or 2 tests. For me the issue was that the headless browser would take a long time to load a page in Windows 10 but the execution of the unit tests itself were fast. I didn't have the problem when I ran my unit tests on a machine running OSX with identical setup. It's been a while since I worked on that project but I was actually able to get around the issue. I believe it had something to do with the fact that the site I was performing a
I am almost sure it was the first one and if that were the case I modified the html of the site so the external links matched the schema of the site URL I was visiting. In my case I changed them to be all http. I hope this helps someone even though it's a bit late. |
Hey, @jennifer-shehane are there any updates on this feature?! if you guys can prioritize this it will be great as this issue makes a lot of noises |
Is this still being worked on? I've gone to a different employer and this issue causes the application at my new workplace to hang as well. cy.visit() seems to not wait for the rest of the resources to load and simply stalls rendering. I can confirm that both in the case of the old application I was working on and in the new application, the I would really like to use cypress, so in place of a resolution to this issue, is there a workaround? |
I would also very much like to bump the request for a way to short-circuit the wait for a "load" event to be received. We are forced to use certain legacy stacks while we are introducing changes modularly, and in one of these, the load event take roughly 5 minutes to resolve in the pipeline (it works fine locally both headed and headlessly). This issue is causing quite a bit of delay and expense as we try to stand up end-to-end tests, and if we could tie the resolution of |
I have the same issue on And as the visit is part of my beforeEach hook when it fails it stops all other specs as there's no retry ability for those hooks, or is there? 🤔 |
In my case, 3rd party scripts that were sending requests on first load were blocking the load event. Some notable examples were Intercom, Facebook events and others. If they are added to After using |
@brian-mann, try: https://www.garmin.com/en-US/account/profile
|
any update? |
Please allow for opting out of the load event. I am struggling to get past this issue even though the rest of my tests work when I use a beta environment URL that does not have the load page issue. |
Kindly make it optional to opt out of the load event. |
describe('CSS Locator',()=>{ I am running the above code in cypress and everytime it says Timed out after waiting 60000ms for your remote page to load. Your page did not fire its load event within 60000ms. You can try increasing the pageLoadTimeout value in cypress.config.js to wait longer. Browsers will not fire the load event until all stylesheets and scripts are done downloading. |
visit https://www.saucedemo.com/ Your page did not fire its load event within 10000ms. You can try increasing the pageLoadTimeout value in cypress.config.js to wait longer. Browsers will not fire the load event until all stylesheets and scripts are done downloading. When this load event occurs, Cypress will continue running commands. cypress/fixtures/pages/loginPage.js:17:8
|
Is there any update regarding the issue? |
I have been running some tests successfully until today when this issue just surfaced - not sure what have been changed ? |
Current behavior:
Cypress runs extremely slowly. Run time for 2 tiny tests is ~60-65 compared to similar Protractor test suite which takes ~20-25 seconds to complete the same tests. My timing for Cypress is based on the timer in the runner and my timing for Protractor is based on the timestamp in the console from when it starts and finishes.
Desired behavior:
Significant improvement to run time.
How to reproduce:
Using test code below.
Test code:
Cypress code:
(I would set timeout as 15000 just like my Protractor code, but it times out when I do that)
Comparable Protractor code:
Cypress is really great and powerful, but it's a shame that it takes so long to execute these tests.
The text was updated successfully, but these errors were encountered: