【问题标题】:How to wait until page loading image disappears in Protractor on non-Angular page如何等到页面加载图像在非 Angular 页面上的量角器中消失
【发布时间】:2017-02-16 14:33:49
【问题描述】:

在非 Angular 网站上,当我单击某个单选按钮时,会出现页面加载 gif。在量角器测试中,我想等到这个加载器 gif 消失,然后检查另一个元素。

加载器的 HTML(永远存在):

<div class="loader" style="display: none;">
    <div id="loader">
        <img src="/img/loading.gif">
    </div>
    <div class="totalMaskForLoader"></div>
</div>

我在测试中做了什么:

        ...
        //  click on balance dropdown
        page.sortByBalanceSelector.click();

        browser.wait(function() {
                    // return a boolean here. Wait for spinner to be gone.
                    return !browser.isElementPresent(by.css(".loader"));
                }, 20000);

        // compare to the starting player's username
        expect(page.hasText(page.usernameCellButton)).not.toContain(startingUsername);

问题是我总是得到

20009 毫秒后等待超时

如何等待加载器 gif 消失?

【问题讨论】:

  • return !browser.isElementPresent(by.css(".loader")); 为什么在这里使用not
  • 我明白你的意思,因为我复制了这个解决方案并且没有注意到这一点。

标签: javascript protractor gif loader


【解决方案1】:

有一个专门针对此用例的内置 invisibilityOf 预期条件:

page.sortByBalanceSelector.click();

var loader = element(by.id("loader"));
var EC = protractor.ExpectedConditions;

browser.wait(EC.invisibilityOf(loader), 5000);

您也可以使用stalenessOf,它的基本意思是“不存在”。


您当前方法的问题是您将“不”应用于isElementPresent() 返回的承诺,并且,由于承诺始终是真实的,因此您总是得到“错误”由于等待条件,因此超时错误。

【讨论】:

  • 问题解决了!谢谢你!我用过browser.wait(EC.invisibilityOf(loader), 5000);,它确实很有魅力。有人可以将我指向解释所有量角器预期条件的文档或页面吗?
  • 愚蠢的我,不需要链接到解释预期条件的页面,因为量角器页面已经涵盖:protractortest.org/#/api
猜你喜欢
  • 2018-03-03
  • 2015-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多