【发布时间】:2022-02-08 21:38:48
【问题描述】:
由于我正在处理一个承诺,我一直在努力从我的自定义函数中返回一个值。
这是我的代码:
这是我的自定义函数:
Cypress.Commands.add("myFunction", () => {
cy.get('#someID').then($container) => {
const isHidden = $container().children('div:nth-child(3)').is(':hidden');
console.log(isHidden); // This returns either true or false and that is good
return isHidden; // this returns $chainer but I want to return either true or false
}
});
这是我的测试套件:
context('some description', () => {
before(function(){
const result = cy.myFunction();
console.log(result); // This is $chainer, but I want to get the value of true or false from isHidden variable
});
});
【问题讨论】:
-
你不能在 cypress 中返回类似的值。你试过使用别名吗?
标签: javascript promise cypress