2015-10-06 125 views
2

我正在使用量角器进行e2e测试。目前我正在使用很多工作流程超时。我想用browser.wait替换它。问题是我并不总是知道该等什么。例如当切换到其他帧时。 这个特定的问题是等待中继器元素显示。 这是我当前的代码:量角器 - 等待中继器元素

flow.timeout(5000); 

    element.all(by.repeater('whatsNewItem in homePageWhatsNewItems')).count().then(function (firstCount) { 

    console.log("number of WhatsNew=" + firstCount); 
    expect(firstCount >= 5).toBeTruthy(); 
    }); 

我想更换flow.timeoutbrowser.wait(.....) 什么想法?

回答

4

如果您知道要等待哪个元素,则易于使用量角器的ExpectedConditions等待元素出现在页面上。下面是如何 -

var EC = protractor.ExpectedConditions; 
var repeaterElement = element(by.repeater('whatsNewItem in homePageWhatsNewItems')); 

//Wait up to 10 seconds for elements to be visible 
browser.wait(EC.visibilityOf(repeaterElement), 10000) 
.then(function(){ 
    //Perform any operation that you want after waiting for the element to appear 
}); 

如果你不知道要等到哪个元素,然后检查元素,在结束负载总是和等待元素出现。通过这种方式,可以避免错误。希望能帮助到你。

+0

看起来像它的作品。谢谢!只有一件事 - 它应该是'element(by.repeater ...') - 不包括'all' – user2880391

+0

@ user2880391更新了代码我认为你的HTML DOM中有许多中继器,如果它帮助你把它标记为答案,谢谢。 –