1

casper (+phantom) でリダイレクトがあるかどうかを確認するにはどうすればよいですか? それを試してみてください :

casper.test.begin('\n********* check 301 : ***********', function(test){
    casper.start('http://www.linternaute.com/ville/rennes2/ville-35238', function(response){
        this.test.assertHttpStatus(301);    
    })
    .run(function() {
            this.test.comment('--- Done ---\n');
            test.done();
    });
});

casper+slimer では機能しますが、casper+phantom では機能しません。

curl -i http://www.linternaute.com/ville/rennes2/ville-35238

出力:HTTP/1.1 301 Moved Permanently

出力 casper+slimer :PASS HTTP status code is: 301

出力 casper+phantom : FAIL #current: 200, #expected: 301-> issue?

スリム化/ファントムの違い->When PhantomJS receives a redirection as HTTP response, it doesn’t call the onResponseReceive with the start status,slimerJS calls it

4

1 に答える 1

1

OK、詳細についてはRedirects not follow #442を参照してください。まだ 301 をテストしたい場合は、ここに解決策があります:

casper.on('resource.received', function(resource) {
    if(resource.url === 'http://www.linternaute.com/ville/rennes2/ville-35238'){
        this.test.assertEquals(301, resource.status);
    };
});

しかし、私は最終的にこの方法でリダイレクトをテストすることにしました (より簡単です):

casper.test.begin('\n********* check 301 : ***********', 1, function(test){
    casper.start('http://www.linternaute.com/ville/rennes2/ville-35238', function() {
        this.test.assertEquals(this.getCurrentUrl(), 'http://www.linternaute.com/ville/rennes/ville-35238');
    })
    .run(function() {
            this.test.comment('--- Done ---\n');
            test.done();
    });
});

現在の URL がリダイレクトに対応していることを確認するだけです...プロパティ 'openUrl' と 'urlRedirected' を持つオブジェクトで問題ありません - ループ中 -

于 2014-05-13T16:35:07.900 に答える