量角器:browser.wait不在element.click()之后工作

时间:2016-06-12 22:20:00

标签: javascript angularjs promise protractor automated-tests

我使用量角器来测试this projecthere可以看到。

以下是测试:

  • 将延迟设置为2000毫秒。
  • 将持续时间设置为4000毫秒。
  • 单击演示按钮。
  • 时间并等待加载指示器(微调器)。
  • 写下等待的时间(或真实测试的断言)。

然而,browser.wait似乎没有返回。

代码:我认为应该有效......

//Inside it("test", function() {
set(delayInput, 2000); //custom sauce but it sets the element
set(durationInput, 4000); //custom sauce but it sets the element
var tStart = 0;
var spinner = element(by.css('.cg-busy.cg-busy-animation.ng-scope'));
var waitForMe = function() {
    return spinner.getAttribute('class')
        .then(data => data.includes('ng-hide') === false);
}
demoButton.click()
    .then(() => tStart = Date.now());
browser.wait(waitForMe, 4000)
    .then(() => console.log(Date.now() - tStart));

代码:也许其他应该有用的东西......(小差异)

demoButton.click()
    .then(() => tStart = Date.now());
    .then(() => 
        browser.wait(waitForMe, 4000)
            .then(() => console.log(Date.now() - tStart))
    );

代码:定位器和自定义调整

//btw, I can see the test correctly execute so I am actually getting the elements.
var delayInput = element(by.model('delay')),
    durationInput = element(by.model('minDuration')),
    demoButton = element(by.css('.btn')),
    spinner = element(by.css('.cg-busy.cg-busy-animation.ng-scope')),
    set = function(elem, data) {
        elem.clear();
        elem.sendKeys(data);
    };

我不断收到Failed: Wait timed out after 4056ms,这可能意味着spinner始终包含'ng-hide'。但是,如果我检查网页并手动运行测试,那就是' ng-hide'消失(这是有道理的)。所以,我认为这与承诺或阻止功能有关,但我不确定。

修改

代码:我也试过......

var EC = protractor.ExpectedConditions;
browser.wait(EC.visibilityOf(spinner), 4000)
    .then(() => console.log(Date.now() - tStart));

我尝试将持续时间和超时时间延长到15000毫秒。这个游戏我有以下错误:

Failed: Cannot assign to read only property 'stack' of Timed out waiting for Protractor to synchronize with the page after 11 seconds. Please see https://github.com/angular/protractor/blob/master/docs/faq.md
    While waiting for element with locator - Locator: By(css selector, .cg-busy.cg-busy-animation.ng-scope). 
    The following tasks were pending:
     - $timeout: function (){
                        tracker.durationPromise = null;
                    }

0 个答案:

没有答案