cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.06k stars 3.19k forks source link

Not able to handle Basic Login Authentication Pop Up in Cypress #28838

Open RavinderNuvei opened 9 months ago

RavinderNuvei commented 9 months ago

Current behavior

I am trying to handle the login authentication pop-up using the following approach

cy.visit('https://username:pwd@example.cypress.io')

and also I tried using

cy.visit('https://example.cypress.io/', {
  auth: {
    username: 'username',
    password: 'pwd',
  },
})

But the website is showing login pop-up even after using the passing the credentials in the url, somehow it is not able to handle this scenario.

Additionally, I tried using cy.intercept method to inject parameters beforehand like this

let isIntercepted=false;
 cy.intercept('https://example.cypress.io/**',(req)=>
    {
      if(!isIntercepted)
      {
       req.url=`https://${username}:${pwd}@example.cypress.io`;
       isIntercepted=true;
      }
       req.continue();
    })
    cy.visit(`https://${username}:${pwd}@example.cypress.io`)

But it doesn't work in this case either.

cypress-issue

Desired behavior

Using Cypress I should be able to login into the website as credentials are given in the URL. This is documented in the cypress documentation.

I should be able to perform the further assertions after I am logged into the website.

Test code to reproduce

I am using the cy.visit to login into the website, and I am passing the credentials in the url as I stated above

cy.visit('https://username:pwd@example.cypress.io')

Cypress Version

12.8.1

Node version

16.20.1

Operating System

Windows 10 Enterprise [10.0.19045 Build 19045]

Debug Logs

No response

Other

Can you please issue this fix on high priority I am looking forward for solution to this issue.

mkoiev commented 5 months ago

Hello @RavinderNuvei have you found any workaround?

Yazan-Mughrabi commented 4 months ago

Hello

I'm Facing the same issue too I'm trying to authenticate oidc user with basic auth but still getting the prompt page as @RavinderNuvei posted and didn't login

Can you please investigate and let us know when this is fixed Thanks

RavinderNuvei commented 4 months ago

Hello @mkoiev @Yazan-Mughrabi

I was not able to find the solution for handling the authentication pop-up as of now. Still struggling to login into the pop-up with automation.

@jennifer-shehane can you please look into this issue and advise us when it would be fixe. I raised it almost 4 months ago.

Thank you in advance !!

mkoiev commented 4 months ago

@RavinderNuvei Updated to the last cypress revision and auth:{} works for me

RavinderNuvei commented 4 months ago

@mkoiev that's nice to hear. can you let me know exactly which cypress version did you used which solved this issue ?

thanks again !!

mkoiev commented 4 months ago

@RavinderNuvei "cypress": "^13.11.0",

RavinderNuvei commented 4 months ago

@mkoiev @Yazan-Mughrabi @jennifer-shehane

I tried by updating the cypress to version 13.11.0 but it didn't solved the issue for me.

@mkoiev was the use case for the issue that you faced was same as this one I raised ? Can you let us know what additional steps we can follow to troubleshoot the issue ?

Thank you

Hazaruddinsyed commented 1 month ago

I am also facing the same issue, I have tried passing the credentials in the URL and also use auth option to visit function but it’s not working out . I am trying to handle SharePoint windows authentication if anyone know how to do please let me know.

kolavcic commented 1 month ago

I have the same thing on "cypress": "^13.15.0".

///

describe('template spec', () => { it('passes', () => { cy.visit('https://some.testing.page',{ auth: { username: "admin", password: "pass" }, failOnStatusCode: false

});

});

it('passes', () => { cy.visit('https://admin:pass@some.testing.page',{ failOnStatusCode: false

});

});

}); In both cases cypress just open the browser dialog and it is waiting like that.