Angularjs 量角器:由中继器元素返回所有大小0

Angularjs 量角器:由中继器元素返回所有大小0,angularjs,jasmine,protractor,Angularjs,Jasmine,Protractor,我对量角器相当陌生,尝试学习自动测角()。我在JavaScript项目部分遇到了麻烦 有效的步骤: it ('should click on the plus sign', function() { $('.icon-plus-sign').click(); expect(element(by.model('editProject.project.name')).isPresent()).toBe(true); }); it ('should fill

我对量角器相当陌生,尝试学习自动测角()。我在JavaScript项目部分遇到了麻烦

有效的步骤:

it ('should click on the plus sign', function() {
        $('.icon-plus-sign').click();
            expect(element(by.model('editProject.project.name')).isPresent()).toBe(true);
});

it ('should fill up the form', function() {
            element(by.model('editProject.project.name')).sendKeys('Test Name');
            element(by.model('editProject.project.site')).sendKeys('https://www.testsite.com');
            element(by.model('editProject.project.description')).sendKeys('Test Description');
            expect(element(by.buttonText('Save')).getAttribute('disabled')).toBe(null);
});
失败的步骤:

it ('should click on save button', function() {
            element(by.buttonText('Save')).click();
            // $$('tr[class="ng-scope"]')
            element.all(by.repeater("project in projectList.projects | filter:projectList.search | orderBy:'name'")).then(function(trElements) {
                console.log(trElements.length);
                for (var i = trElements.length - 1; i >= 0; i--) {
                    console.log('outside if' + i);
                    if (trElements[i].all(by.tagName('td')).first().element(by.tagName('a')).getText() == 'Test Name') {
                        console.log('inside if' + i);
                        expect(trElements[i].all(by.tagName('td')).first().element(by.tagName('a')).getAttribute('ng-href')).toContain('www.testsite.com');
                        expect(trElements[i].all(by.tagName('td')).get(1).getText()).toBe('Test Description');
                        break;
                    }
                }
            });


            browser.sleep(5000);
});
treelements.length正在返回0,但元素肯定存在于DOM中,并在Chrome开发工具的元素选项卡中高亮显示

请帮我做这个


提前谢谢

在查询“treelement”之前,单击“保存”启动的操作未完成。在继续之前,请等待单击“保存”按钮时返回的承诺。即。
元素(按.buttonText(“保存”))。单击()
.然后(()=>{
元素。全部(由。中继器(。。。
});

单击“保存”后,您可能应该等待加载列表。测试可能比加载元素更快,在这种情况下,我们使用预期条件并等待列表可见(此处有API的完整文档):

var EC = protractor.ExpectedConditions;
element(by.buttonText('Save')).click().then(function() {
        // $$('tr[class="ng-scope"]')
   browser.wait(EC.visibilityOf(element(by.repeater("project in projectList.projects | filter:projectList.search | orderBy:'name'"))), 30000, "Project list is not displayed");
        element.all(by.repeater("project in projectList.projects | filter:projectList.search | orderBy:'name'")).then(function(trElements) {
            console.log(trElements.length);
            for (var i = trElements.length - 1; i >= 0; i--) {
                console.log('outside if' + i);
                if (trElements[i].all(by.tagName('td')).first().element(by.tagName('a')).getText() == 'Test Name') {
                    console.log('inside if' + i);
                    expect(trElements[i].all(by.tagName('td')).first().element(by.tagName('a')).getAttribute('ng-href')).toContain('www.testsite.com');
                    expect(trElements[i].all(by.tagName('td')).get(1).getText()).toBe('Test Description');
                    break;
                }
            }
        });
});