我在绕过 UI 登录时遇到问题。我的 Web 应用程序不使用 API 来验证用户身份。没有像这样的端点/login
. index.php
只需打开登录页面并提交表单即可登录。
应用程序通过以下方式对用户进行身份验证auth($_REQUEST['username'], $_REQUEST['password_tx']);
这是 cypress 在 UI 登录提交后打印的内容。
我不知道如何从这里继续前进。
// 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.
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)