2014-02-26 21 views
0

我使用NightwatchJS用的NodeJS:http://nightwatchjs.org/apiNightwatchJS .waitForElementPresent abortOnFailure不工作

我有一個模式對話框,這可能會或可能不會出現。它有一個#close_button需要點擊(如果模態確實出現)繼續。

我將waitForElementPresentabortOnFailure參數設置爲false,因此如果模式沒有出現,腳本會繼續。但是我無法讓它工作。

有什麼建議嗎?

module.exports = { 
    "Test" : function (browser) { 
     browser 
      .url("http://domain.com/") 
      .waitForElementPresent('#close_button', 5000, false, function() { 
       this.click('#close_button') 
      }) 
      .setValue('#username', '[email protected]') 
      //more code here 
      .end(); //does end() go here or inside .waitForElementPresent() above? 
    } 
} 

回答

0

abortOnFailure工作正常,但現在waitForElementPresent在其中傳遞的回調它不是在正確的上下文中調用有一個bug。這將被修復。

在平均時間,你可以寫你的測試是這樣,與放置click之外,這是同樣的事情,看起來比較清爽:

module.exports = { 
    "Test" : function (browser) { 
    browser 
     .url("http://domain.com/") 
     .waitForElementPresent('#close_button', 5000, false) 
     .click('#close_button') 
     .setValue('#username', '[email protected]') 
     //more code here 
     .end(); // end() goes here 
    } 
} 
0

我碰到了類似的東西,我在等待一個iframe在場。我創建了一個功能,真正將其關閉:

pageObject功能:

Home.prototype.closeIframe = function(browser) { 
var self = this; 
console.log('Checking for iframe'); 
this.browser 
     .isVisible(iframeSelectors.iframe, function(result) { 
      if (result.value === true) { 
       self.browser 
         .log('iframe visible') 
         .frame(iframeSelectors.name) 
         .waitForElementVisible(iframeSelectors.closeLink) 
         .click(iframeSelectors.closeLink) 
         .assert.elementNotPresent(iframeSelectors.iframe) 
         .frame(null) 
         .pause(2000); //allow for proper frame switching 
      } else { 
       console.log('iframe is not visible'); 
      } 
     }); 

return this; 

在我的測試我等待頁面執行上面的函數之前完全加載。