0

Currently I have script that logs in to website and then tracks for requests that are emited in this process. However I see that between 2 different pages my requests are the same and does not send user related data to tracker which means that there are no sessions between these pages in PhantomJS.

I listen to resource.requested and all of the requests are there, the problem is that there just isn't data in the last assertion, date that supposed to be injected between page 2 & 3.

Is this some phantomJS related weird behavior? Does anyone have any experience with it?

Here is my code:

var user, pass, url;

casper.on("resource.requested",function(resource){
    var match = resource.url.match("track_data");
    if(match!=null) casper.echo(resource.url);
 });

casper.test.begin('Tracking test',3,function suite(test){
    casper.start(url,function(page){
        this.test.assertHttpStatus(200,'Page opened');
 });
casper.then(function(){
    this.evaluate(function(username, password){
        document.querySelector('#email').value = username;
        document.querySelector('#password').value = password;
        document.querySelector('#submit').click();
    },user,pass);
    this.waitForResource(function(req){
        if(typeof document.sessionStorage !== "undefined") {
            casper.echo(JSON.stringify(document.sessionStorage,null,"   "));
        } // all off the sessions are undefined

        var match = req.url.match("track_user");
        if(match!=null) return true;
    },function(){
        this.test.assert(true,"User is tracked")
    },function(){
        this.test.assert(false,"Request not found");
    });
});
casper.wait(3000);
casper.then(function(){
        this.mouseEvent('click','.next-page');
        this.waitForResource(function(req){
            if(typeof document.sessionStorage !== "undefined") {
                casper.echo(JSON.stringify(document.sessionStorage,null,"   "));
            } // all off the sessions are undefined
            var match = req.url.match("id_user");
            if(match!=null) return true;
        },function(){
            this.test.assert(true,"ID is tracked")
        }, function(){
            this.test.assert(false,"Request 2 not found");
        });

});

casper.run(function(){
    test.done();
});
});

Thank you for your help.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Mario Nikolaus
  • 2,346
  • 1
  • 21
  • 28

0 Answers0