问题
I am setting up new cypress tests to test some functionalities in Dynamics 365 application. But, I'm left with a browser window with the url https://login.microsoftonline.com/__/ and the text Whoops, there is no test to run.
describe('Initial Cypress Tests', () => {
it('navigate to D365', () => {
cy.visit('https://wipropoc.crm8.dynamics.com')
} )
})
回答1:
Would suggest you to directly do a POST call for getting SSO authentication token and fire cy.visit('https://wipropoc.crm8.dynamics.com')
with the obtained token.
Here are the steps to follow from official documentation,
- Login when authentication is done on a 3rd party server.
- Parse tokens using
cy.request()
. - Manually set tokens on local storage.
- Map external hosts and point to local servers.
cy.request('POST', 'https://sso.corp.com/auth', { username: 'foo', password: 'bar' })
.then((response) => {
// pull out the location redirect
const loc = response.headers['Location']
// parse out the token from the url (assuming its in there)
const token = parseOutMyToken(loc)
// do something with the token that your web application expects
// likely the same behavior as what your SSO does under the hood
// assuming it handles query string tokens like this
cy.visit('http://localhost:8080?token=' + token)
// if you don't need to work with the token you can sometimes
// just visit the location header directly
cy.visit(loc)
})
You can read more about this here - https://docs.cypress.io/guides/guides/web-security.html#Form-Submission-Redirects
Real time example - https://xebia.com/blog/how-to-use-azure-ad-single-sign-on-with-cypress/
来源:https://stackoverflow.com/questions/55342478/sample-cypress-script-to-bypass-sso