1

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(不需要身份验证),然后建立XMLHttpRequestEventSource连接,这需要身份验证。我看到密码提示弹出,但我的onAuthPrompt()函数没有被调用。

我做错了什么,或者这不是 onAuthPrompt 的用途,还是我可以报告的错误(但在这种情况下,您认为问题出在 CasperJS 还是 SlimerJS 中?)。

4

1 回答 1

1

根据文档,onAuthPrompt回调是在 0.9.0 版本中添加的,尚未发布。

您可以在此处从 Git 存储库的主分支查看文档。

这里还有最新发布的文档(v0.8.3)

于 2013-10-15T00:57:09.320 回答