SlimerJS 添加了onAuthPrompt
回调。是否有可能让它与 CasperJS 一起工作?
我发现提到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 中?)。