gpt4 book ai didi

azure - 无法通过 Cypress 加载我的 Azure 托管 Web 应用程序

转载 作者:行者123 更新时间:2023-12-03 01:20:56 27 4
gpt4 key购买 nike

当我尝试 cy.visit('url') Cypress 时,我有一个 Azure 托管应用程序,并且可以看到下面的内容。一段时间后“HTTP 错误 414。请求 URL 太长。”是可见的。如果有人知道如何解决此问题,请提供帮助。

enter image description here

最佳答案

从 URL 来看,您的应用程序似乎使用 Active Directory 登录。这意味着您的 Cypress 测试必须首先使用测试用户登录。您可以按如下方式实现此目的:

在 Cypress 中,您可以添加自己的自定义命令,如下所述: https://docs.cypress.io/api/cypress-api/custom-commands

这样您就可以编写自定义命令,从技术上将测试用户登录到事件目录中,例如:

Cypress.Commands.add('login', () => {
return cy
.request({
method: 'POST',
url: `https://login.microsoftonline.com/${tenantId}/oauth2/token`,
form: true,
body: {
grant_type: 'password',
tenant: 'tenantId',
client_id: 'clientId',
client_secret: 'clientSecret',
username: 'username',
password: 'password',
resource: 'clientId',
},
})
.then((response) => {
sessionStorage.setItem('access_token', response.body.access_token);
});
});

然后您可以在测试中使用自定义命令作为第一个操作,例如:

cy.login();

然后执行您的站点访问:

cy.visit()

关于azure - 无法通过 Cypress 加载我的 Azure 托管 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70379955/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com