Cypress alert (pop-up) login at visit url

Viewed 1537

I have strange problem. I want to automate one web site using Cypress. At the begining I need to enter credentials like username and password into the alert (pop-up) window. I tryed a lot of ways to handle this. Here is my code that I used for handling alert (pop-up) windows, that contains input text element:

cy.window().then(($win) => {
cy.stub($win, 'prompt').returns(text)
cy.get(#randomId).click()
})

I wasn't sure if this is the correct way to handle this, thats why I tryed one package named: cypress-ntlm-auth. I tried to use this package, because it seems that the package handles "Windows Authentication login" when visiting a site for the first time. Here is the code that I tried:

cy.ntlm(['chiquito-qa.omnifitrgsites.co.uk'], "tainae", "nekazvam", "chiquito-qa");
cy.visit('chiquito-qa.omnifitrgsites.co.uk');

Btw the credentials are not real.

3 Answers

you could use this one

describe('auth with proper credentials', () => { 
            it('bypass login', () => {
                cy.visit('your url', {
                    auth: {
                        username: 'enter username',
                        password: 'enter password,          
                     },
                })
                
            })
    })
    
    

I think the website use a basic authentication method to login simply use this pattern

cy.visit("http://username:password@chiquito-qa.omnifitrgsites.co.uk")

Or to simplify your process for other request use a base url on the cypress.json file

"baseUrl": "http://username:password@chiquito-qa.omnifitrgsites.co.uk"

You can do something like this. This will bypass the auth pop-up and will directly authenticate.

cy.visit('https://username:password@example.com')
Related