When invoking cy.route() with baseUrl having basic auth credentials in the URL the route is never called.
$ CYPRESS_baseUrl=https://username:[email protected] yarn cypress:run
cy.route('POST', '/api/endpoint').as('someJsonData');
cy.wait('@someJsonData') // fails, since Cypress is waiting for the XHR call to include the basic auth credentials
The route should be called as all the subsequent XHR calls add the Authentication headers automatically. However the cy.route() expects the route to have the credentials in the URL.
Start a server that required basic auth. Add basic auth credentials to the baseUrl e.g. by passing in an environment variable. CYPRESS_baseUrl=https://username:[email protected] yarn cypress:run
Providing username:password as part of my baseUrl broke everything; it caused an immediate 401 as soon as the child Chrome process started in interactive mode, and caused timeouts in cypress run cli.
I was able to work around this by stripping it out of baseUrl and adding a dummy cy.visit() first thing in my tests, like this:
describe('Set up environment', function() {
context("Set up environment", function() {
it("starts", function() {
cy.visit('/', {
auth: {
username: 'username',
password: 'pass'
} } )
})
})
})
Not sure if this is the exact thing you're seeing...
I was having the same issue. I fixed it by overwriting the visit command:
Cypress.Commands.overwrite('visit', (orig, url, options) => {
options = options || {}
options.auth = {
username: 'username',
password: 'pass',
}
return orig(url, options)
})
Most helpful comment
I was having the same issue. I fixed it by overwriting the visit command: