Skip to content

Instantly share code, notes, and snippets.

@danpalmer
Created June 14, 2012 11:40
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 danpalmer/2929799 to your computer and use it in GitHub Desktop.
Save danpalmer/2929799 to your computer and use it in GitHub Desktop.
Casperjs Multiple Tests
// Test 1
casper.start();
casper.open('http://localhost:3000/');
casper.then(function() {
// asserts
});
casper.run(function() {
// I can't mark as done here because the first test to finish will be used?
});
//
// Not sure how best to do this, can I put the whole of each test inside the start function and reference this?
//
// Test 2
casper.start();
casper.open('http://localhost:3000/');
casper.then(function() {
// asserts
});
casper.run(function() {
this.test.done();
});
@n1k0
Copy link

n1k0 commented Jun 14, 2012

Here's how I'd do it:

// Test 1
casper.start('http://localhost:3000/', function() {
  // asserts
});

// Test 2
casper.thenOpen('http://localhost:3000/', function() {
  // asserts
});

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

@danpalmer
Copy link
Author

Thanks for the reply, but does thenOpen keep the browser state? I ask because I need cookies to be reset and the only way I can find to make this happen is to have totally separate testing processes with their own start.

@n1k0
Copy link

n1k0 commented Jun 14, 2012

Hmm. Try with the clear() method, I think it also resets cookies as a side effect.

Otherwise, split your tests across two files and run the suite using $ casper test :)

@danpalmer
Copy link
Author

Ok, thanks for the tip, I didn't know about clear(). For the moment I'm running everything as a suite with casper test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment