我正在尝试组合两个字符串“globalVariables.EditButton_”和“i”的值,并将该字符串(例如“globalVariables.EditButton_1”)作为变量传递,该变量应该引用我们存储为全局变量的按钮元素。下面是我的代码,但它不起作用。错误是
“消息:失败:Button.isDisplayed 不是函数堆栈:TypeError:Button.isDisplayed 不是函数”
代码片段:
it('should show the same data in both Page' , function(){
var RowCount=
globalVariables.tableData_Dashboard.all(by.tagName("tr")).count() -1;
for (var i=1; i < RowCount; ++i){
var Button = 'globalVariables.Edit_Button_'+i;
expect(Button.isDisplayed());
// do something
}
});
在这种情况下,如何添加两个字符串并将其用作变量?
在上面的代码段中,您globalVariables.tableData_Dashboard.all(by.tagName("tr")).count()
返回了一个promise。因此,当您将这些加在一起时,您就是在向 int 和 int 添加承诺。接下来看起来很奇怪的事情:var Button = 'globalVariables.Edit_Button_'+i;
这不会被评估为 elementFinder。我同意上面应该使用的 yong 的评论globalVariables['Edit_Button_'+i];
因此,我将使用 async / await 来回答这个问题,并且控制流已关闭。这是SELENIUM_PROMISE_MANAGER: false,
在您的配置文件中设置的。
it('should show the same data in both Page' , async () => {
const RowCount=
(await globalVariables.tableData_Dashboard.all(by.tagName("tr")).count()) - 1;
for (var i=1; i < RowCount; ++i){
const button = globalVariables['Edit_Button_'+i];
expect(await button.isDisplayed());
// do something
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句