gpt4 book ai didi

cypress - 使用 Cypress 绕过 UI 登录

转载 作者:行者123 更新时间:2023-12-04 13:59:46 25 4
gpt4 key购买 nike

我在绕过 UI 登录时遇到问题。我的 Web 应用程序不使用 API 来验证用户。没有像 /login 这样的端点. index.php只会打开登录页面并提交表单进行登录。

应用程序通过以下方式验证用户auth($_REQUEST['username'], $_REQUEST['password_tx']);
这是 cypress 在 UI 登录提交后打印的内容。

enter image description here

我不知道如何从这里继续前进。

    // This doesn't work. The application doesn't get the user details from the body. It is in the submitted form. 
cy.request({
method: 'POST',
url: '/index.php?p=sys001',
form: true,
body: {
username: 'user',
password_tx: 'pass'
}
})

最佳答案

这是该问题的完整测试用例。添加了注释以使其易于理解。

it("login via form spoof", () => {
cy.get("div#mDiv > form").invoke("attr", "action").then(($action) => { //get
the attribute of 'action' and pass encoded uname and pwd to it
let username = Cypress.env("username");
let password = Cypress.env("password");

cy.intercept("POST", $action, (req) => { //post request and populate body
// intercepting the POST form to spoof it.
req.body = $action + encodeURIComponent(username)+ encodeURIComponent(password)
})
.as("loginForm"); //alias
});

cy.get("div#mDiv > div.login > form")
.submit(); //Submit the form after locating it.
});

关于cypress - 使用 Cypress 绕过 UI 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51878136/

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