Skip to content

Instantly share code, notes, and snippets.

@tmbritton
Created January 30, 2014 04:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmbritton/8702872 to your computer and use it in GitHub Desktop.
Save tmbritton/8702872 to your computer and use it in GitHub Desktop.
casper.js testing test
/**
* Casper.js testing test
*/
var testSuite = {
config: {
baseUrl: 'http://www.wholefoodsmarket.com',
},
googleTest: function(){
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();
});
});
},
wfmHomePage: function() {
casper.test.begin('Whole Foods Market home page loads', 4, function suite(test) {
casper.start(testSuite.config.baseUrl, function() {
/**
* Assert welcome box displays.
*/
test.assertVisible('.welcome-box', "Welcome box is visible.");
/**
* Assert there are two or more marquees.
*/
test.assertEval(function() {
return __utils__.findAll('.marquee-container').length >= 2;
}, 'There are more than two marquees on the home page.');
/**
* Assert there is at least one tweet.
*/
test.assertEval(function() {
return __utils__.findAll('.tweet-content').length >= 1;
}, 'There are tweets on the home page.');
/**
* Assert there is at least one facebook update.
*/
test.assertEval(function() {
return __utils__.findAll('.facebook-post-fetcher-item').length >= 1;
}, 'There are Facebook updates on the home page.');
});
casper.run(function() {
test.done();
});
});
},
wfmSearch: function () {
casper.test.begin('Whole Foods Market global search', 3, function suite(test) {
casper.start(testSuite.config.baseUrl, function() {
test.assertExists('#search-api-page-search-form-global-search', "Global search form found");
this.fill('#search-api-page-search-form-global-search', {
keys_16: "Cheese"
}, true);
});
casper.then(function() {
test.assertUrlMatch(/site_search\/Cheese/, "Search result page loads");
test.assertEval(function() {
return __utils__.findAll('.search_result_item').length >= 10;
}, 'Search for "Cheese" returns multiple results.');
});
casper.run(function() {
test.done();
});
});
},
wfmStoreSearch: function () {
casper.test.begin('Whole Foods Market store search', 2, function suite(test) {
var storeSearchLink = '.store-box a';
casper.start(testSuite.config.baseUrl, function() {
test.assertExists(storeSearchLink, "Store search link found");
});
casper.then(function(){
this.click(storeSearchLink);
});
casper.wait(3000, function() {
casper.then(function(){
test.assertExists('#modalContent .view-store-lookup-by-address', "Store search pop-up is found");
});
});
casper.run(function() {
test.done();
});
});
},
init: function() {
testSuite.wfmHomePage();
testSuite.wfmSearch();
//testSuite.wfmStoreSearch();
},
};
testSuite.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment