Authentication Cypress:登录身份验证重定向到另一个域:解决方法?
我知道Cypress不允许从一个域切换到另一个域,因为它会出现以下错误:Authentication Cypress:登录身份验证重定向到另一个域:解决方法?,authentication,redirect,cypress,Authentication,Redirect,Cypress,我知道Cypress不允许从一个域切换到另一个域,因为它会出现以下错误: chrome-error://chromewebdata/ 但是,我需要一个解决办法。我为多个环境提供了一个测试集:阶段、演示、产品 使用DEMO和PROD,在身份验证阶段(用户名/密码),保持在同一域内: 访问:https://[demo|www.foo.com AUTH:https://account.foo.com/auth>用户名>>密码 同意:https://[demo| www.foo.com/action
chrome-error://chromewebdata/
但是,我需要一个解决办法。我为多个环境提供了一个测试集:阶段、演示、产品
使用DEMO和PROD,在身份验证阶段(用户名/密码),保持在同一域内:
- 访问:
https://[demo|www.foo.com
- AUTH:
>用户名>>密码https://account.foo.com/auth
- 同意:
https://[demo| www.foo.com/action…
- 访问:
https://[stage].foo.com
- AUTH:
>用户名>>密码https://account.bar.com/auth
- 同意:
https://[stage].foo.com/action…
- 木偶演员
- 使用
cy.request()
谢谢你,非常感谢你的帮助。我采用的方法与柏树食谱相似 如前所述,每个部署都有自己的网站URL,然后是帐户登录URL 首先需要的是来自帐户登录页面的令牌,其URL在这里称为
$baseUrl
:
Cypress.Commands.add('cmdGetCSRF', ($baseUrl) => {
cy.log('COMMAND cmdGetCSRF');
expect($baseUrl)
.to.be.a('string')
.not.empty
cy.request($baseUrl)
.its('body')
.then(($body) => {
const $html = Cypress.$($body)
cy.log('html', $html)
const csrf = $html.find('input[name="__RequestVerificationToken"]').val()
expect(csrf)
.to.be.a('string')
.not.empty
return cy.wrap(csrf)
})
})
然后在提供给执行登录的cy.request()
的requestOptions的body
中,提供一次性CSRF令牌:
const body: { [key: string]: string } = {
email: $envCypress.account_username,
password: $envCypress.account_password,
__RequestVerificationToken: $csrfToken
};
我采用的方法与柏树食谱相似
如前所述,每个部署都有自己的网站URL,然后是帐户登录URL
首先需要的是来自帐户登录页面的令牌,其URL在这里称为$baseUrl
:
Cypress.Commands.add('cmdGetCSRF', ($baseUrl) => {
cy.log('COMMAND cmdGetCSRF');
expect($baseUrl)
.to.be.a('string')
.not.empty
cy.request($baseUrl)
.its('body')
.then(($body) => {
const $html = Cypress.$($body)
cy.log('html', $html)
const csrf = $html.find('input[name="__RequestVerificationToken"]').val()
expect(csrf)
.to.be.a('string')
.not.empty
return cy.wrap(csrf)
})
})
然后在提供给执行登录的cy.request()
的requestOptions的body
中,提供一次性CSRF令牌:
const body: { [key: string]: string } = {
email: $envCypress.account_username,
password: $envCypress.account_password,
__RequestVerificationToken: $csrfToken
};