Cypress: Don't fail visit calls on other than 2xx response codes

Created on 25 Jul 2017  路  5Comments  路  Source: cypress-io/cypress

Is this a Feature or Bug?

Feature

Current behavior:

When testing our error page the response code was 404 i.s.o. 200 and when using the visit() command this fails as it requires a 2xx response.

Desired behavior:

Don't fail tests when a response code other then 2xx is fired upon visiting an url. Or make it explicit that you expect another code than 2xx.

How to reproduce:

Visit a 404/500 page to reproduce

pkdriver feature

Most helpful comment

All 5 comments

Was brought here via https://github.com/cypress-io/cypress/issues/421 and this issue.

Was looking to maybe help out and throw up a potential PR if the feature is not too big.

I was playing around with adding a failOnStatusCode option to be used with cy.visit(url, options) in navigation.coffee.

This works, but for non 2XX status code pages it results in loading the actual page url and not the test runner view. I'm assuming some on error handler or logic needs to be added for this. Any thoughts? 馃槃

You likely just want to restructure the logic around this part:

https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/navigation.coffee#L265

I'd have to see your code to know what you're doing differently. Feel free to open a PR thats WIP.

If you follow the resolve:url websocket event it will eventually reach this code...

https://github.com/cypress-io/cypress/blob/628281dd65055374958ef223a00ff75c93a0c31b/packages/server/lib/server.coffee#L279

There is ridiculous and considerable complexity around this function - but I don't think it actually needs to be modified. This should all just work with a couple driver changes and 1 or 2 tests around it.

EDIT:

Nope, this needs to be modified https://github.com/cypress-io/cypress/blob/628281dd65055374958ef223a00ff75c93a0c31b/packages/server/lib/server.coffee#L372

The server is making assumptions about what is acceptable - so this code also needs to take into account the options override for enabling non Ok responses to go through.

That's probably why it's switching to the domain and not re-running cypress - it's not setting the current super domain under test correctly. It needs that state for everything to work.

How we juggle and buffer visits is some of the most complex code inside of Cypress.

@brian-mann Amazing. Thanks for the pointers. I'll open a WIP PR when I next get a chance 馃槃

Released in 1.1.3.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zbigniewkalinowski picture zbigniewkalinowski  路  3Comments

igorpavlov picture igorpavlov  路  3Comments

verheyenkoen picture verheyenkoen  路  3Comments

weskor picture weskor  路  3Comments

SecondFlight picture SecondFlight  路  3Comments