Windows LiveWriter Updated

I finally updated my install of Windows LiveWriter. It’s still a very simple tool to use and I find it very useful for offline editing of blog posts. The new version is noticeably faster to upload than the previous version, the UI looks nicer too, and I can easily switch between the various blogs I post on. The new add a plugin feature is also quite cool.

Automated regression testing and CI with Selenium PHP

I’ve been doing some work this iteration on getting Selenium RC integrated into our build process so we can run a suite of automated functional regression tests against our application on each build. The application I’m working on is written in PHP, normally when you use Selenium IDE to record a test script it saves it as a HTML file.

For example a simple test script that goes to Google and verifies that the text “Search:” is present on the screen and the title of the page is “iGoogle” looks like this:

  1.  
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>New Test</title>
  6. </head>
  7. <body>
  8. <table cellpadding="1" cellspacing="1" border="1">
  9. <thead>
  10. <tr><td rowspan="1" colspan="3">New Test</td></tr>
  11. </thead><tbody>
  12. <tr>
  13.     <td>open</td>
  14.     <td>/ig?hl=en</td>
  15.     <td></td>
  16. </tr>
  17. <tr>
  18.     <td>verifyTextPresent</td>
  19.     <td>Search:</td>
  20.     <td></td>
  21. </tr>
  22. <tr>
  23.     <td>assertTitle</td>
  24.     <td>iGoogle</td>
  25.     <td></td>
  26. </tr>
  27.  
  28. </tbody></table>
  29. </body>
  30. </html>
  31.  

You can choose to export the script in several other languages, including PHP, in which case the test script it produces looks like this:

  1. span class=”st0″>’Testing/Selenium.php’‘PHPUnit/Framework/TestCase.php’"*firefox", "http://localhost:4444/""/ig?hl=en""Search:""iGoogle"

The Export produces a valid PHPUnit test case that uses the Selenium PHP Client Driver(Selenium.php). Whilst the script is valid and will run you do need add a little more to it before the test will correctly report errors. As it stands all errors captured during the test are added to an array called verificationErrors, by catching the assertion Exceptions that are thrown when an assert fails, in other words if you ran this test as it is, and it did fail you wouldn’t know! To correct this we need to do two things. Firstly, each assert needs to have a message added to it which will printed out in the test report if the assert fails. Secondly we need to modify the tearDown method so that once a test has run, it checks the verificationErrors array, and if any failures have occurred, fails the test. After making these changes the PHP test script looks like this:

  1. span class=”st0″>’Testing/Selenium.php’‘PHPUnit/Framework/TestCase.php’"*firefox",
  2.                          "http://localhost:4444/""VERIFICATION ERRORS:""\n""/ig?hl=en""Search:"),
  3.                "The string Search: was not found""iGoogle",
  4.                    $this->selenium->getTitle(),
  5.                    "The page title did not match iGoogle."

Obviously, I have also given the PHP Class and test function slightly more meaningful names. Now you have a PHP Unit Test case that will use the Selenium PHP Client Driver with Selenium Remote Control to launch a browser, go to the specified URL, and test a couple of assertions. If any of those assertions fail, the tearDown method fails the test … pretty cool, right?

Well now it get’s better. Because the Selenium Client Driver has a published api which is pretty easy to follow, there’s no reason why you can’t just write test cases without using Selenium IDE … for those who want to you could even incorporate this into a TDD process. But for all this to hang together we need to be able to run a build, on a Continuous Integration server which checks out the code, runs unit tests and selenium regression tests against that code line, and only if all tests succeed passes the build.

We are currently using ANT, and CruiseControl to handle our CI/Automated build process. When running the automated suite of tests we need to ensure that the Selenium Remote Control server is also running which creates some complications. The Selenium Remote Control server takes several arguments which can also include the location of a test suite of html based selenium tests – which is really nice because the server will start, execute those tests and then end. Unfortunately you can’t invoke the server and pass it the location of a PHP based test suite. This means you need to find a way to start up the server, then run your tests, and once they are complete, shut the selenium server down.

He are the ANT targets that I have written to achieve this, if anyone can think of better ways of doing this I’d welcome any feedback or suggestions, to run this example you’d simply enter the command “ant selenium” :

  1.  
  2. <target name="selenium" depends="clean, init" description="Run the Selenium tests">
  3.   <parallel>
  4.     <antcall target="StartRCServer" />
  5.     <antcall target="RunSeleniumTests" />
  6.   </parallel>
  7. </target>
  8.                
  9. <target name="StartRCServer" description="Start the Selenium RC server">
  10.   <java jar="dependencies/SeleniumRC/lib/selenium-server.jar"
  11.         fork="true" failonerror="true">
  12.     <jvmarg value="-Dhttp.proxyHost=host.domain.com"/>
  13.     <jvmarg value="-Dhttp.proxyPort=80"/>
  14.   </java>
  15. </target>
  16.    
  17. <target name="RunSeleniumTests" description="RunAllSeleniumTests">    
  18.   <sleep milliseconds="2000" />
  19.   <echo message="======================================" />
  20.   <echo message="Running Selenium Regression Test Suite" />
  21.   <echo message="======================================" />
  22.   <exec executable="php"
  23.        failonerror="false"
  24.        dir="test/seleniumtests/regressiontests/"
  25.        resultproperty="regError">
  26.        <arg line="../../../dependencies/PHPUnit/TextUI/Command.php –log-xml ../../../doc/SeleniumTestReports/RegressionTests/TestReport.xml AllRegressionTests" />
  27.   </exec>
  28.   <get taskname="selenium-shutdown"
  29.     src="http://localhost:4444/selenium-server/driver/?cmd=shutDown"
  30.     dest="result.txt" ignoreerrors="true" />
  31.                    
  32.   <condition property="regressionTest.err">
  33.     <or>
  34.        <equals arg1="1" arg2="${regError}" />
  35.        <equals arg1="2" arg2="${regError}" />
  36.     </or>
  37.   </condition>
  38.  
  39.   <fail if="regressionTest.err" message="ERROR: Selenium Regression Tests Failed" />               
  40. </target>
  41.  

A couple of notes, the reason I have to use a conditional check at the end of the selenium target is because, if the exec task that runs the PHP tests was set to failonerror=true then the build would never reach the next line which shuts the Selenium RC server down. To ensure that always happens I have to set the exec to failonerror=false, but this means I have to check what the result was from the exec. Which if successful will return 0, if test failures exist will return 1, and if there were any errors (preventing a test to be exectuted ) will return 2. Hence the conditional check sets regressionTest.err if either of these latter two conditions are true.

Also in order to start up the server, which could take up to a second, but can’t be sure precisely how long. I have to use the Ant Parallel task, which calls the task to start the server and the task to run the tests at the same time. The task to run the tests has a 2 second sleep in it, which should be more than enough time to allow the server to start. This all kind of feels a little clunky, but at the moment it does work very well.

In a nutshell, thats how you integrate PHP based Automated Selenium Regression tests into a continuous build.

On an Eclipse of the Moon

Struggling, and faint, and fainter didst thou wane,
O Moon! and round thee all thy starry train
Came forth to help thee, with half-open eyes,
And trembled every one with still surprise,
That the black Spectre should have dared assail
Their beauteous queen and seize her sacred veil


                                    by Walter Savage Landor

Interesting PHP / XSL Cross Platform Defect

Came across a rather interesting cross platform problem whilst trying to perform a rather simple xsl transformation using PHP. To understand the problem take a look at this little snippet of XSL and see if you can spot what’s wrong with it:

  1.  
  2.   <xsl:template name="someTemplate">    
  3.     <xsl:for-each select="/rdf:RDF/rss:item" >
  4.     <xsl:param name="foo"/>
  5.     …
  6.     </xsl:for-each>
  7.   </xsl:template>
  8.  

The flaw in the snippet above is that it defines an xsl:param inside an xsl:for-each which is completely invalid. Now earlier today one of my colleagues was refactoring some XSL and whilst he was copying code from one template into another he inadvertently made the mistake above. Now you’d like to think that when you try to run the XSL through PHP that the invalid markup would throw an error. Well under PHP 5.2.2 on Window’s it doesn’t throw an error – in fact the XSL runs and performs the transformation. However when you run the same XSL under PHP running on Linux it quite rightly throws an error and informs you that the xsl:param is invalid.

I haven’t looked too deeply into why the invalid markup is accepted under Windows, I suspect it might have something to do with the php_xsl.dll that is comes as part of PHP 5.2.2, but it is something that made my jaw drop. Has anyone else experienced this?

Some more useful Firefox extensions

Been using several  very useful Firefox extensions that have made my life considerably easier lately.

The first is called Duplicate Tab, which allows you to create a new tab that duplicates a currently open tab – along with all its history. I’m finding this very useful when im writing SPARQL queries against our platform where I invariably end up having lots of tab’s open because I often write a query, run it, but then want to be able to keep the results open so I can write another query but to do that I have to manually open a tab, navigate to the bookmark … and thats tedious when your trying to get stuff done. Its so much nicer being able to run the query – and then duplicate the tab, hit back in the duplicated tab and now I have one tab with the results in it and one tab with the editing pane in it … away I go!

The second is the Google Preview extension. When you do a search in Google this extension inserts preview thumbnail images of websites, which I find quite useful.

The final extension is Pearl Crescent Page Saver (basic), which allows you to take a screenshot of the current page your viewing in the browser as a png. 

Book: The Cult of the Amateur

I just finished reading Andrew Keen’s The Cult of the Amateur, a highly provocative and controversial book that argues that the net’s user generated content is in fact destroying our culture.  Keen decries everything he believes to be wrong with the Web 2.0 which is namely the mediocre work of amateurs:

… democratization, despite its lofty idealization, is undermining truth, souring civic discourse, and belittling expertise, experience, and talent. As I noted earlier, it is threatening the very future of our cultural institutions. I call it the great seduction. The Web 2.0 revolution has peddled the promise of bringing more truth to more people—more depth of information, more global perspective, more unbiased opinion from dispassionate observers. But this is all a smokescreen. What the Web 2.0 revolution is really delivering is superficial observations of the world around us rather than deep analysis, shrill opinion rather than considered judgment. The information business is being transformed by the Internet into the sheer noise of a hundred million bloggers all simultaneously talking about themselves.

Moreover, the free, user-generated content spawned and extolled by the Web 2.0 revolution is decimating the ranks of our cultural gatekeepers, as professional critics, journalists, editors, musicians, moviemakers, and other purveyors of expert information are being replaced (“disintermediated,” to use a FOO Camp term) by amateur bloggers, hack reviewers, homespun moviemakers, and attic recording artists. Meanwhile, the radically new business models based on user-generated material suck the economic value out of traditional media and cultural content.

Keen is an excellent and engaging writer and whilst I dont actually agree with his views I did find them interesting, thought provoking and quite entertaining. I have to be honest, his over the top vitriol against the collaborative and distributed nature of the content generated on the internet in this Web 2.0 world, is at times so over the top that I couldn’t help but laugh.

Keen does raise some very important points about intellectual property, authenticity, authority and even identity and whilst its easy to dismiss some of his vitriol as the rantings of a self proclaimed (although  he was being sarcastic at the time :p ) “disgraceful fascist luddite communist control freak monarchist failed dotcom entrepreneur” ,you can’t dismiss the fact that some of concerns he raises are not only valid but deserve thought – even if you have to dig to see it! 

I also took the time to read one of the articles Keen wrote for the Washington Post in which he likens the promise of Web 2.0 to Marx’s promise of Communism …

Just as Marx seduced a generation of European idealists with his fantasy of self-realization in a communist utopia, so the Web 2.0 cult of creative self-realization has seduced everyone in Silicon Valley. The movement bridges counter-cultural radicals of the ’60s such as Steve Jobs with the contemporary geek culture of Google’s Larry Page. Between the book-ends of Jobs and Page lies the rest of Silicon Valley including radical communitarians like Craig Newmark (of Craigslist.com), intellectual property communists such as Stanford Law Professor Larry Lessig, economic cornucopians like Wired magazine editor Chris “Long Tail” Anderson, and new media moguls Tim O’Reilly and John Batelle.

You don’t have to like his views or even agree with them, but it would be a mistake to ignore them entirely. For that reason I think the  The Cult of the Amateur is a valuable text that will hopefully spur on some constructuve debates within the Web 2.0 community. 

Harry Potter and the Order of the Pheonix

I have had a very long week at work, it’s been a lot of fun but I often fall foul of becoming entirely absorbed with what i’m doing and that kind of tunnel vision leads to me totally ignoring everything else going on around me. Fortunately though I did get a chance to go out earlier on in the week to watch the new Harry Potter movie at the IMAX here in Birmingham.

The last 20 minutes of the movie where in 3D and it was stunning! 3D in cinema has come a long way, although I did find that after the film had ended I had an awful headache and felt quite dizzy for a day or so. Oh well!

The film itself was very enjoyable and whist the book was very dark and in ways very disturbing the film didn’t focus on the darker or sadistic elements of the fifth book. It’s also impossiblet to squeeze everything in the book into two and half hours on screen but I still found the film to be extremely enjoyable.

If you get the chance to watch it in 3D I do recommend it! It’s tonnes of fun!

Peter Morville talks to Talis

Last month I talked about Peter Morville’s tech talk over at Google about his new book Ambient Findability. Well last week Peter was interviewesto one of my colleagues here at Talis, Richard Wallis, about his book and his views on Web 2.0, information architecture, authority and a number of other issues you can listen to the podcast here…


Download MP3 [40 mins, 36Mb]>