Cypress: cy.location('pathname') throws an error, claiming not having a pathname key

Created on 10 Aug 2017  路  5Comments  路  Source: cypress-io/cypress

Current behavior:

When using cy.location('pathname') , asserting throws error.

assertion looks like this:

cy.location('pathname').should("eq", `/onboarding/name`)

error:
CypressError: Location object does not have key: pathname

fyi: writing out assertion with function works no problem:

cy.location().should(function(location){
  expect(location.pathname).to.eq('/events')
})

Desired behavior:

Should not throw error, when trying to use cy.location('pathname')

How to reproduce:

in this particular case, the assertion comes right after redirect after login

Additional Info (images, stack traces, etc)

looks like this. you can see the test does not wait for path change and throws an error.

screenshot 1
screenshot 2

1锔忊儯 bug

Most helpful comment

It works with cy.window()

        it('signs in to backoffice', () => {
          cy.window().then((win) => {
            expect(win.location.pathname).to.equal('/backoffice')
          })
        })

All 5 comments

I'm having this issue as well.

What's most interesting is that it's not consistent, however, it ONLY occurs with the cypress run command.
Regardless of whether it is run normally or with the --headed flag, it will happen 70-80% of the time, and is causing my tests to needlessly fail...
I cannot understand why or what the difference between running this via cypress open or just cypress run is. Even though I'm using Electron 57 for cypress open...

It works with cy.window()

        it('signs in to backoffice', () => {
          cy.window().then((win) => {
            expect(win.location.pathname).to.equal('/backoffice')
          })
        })

issue replicated doing like:
cy.location('pathname').should($pathname =>

Tried to reproduce the problem, but failed.

You can see the failed attempts here.

I both tested with cypress:open and cypress:run. Both are fine.

If anyone encounters with this problem, please leave an example code/project that fails.

Thanks.

p.s.

My environment:

  • Ubuntu 18.04
  • Chrome v78
  • Cypress 3.4.1 and 3.5+

Cypress version has gone up a lot. It is possible that it's been fixed.

Closing as resolved. Please comment with a completely reproducible example if you are still having this issue and we will consider reopening.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jennifer-shehane picture jennifer-shehane  路  3Comments

scottcrowe picture scottcrowe  路  3Comments

igorpavlov picture igorpavlov  路  3Comments

verheyenkoen picture verheyenkoen  路  3Comments

rbung picture rbung  路  3Comments