Running multiple tests

63 views
Skip to first unread message

Joe Foulkes

unread,
Apr 9, 2014, 6:57:28 AM4/9/14
to casp...@googlegroups.com
I'm new to casperjs but just I've written a couple of UI tests which when run individually work just fine, however when I try to run them like this (i.e. run all tests from the 'ui' folder)...

casperjs test /ui --ignore-ssl-errors=true

... then I'm finding that the first test will work fine, however the second test will fail because it's using the same browser window as the first session.

In the interests of giving an easy example, here's a basic test that will open a website, login and do some assertion...

casper.start();
casper.test.on('fail', function() { casper.capture('fail.png'); });  
casper.open('http://dev.localhost');

casper.then(function () {   
    this.thenClick("header#js-page-head a.js-login", function() {
       this.fill('form#login', {
                'username': 'user1',
                'password': 'letmein'
       }, true);                   
    });        
});

casper.then(function () {
    this.waitForSelector('#welcome', function() {
        this.test.assert(true,'good, i am now logged in');
    });
});

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


That works fine when run on its own.

Again, for the sake of an easy example, lets say that I've got two versions of that test... 'ui/test1.js' and 'ui/test2.js'... they are exactly as above except they login as different users.

If I ask casper to run both tests (i.e. casperjs test /ui --ignore-ssl-errors=true), then I'm finding that test2.js will fail because when it tries to click the Login button (aka "header#js-page-head a.js-login") it can't because it's not there, that's because it's using the session left over from test1.js where the previous user is still logged in.

I know this is happening because when test2.js fails and captures the 'fail.png' screenshot, I can see that the user from test1.js is still logged in.

Is there not a way to reset the session between tests, or close it off after the casper.run() ??

Thanks
Joe

Joe

unread,
Apr 9, 2014, 8:29:54 AM4/9/14
to casp...@googlegroups.com
Found a solution, it's...

phantom.clearCookies();
Reply all
Reply to author
Forward
0 new messages