我很难从我的自定义函数中返回一个值,因为我正在处理一个Promise。
这是我的代码:
这是我的自定义函数:
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
});
});