2017-10-11 87 views
1

我知道我可以使用waitForSelector來測試某個特定元素是否準備就緒,但JavaScript呢?測試是否使用casperjs評估/準備好所需的JavaScript文件

this.waitForSelector('#someid', function _then() { 
    // do something that requires js to be fully loaded and functional 
    // before clicking the submit button 
    self.click('#submit') 
}, function _timeout() { 
    fail('Page timeout') 
}) 

回答

0

什麼是您的jQuery插件究竟做的事:例如,如果我的頁面依賴於一個jQuery插件的工作,如果JS文件沒有得到正確加載下面的代碼可能會失敗?基於此,您可以使用

this.waitFor(function(){ 

     // return true based on your jquery plugin/ js code evaluation 
     // eg: if your jquery sets a variable $x=10 by evaluating a particular jquery plugin code. 
     return $x==10; 

    }, function(){ 
     // what to do after the js code called 

    }, function(){ 
     // when failed 
});