在我们的项目中,有不同的URL分配给不同类别的产品。如果产品类别为Cat1,则单击“编辑”按钮应将用户带到Cat1页面,而Cat2应将用户带到Cat2页面。但是,这些类别在动态表中,因此我们不能对编辑按钮使用修订参考,而我正在尝试使其动态化。以下是我的代码段:
it('should take the user to appropriate page', function () {
expect(globalVariables.Edit_Button_1.isDisplayed());
// get rows
var row_1 = globalVariables.tableData_Dashboard.all(by.tagName("tr")).get(1);
// get cell values
var cells = row_1.all(by.tagName("td"));
var Cetegory = cells.get(3).getText().then(function (GL) {
// console.log(GL)
return GL;
});
globalVariables.Edit_Button_1.click();
browser.wait(EC.invisibilityOf(globalVariables.Edit_Button_1), 25000, 'Edit button is not disappearing yet');
if (Cetegory.endsWith('Cat1')){
expect(browser.getCurrentUrl()).toEndWith("Cat1");
}
else {
expect(browser.getCurrentUrl()).toEndWith("Cat2")
}
测试失败,并显示“失败:Cetegories.endsWith不是函数..
如何解决?
答案 0 :(得分:1)
Cetegory
是一个承诺,不是字符串。因此它确实具有功能endsWith
。您需要按以下方式消耗then()
中的promise最终值。
Cetegory.then(function(_Cetegory){
if (_Cetegory.endsWith('Cat1')){
expect(browser.getCurrentUrl()).toEndWith("Cat1");
}
else {
expect(browser.getCurrentUrl()).toEndWith("Cat2")
}
})