Monday, July 5, 2010

Using Selenium for Meta tag testing

I recently tweeted that I had figured out how to use Selenium to test for meta tag content. Here is in an example using http://www.protegra.com/. On the Protegra home page, I wanted to make sure the following 2 tags existed:

<meta name="title" content="Protegra.com" /> 
<meta name="description" content="Business. Technology. Solutions." />

Obviously, meta tags don't show on the page at all, but do exist in the HTML. To test this manually, I would need to open the page in a browser, click view source, search for 'meta' and then manually compare the results to the expected meta tags. To test this using Selenium, all you need to do is create a test case that opens up Protegra.com and then uses VerifyElementPresent to search for each meta tag. The VerifyElementPresent command allows you to enter the name of the meta tag and the expected content in the format of :

//meta[@name='name of the meta tag' and @content='the expected content']

The Selenium test case html for the two meta tags I'm looking for looks like this:
<tr>
  <td>verifyElementPresent</td>
  <td>//meta[@name='title' and @content='Protegra.com']</td>
  <td></td>
</tr>
<tr>
  <td>verifyElementPresent</td>
  <td>//meta[@name='description' and @content='Business. Technology. Solutions.']</td>
  <td></td>
</tr>

Now I can run this test repeatedly to test for the expected meta tag content on the home page whenever I want without using manual effort.  I can also create similar tests for each page throughout the site and run them all consecutively.  Additionally, I could use Excel to generate the Selenium test case html for all my pages and meta tags without having to write the html manually or I could export this test case into C# (or any of the other programming languages supported by Selenium) and transform this test to lookup pages and meta tag values in a database table.  Fast and easy.

Friday, July 2, 2010

But does it work? - an agile metric

I've said publicly at conferences and other gatherings that my passion for agile and lean began years ago after a particularly troubling project that tried to be agile.  While that project had a strong team and eventually delivered a product, it had trouble with quality, scope and budget.  In retrospect the biggest problem was that we had little knowledge of what it meant to be agile - our process was flawed.  As a leader of that team, I took responsibility for the result and began a search to understand agile.  Borrowing a phrase from the agile manifesto, I wanted to 'uncover better ways'.

After implementing several changes to our process, my projects over the years seem to have improved significantly.  But how do you measure this?  While no metric should stand alone, here is one quality metric that I'm experimenting with:

((# of high defects * 5) + (# of medium defects * 3) + (# of low defects * 1) / Total project hours * 100.

The 'troubled' project had a score of 18.7.  My most recent project score was 1.2 which is almost a 1600% improvement on quality. I think I'll keep doing this agile thing.

P.S.  I'm heading to Agile2010 this summer.  Give me a shout if you are going and we can find ways to de-brief together over lunch or dinner in Orlando.