承诺工作没有解决它在量角器



下面是我的页面对象代码

this.getRowBasedOnName = function (name) {
    return this.tableRows.filter(function (elem, index) {
        return elem.element(by.className('ng-binding')).getText().then(function (text) {
            return text.toUpperCase().substring(0, 1) === name.toUpperCase().substring(0, 1);
        });
    });
};

上述函数在同一页对象的另一个函数中调用,该函数为

this.clickAllProductInProgramTypeBasedOnName = function (name) {
   this.getRowBasedOnName(name).then(function (requiredRow) {
        requiredRow.all(by.tagName('label')).get(1).click();
    });
};

但是上面的代码在控制台中抛出了一个错误requiredRow。all不是一个函数

但是当我做以下操作时:

this.clickAllProductInProgramTypeBasedOnName = function (name) {
    var row = this.getRowBasedOnName(name)
    row.all(by.tagName('label')).get(1).click();
};

这个可以很好地点击所需的元素。

但是this.getRowBasedOnName()函数返回一个promise,它应该并且可以在使用then function解析它之后使用。为什么它能通过赋值给一个变量来工作呢?

当您解析getRowBasedOnName()的结果时,它是ElementArrayFinder,您将得到一个元素的常规数组,它没有all()方法。

您根本不需要解析getRowBasedOnName()的结果-让它成为ElementArrayFinder,您可以与all()链接,如第二个示例:

var row = this.getRowBasedOnName(name);
row.all(by.tagName('label')).get(1).click();

换句话说,requiredRow不是ElementArrayFinder,但row是。

最新更新