1

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?).

Community
  • 1
  • 1
Darren Cook
  • 27,837
  • 13
  • 117
  • 217
  • What version of SlimerJS are you using? It looks like this feature was only added in version `0.9.0`. – hexid Oct 14 '13 at 21:50
  • @hexid Thanks, I'm using 0.8.3, which is the latest release at slimerjs.org (Sep 17th 2013). I've not managed to track down which commit onAuthPrompt was in, but it doesn't seem to have been since then. – Darren Cook Oct 14 '13 at 22:56
  • I will try a pure slimerJS test using that functionality, and see if and when it gets called... – Darren Cook Oct 14 '13 at 22:57
  • According to the documentation, it was added with 0.9.0. http://docs.slimerjs.org/nightly/release-notes.html#new-api – hexid Oct 15 '13 at 00:16
  • @hexid Aha! Thanks. So, it is vapourware currently, and they are documenting before releasing (which is a nice approach). I think if you post that as an answer I can give you the tick. ...But hang on, the code for it was committed 3 months ago: https://github.com/laurentj/slimerjs/commit/0304aaf3ab2dcd125a8f5892ebb4b03da83d4366 I wonder why it wasn't in the 0.8.3 release? – Darren Cook Oct 15 '13 at 00:22

1 Answers1

1

According to the documentation, the onAuthPrompt callback was added in version 0.9.0, which has yet to be released.

You can check the documentation from the master branch of the Git repo here.

There is also the latest released documentation (v0.8.3) here

hexid
  • 3,811
  • 1
  • 30
  • 40