Validating the cookie cypress throws 'TypeError: cy.chain is not a function
Validating the cookie cypress throws 'TypeError: cy.chain is not a function
我正在下面的 'login' 赛普拉斯测试中验证 cookie,但赛普拉斯抛出以下错误:
TypeError: cy.chain is not a function
在 '../support/index.js'
下清楚地导入了以下内容 有人可以告诉我为什么抛出错误
import './commands'
赛普拉斯测试:
describe("Login test validate cookie", () => {
it.only('Verify the cookies test for login', function() {
cy
.login(Cypress.env('email'), Cypress.env('password'))
cy
.getCookie('csrftoken')
.then((csrftoken) => {
console.log(csrftoken)
})
})
以下是我的'login'method/function../support/commands.js
Cypress.Commands.add('login', (email, password) => {
return cy.chain().request({
method: 'POST',
form: true,
url: '${cypress.env("test_server")}',
body: '{"email", "password"}',
})
});
'cypress.env.json' 文件
中提供了以下详细信息
{
"email": "test@soccer.nl",
"password": "test1234"
}
错误正确; cy.chain()
确实不是函数。但是,您的命令中存在许多问题:
- 除非您打算链接此命令,否则您不需要 return 任何东西。不过,它当然不会造成任何伤害。
- 如前所述,
.chain()
是不必要的。
- 您的
url
字段需要使用反引号 (``) 才能使 ${...}
正常工作。
- 您的
body
字段将包含 "email" 和 "password",而不是您的实际电子邮件和密码。
可能还有其他问题,但这些是我能看到的。
如果没有这些问题,您的命令将如下所示:
Cypress.Commands.add('login', (email, password) => {
cy.request({
method: 'POST',
form: true,
url: `${cypress.env("test_server")}`,
body: `{"${email}", "${password}"}`,
});
});
我正在下面的 'login' 赛普拉斯测试中验证 cookie,但赛普拉斯抛出以下错误:
TypeError: cy.chain is not a function
在 '../support/index.js'
下清楚地导入了以下内容 有人可以告诉我为什么抛出错误
import './commands'
赛普拉斯测试:
describe("Login test validate cookie", () => {
it.only('Verify the cookies test for login', function() {
cy
.login(Cypress.env('email'), Cypress.env('password'))
cy
.getCookie('csrftoken')
.then((csrftoken) => {
console.log(csrftoken)
})
})
以下是我的'login'method/function../support/commands.js
Cypress.Commands.add('login', (email, password) => {
return cy.chain().request({
method: 'POST',
form: true,
url: '${cypress.env("test_server")}',
body: '{"email", "password"}',
})
});
'cypress.env.json' 文件
中提供了以下详细信息{
"email": "test@soccer.nl",
"password": "test1234"
}
错误正确; cy.chain()
确实不是函数。但是,您的命令中存在许多问题:
- 除非您打算链接此命令,否则您不需要 return 任何东西。不过,它当然不会造成任何伤害。
- 如前所述,
.chain()
是不必要的。 - 您的
url
字段需要使用反引号 (``) 才能使${...}
正常工作。 - 您的
body
字段将包含 "email" 和 "password",而不是您的实际电子邮件和密码。
可能还有其他问题,但这些是我能看到的。
如果没有这些问题,您的命令将如下所示:
Cypress.Commands.add('login', (email, password) => {
cy.request({
method: 'POST',
form: true,
url: `${cypress.env("test_server")}`,
body: `{"${email}", "${password}"}`,
});
});