我對casperJS.I有相對較新的腳本,我想在頁面B中執行操作(即驗證用戶的確認郵件),然後在頁面A中繼續執行。代碼段如下所示CasperJS WaitFor不等待條件完成
casper.waitFor(function(){
return this.run(function(){
return verifyEmail(user_details['email']);
});
},function then(){
this.wait(60000, function() {
this.reload(function(){
this.echo("Refresh");
this.capture('after-reload-a.png');
});
});
});
和verifyEmail被定義爲函數如下:
function verifyEmail(email){
return casper.open('someURL').then(function(response){
//extract URL from response
this.echo("URL"+url);
casper.start().thenOpen(url, function() {
this.waitForText('someText',function(){
this.capture("final.jpg");
});
});
return url;
});
};
執行期間,卡斯帕從未執行函數verifyEmail(從不打印URL),並用然後前進()功能。我在這裏錯過了什麼?
這是如何使用casperJS測試實例來實現的?是否有可能產生兩個實例? – Devi 2015-01-21 07:32:12
這是不可能的。但是,也許你可以完全忘記第二個實例或Ajax。看來你重新加載了原始頁面。你爲什麼不通常用'thenOpen'來訪問''someURL'',做你的解析,然後用'thenOpen'打開原來的URL而不用等待?你甚至可以得到當前的URL,以確保你回到正確的頁面。 – 2015-01-21 07:36:56