量角器 - 使用另一个函数中的一个函数值的问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了量角器 - 使用另一个函数中的一个函数值的问题相关的知识,希望对你有一定的参考价值。
嗨,我是新的量角器,我有两个函数,第一个函数是返回一个promise,我想在第二个函数中使用它来从中检索值并使用它。
getColumnNumber(columnName) {
this.eh.waitForElement(this.GridsEleMap.get("HeaderTableHeaderRow"));
var colEle = this.GridsEleMap.get("HeaderTableHeaderRow").all(by.xpath(".//td//div[contains(@class,'text-content')]"));
return colEle.getText().then(function (text) {
var actIndex = text.indexOf(columnName) + 1;
logger.info("Column Index:" + actIndex);
});
}
clickRowElementUsingRowTextAndColumnName(rowText, columnName) {
var ele = this.GridsEleMap.get("BodyTable");
return this.getColumnNumber(columnName).then(function (result) {
logger.info("Text:" + result);
var cellEle = ele.all(by.xpath(".//tr//td[" + result + "]//div[@class='virtualLink']"));
logger.info("Result:" + cellEle);
return cellEle.filter(function (elem) {
browser.actions().mouseMove(elem).perform();
browser.sleep(50);
return elem.getText().then(function (text) {
return text.trim() === rowText.trim();
});
}).each(function (element) {
browser.actions().mouseMove(element).perform();
element.click();
browser.sleep(10*1000);
});
});
每当我试图在then
中使用clickRowElementUsingRowTextAndColumnName
函数的“result”对象应用于第一个函数时,它的值将变为未定义。请帮帮我。
我必须传递此结果值以形成特定列索引的xpath并对其执行操作。
答案
您应该正确返回第一个函数的值。您可以尝试以下代码,例如:
getColumnNumber(columnName) {
...
return colEle.getText().then(function (text) {
return text.indexOf(columnName) + 1;
});
}
如果你看到,它会返回actIndex
。
还要注意你没有正确链接的代码,所有的量角器方法都会返回需要链接的promises,以确保保持流同步。
然后,就像建议一样,尽量避免使用xpath
定位器。它们是不可读的,它们会降低性能。
以上是关于量角器 - 使用另一个函数中的一个函数值的问题的主要内容,如果未能解决你的问题,请参考以下文章