量角器 - 索引越界.尝试访问索引处的元素:0



我想知道是否有人设法解决这个问题?基本上我使用这个功能

this.removeContributorFromPermissions = function(name) {
        $('button[title="Unlock owner management options"]').click();
        browser.sleep(2000); // here to create a delay until button appears.
        var remove = element.all(by.repeater('existingOwner in companyOwners')).filter(function(rowElement){
            return rowElement.element(by.css('td[ng-bind="existingOwner.Name"]')).getText().then(function(text){
                return text.trim() == name;
            });
        });
        remove.first().$('.btn.close').click();
        element(by.buttonText('Remove')).click();
    };

而这两个断言

it('Newly added new contributor is deleted from the company permissions', function() {
        settingsPage.removeContributorFromPermissions(browser.params.settings.contributors.newContributorName);
        var owners = element.all(by.repeater('existingOwner in companyOwners').column('existingOwner.Name'));
        expect(owners).not.toContain(browser.params.settings.contributors.newContributorName);
    });
it('Newly added existing contributor is deleted from the company permissions', function() {
        settingsPage.removeContributorFromPermissions(browser.params.settings.contributors.existingContributorName);
        var owners = element.all(by.repeater('existingOwner in companyOwners').column('existingOwner.Name'));
        expect(owners).not.toContain(browser.params.settings.contributors.existingContributorName);
    });

第一次迭代运行并成功删除用户,但第二次迭代在完成 browser.sleep(( 后停止;

完全错误

1) Testing company permission area Newly added existing contributor is deleted from the company permissions
  - Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator by.repeater("existingOwner in companyOwners")
我相信

你的 2 秒硬睡眠是不够的,这就是使测试变得不稳定的原因(在第一次迭代中就足够了,但在几秒钟内就不行了(。您是否考虑过使用预期条件

    var EC = protractor.ExpectedConditions;
    var repeaterElement = element(by.repeater('existingOwner in companyOwners'));
    //Wait up to 10 seconds for elements to be visible
    browser.wait(EC.visibilityOf(repeaterElement), 10000);
    var remove = element.all(by.repeater('existingOwner in companyOwners')).filter(function(rowElement){
            return rowElement.element(by.css('td[ng-bind="existingOwner.Name"]')).getText().then(function(text){
                 return text.trim() == name;
            });
    });
    remove.first().$('.btn.close').click();
    element(by.buttonText('Remove')).click();

最新更新