SlimerJS增加了一個onAuthPrompt
回調。是否有可能使它與CasperJS一起使用?使用onAuthPrompt()與CasperJS和SlimerJS
我發現一提的是,phantomjs或slimerjs對象可用作casper.page
,然後將下面的回答說,casper.page
只是調用casper.start()
後可用:https://stackoverflow.com/a/16629231/841830
所以,我想這個代碼。 onAuthPrompt
代碼取自文檔;我只是添加了一個日誌行來確保它能夠正常工作。
casper.test.begin("first",function suite(test){
casper.start();
casper.page.onAuthPrompt = function (type, url, realm, credentials) {
console.log("onAuthPrompt: type="+type+",url="+url+",realm="+realm+",credentials="+credentials); //TEMP
credentials.username = "laurent";
credentials.password = "1234";
return true;
};
casper.thenOpen(url,function(){
console.log('Loaded:'+url);
test.assertSelectorHasText('#msg','');
this.capture('1.png');
});
casper.run(function(){test.done();});
});
它加載url
(不需要身份驗證),那麼XMLHttpRequest
或EventSource
連接而成,這是需要驗證。我看到密碼提示彈出,但我的onAuthPrompt()
函數沒有被調用。
我做錯了什麼,或者這不是onAuthPrompt的用處,或者它可能是我可以報告的錯誤(但在這種情況下,您認爲問題出在CasperJS或SlimerJS上?)。
您正在使用什麼版本SlimerJS最新發布的文檔(v0.8.3)?看起來這個功能只是在0.9.0版本中添加的。 – hexid
@hexid謝謝,我正在使用0.8.3,它是slimerjs.org(2013年9月17日)的最新版本。我沒有設法追蹤到AuthPrompt在哪個提交中,但似乎從那時起就沒有。 –
我會嘗試使用該功能的純slimerJS測試,並查看它是否以及何時被調用... –