您如何request
在赛普拉斯自定义命令中调用?
Cypress.Commands.add('factory', async (name, attributes) => {
const response = await cy.request('POST', '/cypress/factories', {
name,
attributes: attributes || {}
});
return response;
});
结果是 ..
返回承诺的命令是:> cy.factory()。
您在promise中调用的cy命令是:> cy.request()。
因为赛普拉斯命令已经像承诺一样,所以您不需要包装它们。
或返回您自己的承诺。Cypress将使用来解决您的命令。
无论赛普拉斯最终命令产生什么结果。
就像消息中说的那样,赛普拉斯将为您解决响应,因此无需返回任何内容。
Cypress.Commands.add('factory',(name, attributes) => {
cy.request('POST', '/cypress/factories', {
name,
attributes: attributes || {}
});
});
您可以将命令与 then
cy.factory(name, attributes).then(response => {
console.log(response)
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句