gpt4 book ai didi

javascript - 使用 Protractor 使用部分文本来控制重定向

转载 作者:行者123 更新时间:2023-12-03 00:22:55 26 4
gpt4 key购买 nike

在我们的项目中,不同的网址分配给不同类别的产品。如果产品类别为 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 不是函数..

如何解决这个问题?

最佳答案

Cetegory 是一个 promise ,而不是一个字符串。因此它确实有函数endsWith。您需要在 then() 中使用 Promise 最终值,如下所示。

Cetegory.then(function(_Cetegory){
if (_Cetegory.endsWith('Cat1')){
expect(browser.getCurrentUrl()).toEndWith("Cat1");
}
else {
expect(browser.getCurrentUrl()).toEndWith("Cat2")
}
})

关于javascript - 使用 Protractor 使用部分文本来控制重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54226823/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com