在 Cypress 中,我们可以在访问这样的 url 时处理窗口弹出身份验证
步骤:1
cy.visit(https://username:[email protected])
这工作正常。 但我的场景是执行步骤 1 后,我们需要单击一个导航到其他子域 url 的元素
us.myapp.com
但这一次单击元素并导航到子域后,它再次要求进行窗口弹出身份验证。 此时我们没有访问 url,因此我们无法像下面这样通过弹出窗口身份验证
cy.visit(https://username:[email protected])
我们如何应对这种情况?
您应该能够使用
cy.intercept()
将参数注入到传出请求中。
假设
https://username:[email protected]
适用于第二个域,它会是这样的,
const username = ...
const password = ...
cy.intercept('https://us.myapp.com/**', (req) => {
req.url = `https://${username}:${password}@us.myapp.com`;
req.continue()
})