迁移到 Cucumber 4 时如何 return 承诺?
How can I return promise while migrating to Cucumber 4?
我正在将测试用例迁移到 Cucumber 4,我有以下代码片段,我想将其转换为 Cucumber 4 类型的代码。
homePage.js
this.isHomeButtonEnabled = function(){
var isButtonEnabled = true;
browser.element(by.css('.home-btn')).getAttribute('disabled').then(function () {
isButtonEnabled = false;
})
return isButtonEnabled;
}
我的预期情况是,
expect(homePage.isHomeButtonEnabled()).to.be(true);
现在我以上功能即 isHomeButtonEnabled
应该 return 承诺。但是迁移上面代码段的合适方法是什么?
选项 1) 使用量角器 isEnabled()
api:
this.isHomeButtonEnabled = function(){
return element(by.css('.home-btn')).isEnabled();
}
选项 2) 使用 getAttribute('disabled')
:
this.isHomeButtonEnabled = function(){
return element(by.css('.home-btn')).getAttribute('disabled')
.then(function(disabled){
return disabled === null ? true: false;
});
}
我正在将测试用例迁移到 Cucumber 4,我有以下代码片段,我想将其转换为 Cucumber 4 类型的代码。
homePage.js
this.isHomeButtonEnabled = function(){
var isButtonEnabled = true;
browser.element(by.css('.home-btn')).getAttribute('disabled').then(function () {
isButtonEnabled = false;
})
return isButtonEnabled;
}
我的预期情况是,
expect(homePage.isHomeButtonEnabled()).to.be(true);
现在我以上功能即 isHomeButtonEnabled
应该 return 承诺。但是迁移上面代码段的合适方法是什么?
选项 1) 使用量角器 isEnabled()
api:
this.isHomeButtonEnabled = function(){
return element(by.css('.home-btn')).isEnabled();
}
选项 2) 使用 getAttribute('disabled')
:
this.isHomeButtonEnabled = function(){
return element(by.css('.home-btn')).getAttribute('disabled')
.then(function(disabled){
return disabled === null ? true: false;
});
}