我如何在cypress中编写以下量角器代码作为类的方法
this.openIf = function (element, ctrl) {
return element.isDisplayed()
.then(
function clickCtrlUnlessElementVisible(visible) {
if (!visible) {
return ctrl.click();
}
return;
})
.then(
function waitForElementToBeDisplayed() {
return browser.wait(
function() {
return element.isDisplayed();
})
}).then(function checkElement() {
expect(element.isDisplayed()).toBeTruthy();
})
};