Javascript 如何在e2e测试中循环行和列

Javascript 如何在e2e测试中循环行和列,javascript,testing,protractor,end-to-end,e2e-testing,Javascript,Testing,Protractor,End To End,E2e Testing,我正在尝试测试我的表的内容,我需要遍历所有的行和列来完成这项工作。我目前的代码是: it('test', function () { var appRowLocator = by.repeater('appRow in model.getAppList()'); browser.wait(function () { return element(appRowLocator).isPresent(); }, 1000);

我正在尝试测试我的表的内容,我需要遍历所有的行和列来完成这项工作。我目前的代码是:

it('test', function () {
        var appRowLocator = by.repeater('appRow in model.getAppList()');

        browser.wait(function () {
            return element(appRowLocator).isPresent();
        }, 1000);

        var i = 0;
        element.all(appRowLocator).then(function(rows){
            expect(rows.length).toBe(2);
            while(i < 2){
                rows[i].all(by.tagName('td')).then(function(cols){
                    expect(cols.length).toBe(8);
                        expect(cols[0].getText()).toBe(summary.applicationSummaries[i].application.name);
                        expect(cols[2].getText()).toBe("");
                });
                i++;
            }
        })
    });
it('test',函数(){
var appRowLocator=by.repeater('appRow in model.getAppList()');
browser.wait(函数(){
返回元素(ApprovLocator).isPresent();
}, 1000);
var i=0;
元素.all(approvlocator).then(函数(行){
expect(行长).toBe(2);
而(i<2){
行[i]。全部(按.tagName('td'))。然后(函数(cols){
期望长度(cols.length)、toBe(8);
expect(cols[0].getText()).toBe(summary.applicationSummaries[i].application.name);
expect(cols[2].getText()).toBe(“”);
});
i++;
}
})
});
我正在访问单元格的内容,但测试仍然失败,因为行[I].all(..)中的计数器是递增的。我的行长度是预期的2,并且预期通过了,但我仍然不明白为什么在行[I].all(…)中也是反增量的。我得到的错误是:

失败:无法读取未定义的属性“应用程序”

这是因为它试图使用索引2访问应用程序,而数组中没有该元素。

这里不需要
then()
。使用
get()
并让
expect()
为您解决承诺:

var cells = rows[i].all(by.tagName('td'));

expect(cells.count()).toEqual(8);
expect(cells.get(0).getText()).toBe(summary.applicationSummaries[i].application.name);
expect(cols.get(2).getText()).toBe("");

是的,但是我失败了:无法调用undefinedelement.all(appRowLocator).then(函数(行){expect(行.长度).toBe(2);for(变量I=0;i@Sanja它仍然失败吗?我修复了它,但不得不使用承诺。尝试了你的方法,但没有成功