2017-08-24 201 views
0

我正在开发一个测试套件,并且我发现确保页面已准备好的唯一方法是选择器'div.spinner'消失。 我是能够做到抓与CapserJs这种情况下(与PhantomJs或SlimerJs):CodeceptJs等待一个元素从DOM中消失

casper.waitWhileSelector('div.spinner'); 

我不得不切换到codeceptjs 1.0.1与nightmarejs 2.10.1,我无法正确翻译这个条件。

我必须避免等待一些预定义的时间,因为我们有许多环境要测试,并且根据负载的不同,等待时间可以从1s到40s +不等。

目前我打算复制上codecept从卡斯帕功能Casper.prototype.waitWhileSelector

有谁有类似的问题?我是否错过了CodeceptJs中的某些功能?

Related github issue

在此先感谢

回答

0

作为参考,这种方法被合并名为waitUntilExists:

https://github.com/Codeception/CodeceptJS/pull/683 https://github.com/Codeception/CodeceptJS/issues/682

要使用它,你可以这样做:

describe('#waitUntilExists',() => { 
    it('should wait for an element to be removed from DOM',() => { 
    return I.amOnPage('/spinner') 
     .then(() => I.seeElementInDOM('.loader')) 
     .then(() => I.waitUntilExists('.loader')) 
     .then(() => I.dontSeeElement('.loader')) 
    }); 

    it('should wait for a non-exising element to be removed from DOM',() => { 
    return I.amOnPage('/spinner') 
     .then(() => I.dontSeeElement('.non-existing-class')) 
     .then(() => I.waitUntilExists('.non-existing-class')) 
     .then(() => I.dontSeeElement('.non-existing-class')) 
    }); 
});