And being composed of software, sometimes they break or stop working. The APIs from those huge web brands themselves are unlikely to be the cause of the problem. Rather, it's usually that I've got a bug in my JS. Yep. The scripts themselves go to work by finding a tag in the blog's HTML - like the tweet example below - using the tweet's id to fetch it via the Twitter API. Tweet received, the JS pushes the tweet's text into that [Tweet goes here] space. To paraphrase Cody Lindley's 'jQuery Enlightenment', jQuery is all about "Find stuff do stuff".
<span data-tweet-id="179313185281675264">[Tweet goes here]</span>So obviously I should test this HTML/JS/API interface. The problem is that since my JS services are spread unevenly among my blog posts (some posts only need tweets embedded, some need photos and Google Books, and so on) writing a test to hit the actual posts themselves would be tricky to say the least.
The testSo, like Victor Frankenstein, I decided to make something from disparate components as a sort of experiment in serving mankind. His effort was called "the monster", but mine can be called "an aggregation of my JS services into one master page". Another distinction between the two is that mine is unlikely to harm children. The idea is by loading all my scripts on this page, and reproducing my repertoire of HTML placeholders for photos, tweets, SO questions, etc. there, I can get a lot of testing bang for my buck.
That page has a custom JS file attached as part of the test harness, which is kind of the brains of the whole operation. Much like the "Frankenpage" itself, it gathers together the various JS methods required to convert the HTML to tweets, photos, etc. So, once you script up a simple test using Selenium to browse to the test page, the custom JS page executes too.
BDD - why not?For the purposes of clarity, I've chosen to use the excellent bddify to run the actual test. I was unsure as to whether taking a behaviour driven design approach made any sense if I'm the only one working on some code: BDD is probably considered over-the-top for a one-man scenario. But as Mehdi Khalili, the creator of bddify, explained when I asked him about this, even just for your own sake BDD can be a help keeping tabs on what the purpose of your test is.
As an aside, speaking of Selenium, the docs at Selenium HQ are actually written with a dose of wit. Read this, from 'Brief History of The Selenium Project':
The Beijing Olympics mark China’s arrival as a global power, massive mortgage default in the United States triggers the worst international recession since the Great Depression, The Dark Knight is viewed by every human (twice), still reeling from the untimely loss of Heath Ledger. But the most important story of that year was the merging of Selenium and WebDriver...