【问题标题】:How to loop through rows columns in e2e test如何在 e2e 测试中遍历行列
【发布时间】:2015-03-18 09:51:16
【问题描述】:

我正在尝试测试我的表格的内容,我需要遍历所有行和列才能完成此操作。我当前的代码是:

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++;
            }
        })
    });

我正在访问单元格的内容,但测试仍然失败,因为计数器在 rows[i].all(....) 内递增。我的行长度是预期的两个,并且期望通过了,但我仍然很困惑为什么计数器在 rows[i].all(...) 内也增加。我得到的错误是:

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

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

【问题讨论】:

    标签: javascript testing protractor end-to-end e2e-testing


    【解决方案1】:

    这里不需要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("");
    

    【讨论】:

    • 是的,但后来我失败了:无法调用未定义的方法“getText”
    • element.all(appRowLocator).then(function(rows){ expect(rows.length).toBe(2); for(var i=0; i
    • @Sanja 还是失败了吗?
    • 我修复了它,但必须使用 Promise。试过你的方法,但没用
    猜你喜欢
    • 1970-01-01
    • 2019-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多