量角器 - 等待转发器元素

时间:2015-10-06 12:10:04

标签: javascript protractor wait angularjs-e2e e2e-testing

我使用Protractor进行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.timeout中的browser.wait(.....) 任何想法?

1 个答案:

答案 0 :(得分: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
});

如果你根本不知道要等待哪个元素,那么请检查最后加载的元素并等待该元素出现。通过这种方式,可以避免错误。希望它有所帮助。