Manually enter auth credentials in dialog

Viewed 1612

I need Cypress authenticate a XHR request done in my app. The authentication is not Basic, but Digest, which has made finding help harder.

There also seems to be a bug for authenticating requests, such like:

cy.request({
  url: 'http://postman-echo.com/digest-auth',
  auth: { user: 'postman', pass: 'password', sendImmediately: false },
})

https://github.com/cypress-io/cypress/issues/2128

I'm wondering if there is a temporary workaround involving making Cypress manually entering the credentials in the dialog?

I've looked into listening to events such as window:alert and window:confirm, but these don't seem to catch the auth dialog.

TL:DR: How can I make Cypress enter the credentials manually in the dialog?

3 Answers

cy.visit currently only supports sending Basic HTTP auth, but I've opened a feature request for digest auth: https://github.com/cypress-io/cypress/issues/4669

In the meantime, the workaround would be to disable HTTP authentication in your local testing environment.

You would probably need something like this

    cy.visit('http://yoururl/')
    cy.get('input#username').type('username')
    cy.get('input#password').type('password')
    cy.get('button#signin').click()
Related