Skip to content

Instantly share code, notes, and snippets.

@mwcz
Last active August 12, 2018 08:29
Show Gist options
  • Save mwcz/7b96a741d2f1431c8199 to your computer and use it in GitHub Desktop.
Save mwcz/7b96a741d2f1431c8199 to your computer and use it in GitHub Desktop.
casperjs test case example
// googletesting.js
casper.test.begin('Google search retrieves 10 or more results', 5, function suite(test) {
casper.start("http://www.google.fr/", function() {
test.assertTitle("Google", "google homepage title is the one expected");
test.assertExists('form[action="/search"]', "main form is found");
this.fill('form[action="/search"]', {
q: "casperjs"
}, true);
});
casper.then(function() {
test.assertTitle("casperjs - Recherche Google", "google title is ok");
test.assertUrlMatch(/q=casperjs/, "search term has been submitted");
test.assertEval(function() {
return __utils__.findAll("h3.r").length >= 10;
}, "google search for \"casperjs\" retrieves 10 or more results");
});
casper.run(function() {
test.done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment