Created
April 2, 2015 10:34
-
-
Save lf94/e4fc5fb299acc7289c43 to your computer and use it in GitHub Desktop.
A CasperJS test case to determine if Reddit has cats on its front page or not.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Your test cases begin in here. | |
casper.test.begin("Reddit Top Links Tests", 1, function(test) { | |
// Your first test case starts here. | |
casper.start("http://reddit.com/", function() { | |
// In here, we have access to the website's (reddit's) DOM! | |
/* | |
So what we're doing is selecting all the entry links, | |
and then extracting their text, and then filtering | |
the link's text based on if they have the word "cat" | |
or not. | |
*/ | |
links = document.querySelectorAll(".entry p a"); | |
links = Array.prototype.map.call(links, function(el) { | |
return el.childNodes[0].data; | |
}); | |
links = links.filter(function(el) { | |
return (el.indexOf("cat") >= 0); | |
}); | |
// We check to see if we have any cat-related links. If we do the test case passes! | |
test.assertEquals(links.length > 0, true, "Meowston we have cats!!!"); | |
}); | |
// This is how you run the test cases. | |
casper.run(function() { | |
test.done(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment