2017-08-24 203 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')) 
    }); 
});