Cypress:如何在单击打开另一个子域链接的链接时处理窗口弹出身份验证?

问题描述 投票:0回答:1

在 Cypress 中,我们可以在访问这样的 url 时处理窗口弹出身份验证

步骤:1

cy.visit(https://username:[email protected])

这工作正常。 但我的场景是执行步骤 1 后,我们需要单击一个导航到其他子域 url 的元素

us.myapp.com

但这一次单击元素并导航到子域后,它再次要求进行窗口弹出身份验证。 此时我们没有访问 url,因此我们无法像下面这样通过弹出窗口身份验证

cy.visit(https://username:[email protected])

我们如何应对这种情况?

cypress ui-automation
1个回答
0
投票

您应该能够使用

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()
})
© www.soinside.com 2019 - 2024. All rights reserved.