javascript - capture network resource requests on casper.click() -


with casper.on("resource.requested"), can capture resource requests , perform checks evaluation.

on page load, pushing network requests url in array , traverse array find number of calls google analytics (i.e. _utm.gif).

// google analytics calls testing casper.test.begin('test container tags', function suite(test) {      casper.start("http://www.viget.com/", function() {      });      var urls = [],         links = [];      casper.on('resource.requested', function(requestdata, resource) {         urls.push(decodeuri(requestdata.url));     });      casper.then(function() {         var index = -1;         var found = 0;         (var = 0; < urls.length; i++)          {             index = urls[i].indexof('__utm.gif');             if (index > -1)                 found = found+1;         }         casper.echo('found' + found);         test.assert(found > 0, 'page load test complete');     });      //emit "resource.requested" capture network request on link click     casper.then(function(self) {         var utils = require('utils');         var x = require('casper').selectxpath;         casper.click(x("//a[data-type]"));         casper.emit('resource.requested');     });      casper.run(function() {          test.done();     }); }); 

but, next ask verify network resource requests on hyperlinks click event. tried make work casper.emit("resource.requested") no success.

already spent 1 complete day find workaround same. feedback appreciated @ point.

you use casper.waitforresource() after click , validation there.

casper.test.begin('test container tags', function suite(test) {  casper.start("http://www.viget.com/", function() {  });  var urls = [],     links = [];  casper.on('resource.requested', function(requestdata, resource) {     urls.push(decodeuri(requestdata.url)); });  casper.then(function() {     var index = -1;     var found = 0;     (var = 0; < urls.length; i++)      {         index = urls[i].indexof('__utm.gif');         if (index > -1)             found = found+1;     }     casper.echo('found' + found);     test.assert(found > 0, 'page load test complete'); });  //emit "resource.requested" capture network request on link click casper.then(function(self) {     var utils = require('utils');     var x = require('casper').selectxpath;     casper.click(x("//a[data-type]"));  });  casper.waitforresource(function testresource(resource) {     console.log('----->' + resource.url); });  casper.run(function() {      test.done(); }); 

});


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -