I am pretty new to CasperJS and I have started creating a test suite. Some of the steps (like logging in to the application) will be reused a lot, so we would like to manage them in library files (which are included in the test files).
Plus, we have multiple environments running (dev, integration, production etc.) so we need to parametrize the test steps for this, so it shall be possible to pass parameters to the modules.
I searched the documentation and stackoverflow (I am aware there are similar questions), but my Javascript skills are too limited obviously and I was not able to get this up and running.
This is my example test file:
// 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();
});
});
And this is how it should be like (or similar):
// googletesting2.js
casper.test.begin('Google search retrieves 10 or more results', 5, function suite(test) {
doGoogleSearch('casperjs'); // pass a search term
doChecks();
casper.run(function() {
test.done();
});
});