Cypress: Allow visiting `about:blank` during test / before each / after each

Created on 29 Oct 2019  路  2Comments  路  Source: cypress-io/cypress

Current behavior:

cy.visit('about:blank') navigates to http://url/base/about:blank

Desired behavior:

cy.visit('about:blank') navigates to about:blank

Versions

3.4.1

Background

In our application we register some listener on storage events. During before each cypress cleans the storage. This results into failing in our application, because our application is still running from the previous test case.
It should be possible to leave our application for example in after each by visiting about:blank.

I think the easiest way would be adding another option parameter to the visit command to skip adding base url to the target url:
https://github.com/cypress-io/cypress/blob/49f5b3e80c56e382b3cbd37c6deedda7389c32b7/packages/driver/src/cy/commands/navigation.coffee#L555-L563

Our current workaround is patching the register event listener method on window:load.

pkdriver proposal 馃挕 feature

Most helpful comment

@CSchulz This is currently not possible. The only way to do this would be to have your webserver would need to serve an empty page that you could then visit.

But we've discussed having Cypress serve a blank page so that you can reset things like this, something like cy.reset()

You can try using the test code below, but this may not perform the way you think it should exactly since there is still some persistence of state when visiting about:blank manually in this way.

  cy.window().then((win) => {
    win.location.href = 'about:blank'
  })

All 2 comments

@CSchulz This is currently not possible. The only way to do this would be to have your webserver would need to serve an empty page that you could then visit.

But we've discussed having Cypress serve a blank page so that you can reset things like this, something like cy.reset()

You can try using the test code below, but this may not perform the way you think it should exactly since there is still some persistence of state when visiting about:blank manually in this way.

  cy.window().then((win) => {
    win.location.href = 'about:blank'
  })

I just spent quite a while debugging a similar issue. It's very unexpected that the page from a previous test is still open causing things to happen and can fail the current test. Hugely in favor of a cy.reset().

Was this page helpful?
0 / 5 - 0 ratings