question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

regression: `onBeforeLoad` handler not called when overwriting `visit`

See original GitHub issue

Current behavior:

onBeforeLoad hook is only getting called when defined inline with cy.visit(url, { onBeforeLoad }).

Desired behavior:

onBeforeLoad hook should get called when defined with Cypress.Commands.overwrite('visit', ...)

How to reproduce:

git clone https://github.com/sokki/cypress-test-tiny
npm i
npm run cypress:run

or look at circleci build: https://circleci.com/gh/sokki/cypress-test-tiny/1

Additional Info (images, stack traces, etc)

It seems, like the Issue was fixed in a previous version: https://github.com/cypress-io/cypress/issues/640

Test is visiting a static site (https://github.com/sokki/cypress-test-tiny/tree/master/static), deployed at https://static-fiwmrcysbv.now.sh The site just writes window.mocked || 'nope' to the body

  • Operating System: macOS 10.13.3 and Linux @ circleci
  • Cypress Version: 2.0.2
  • Browser Version: Chrome and Electron

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jennifer-shehanecommented, Jul 23, 2019

This appears to be fixed. Tested in Cypress 3.4.0 and it passes. Closing as resolved.

Screen Shot 2019-07-23 at 5 33 11 PM
0reactions
sokkicommented, Mar 9, 2018

@adamdicarlo you can find the test-repo here: https://github.com/sokki/cypress-test-tiny

Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
  return originalFn(url, {
    onBeforeLoad (win) {
      win.mocked = 'mocked'
    }
  })
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

onunload and onbeforeunload not triggered when location ...
Its working.. I have called the function 2 from a setTimeout and test with firefox and check in console with preserve option enable....
Read more >
Changelog - Cypress Documentation
Fixed a regression introduced in the Electron browser in Cypress 10.8.0 where the CYPRESS_EVERY_NTH_FRAME environment variable was not being set ...
Read more >
Allow extensions to intercept and handle onBeforeUnload
2. go to a website that has a window.onBeforeUnload-EventListener in place 3. click any link. What is the expected behavior? chrome.
Read more >
A Race Condition when closing inactive tab with alerts in ...
I believe that the proposed solution to not allow alerts/confirm/prompts in onbeforeunload/onunload/onpagehide is not ideal (see bug 391834).
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
visit command. By the time cy.intercept runs, the call is already in progress, and thus not intercepted. Cypress shows XHR calls by default...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found