I'm trying to write tests for Google Analytics using CasperJS. For this I want to capture GA beacons so I can parse data from query string and write assertions.
Test is executed against staging version of website so it doesn't matter that data gets send to GA.
It's important to do this using navigation since I can't reach some pages without doing actions on previous ones (ie. have product in basket, fill in form etc.)
My problem is I can only capture GA beacon on first page and on next navigation no beacon requests get captured/requested. If I put another domain in navigation (ie. first URL is staging and next one is production) or when I navigate to URL that has redirection then I get beacon requests on both. I can't figure out is this GA or CasperJS issue. I tried to disable disk cache assuming that there is maybe issue but using --disk-cache=false doesn't seem to work for me.
Here is my code:
var startTime;
var beacons = [];
// make sure there is at least 2s since last network response
function networkIdle() {
var time = Date.now();
if (time - startTime > 2000) {
return true;
}
}
function onResourceRequested(data, req) {
// update time for newtworkIdle check
startTime = Date.now();
// collect beacons data
if (data && data.url && Utils.isBeaconUrl(data.url)) {
beacons.push(data.url);
}
}
casper.options.waitTimeout = 10000;
casper.test.setUp(function() {
startTime = Date.now();
casper.start();
casper.on('resource.requested', onResourceRequested);
});
casper.test.begin('Google Analytics', function(test) {
casper.open(URL1)
.waitFor(networkIdle, function() {
testBeacons(test);
casper.clear();
});
casper.thenOpen(URL2)
.waitFor(networkIdle, function() {
testBeacons(test);
casper.clear();
});
casper.run(function() {
test.done();
});
});
click()
, clickLabel()
and DOM click inside evaluate()
with same results.--
CasperJS homepage & documentation: http://casperjs.org/
CasperJS @github: https://github.com/n1k0/casperjs
You received this message because you are subscribed to the Google Groups "casperjs" group.
Visit this group at http://groups.google.com/group/casperjs?hl=en.
---
You received this message because you are subscribed to a topic in the Google Groups "CasperJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/casperjs/Wg98fjeRHNk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to casperjs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.