Skip to content

Instantly share code, notes, and snippets.

@drewwells
Created February 6, 2014 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewwells/8839350 to your computer and use it in GitHub Desktop.
Save drewwells/8839350 to your computer and use it in GitHub Desktop.
run via `casper test index.js`
var base = 'http://m.retailmenot.test';
var url = base + '/view/macys.com';
function getCookie (page, name) {
var cookies = page.cookies;
var val;
cookies.forEach(function (cookie) {
if (cookie.name === name) {
val = cookie.value;
}
});
return val;
};
var page1, page2, success, id,
ufv = [],
sliceCookie = [];
casper.test.begin(
'Cookies did not change across pages', function(test) {
casper.userAgent('iphone');
casper.start(url, function() {
ufv.push(getCookie(this.page, 'userFlashVersion'));
sliceCookie.push(getCookie(this.page, 'slice'));
/*page1 = 'Slice: ' +
getCookie(this.page, 'slice') +
' url: ' + this.getCurrentUrl() +
' userid: ' +
getCookie(this.page, 'userFlashVersion');*/
});
casper.then(function(){
id = this.evaluate(function(){
$(".js-offer").eq(0).trigger('tap');
$(".js-bad-touch span").eq(0).trigger('click');
return $(".js-bad-touch").data('offer-id');
});
if (id) {
success = true;
}
});
casper.then(function(){
casper.thenOpen(base + '/showcoupon/' + id, function(){
console.log('oc_slice: ' + getCookie(this.page, 'oc_slice'));
ufv.push(getCookie(this.page, 'userFlashVersion'));
sliceCookie.push(getCookie(this.page, 'slice'));
test.assertEquals(ufv[0], ufv[1], 'userFlashVersion matches');
test.assertEquals(sliceCookie[0], sliceCookie[1], 'slice matches');
});
});
casper.run(function(){
console.log(getCookie(this.page, 'oc_slice'));
test.done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment