-
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
Cypress hangs up when using done within a before hook after cy.request #1075
Comments
Yeah this should certainly work - I cannot see any reason why it wouldn't. We'll look into it. Curious - why do you need to yield The handful of times |
I'm glad you asked, because that's actually related to another problem I have, but I wanted to investigate further before filing a proper issue. I'm writing an E2E test, where I need to "seed" our platform with data and I do it in the Please let me know if this should work or I am just missing a concept or two. I definitely need to read the whole doc again, after using Cypress for a few weeks now. Thanks! |
@vrockai I believe you can accomplish this with function req () {
cy.request(...).then((resp) => {
return Cypress.Promise.delay(100).then(req)
})
}
req() |
@brian-mann For example if i have function without setTimeout in it but it needs to wait sometimes 10sec, sometimes more or less to load, what is solution. I wanna have some function where i will not need to type exactly the time after which my page will be loaded i just wanna tell to cypress do this when the page is loaded? Thanks. |
I also was having this problem but solved it by returning a "Promise" instead of using the before(function() {
return cy.request("/");
}); |
Thank you for answer, but i think the cy.visit('some_page') will always wait until the whole page is loaded and this is simple solution which solving my problem!:) |
The code for this is done, but this has yet to be released. We'll update this issue and reference the changelog when it's released. |
Released in |
This issue is still happening in Example (pseduo code) const { mockSocket } = require('../../support/mock-socket');
describe('Test My Page', () => {
before(() => {
cy.visit('/my/page', {
onBeforeLoad(win) {
mockSocket(win);
}
});
});
it('it should correctly load the page', () => {
cy.url().should('include', '/my/page');
});
it('should do something else', () => {
cy.get('#ts-1-header').should(...);
});
}); I've been able to get this to work by using the following (although I feel incredibly dirty doing this and we have to wait the extra 10 seconds even if the page has loaded already): const { mockSocket } = require('../../support/mock-socket');
describe('Test My Page', () => {
before((done) => {
return cy.visit('/my/page', {
timeout: 30000,
onBeforeLoad(win) {
mockSocket(win);
}
}).then({ timeout: 30000 }, () => {
return Cypress.Promise.delay(10000).then(done);
});
});
it('it should correctly load the page', () => {
cy.url().should('include', '/my/page');
});
it('should do something else', () => {
cy.get('#ts-1-header').should(...);
});
}); |
This issue will be closed to further comment as the exact issue here was resolved and tested. @tsteuwer If you're experiencing a bug similar to this in Cypress, please open a new issue with a fully reproducible example that we can run. There may be a specific edge case with the issue that we need more detail to fix. |
Current behavior:
When using a
done
callback within athen
method of acy.request
in abefore
hook, tests won't wait for elements to appear on page (page load/redirect) and the whole test-suite will hang-up (it never finishes).When not using the
done
function in the hook, everything works as expected = thecy.get('button')
waits for the page to load.Desired behavior:
The test behavior should be independent of the usage of the
done
function inside thebefore
hook.How to reproduce:
Try running my simple test code with a page that take a while to load.
Test code:
The text was updated successfully, but these errors were encountered: