SlimerJS added a onAuthPrompt
callback. Is it possible to get it to work with CasperJS?
I found mention that the phantomjs or slimerjs object is available as casper.page
, and then the following answer said that casper.page
is only available after calling casper.start()
: https://stackoverflow.com/a/16629231/841830
So I tried this code. The onAuthPrompt
code is taken from the documentation; I just added a log line to make sure it works.
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();});
});
It loads url
(which does not require auth), then an XMLHttpRequest
or EventSource
connection is made, which is what requires authentication. I see the password prompt pop-up but my onAuthPrompt()
function is not getting called.
Am I doing something wrong, or is this not what onAuthPrompt is for, or could it be a bug that I could report (but in that case, do you think the problem is in CasperJS or in SlimerJS?).