Wed 04 Aug 2010
Measuring the speed of how long a page takes to load is becoming one of the most important metrics that we as software developers or testers can measure. This is because milliseconds can mean the difference between a sale being paid for or abandoned. A couple of years ago Amazon did research that showed for every 100ms slower the page was in loading they lost 1% of sales.
The downside to all of this is that we, as developers, testers and even ops, can only control the speed of things within our code and within our datacenters. With this in mind we should be trying to record all of the information that we can from within the browser. Last year at GTAC 2009 ( presentation video) David Henderson and I discussed how we used YSlow and Selenium to record page metrics and load times of the web application. We made the total primed page size decrease by 85% with the work we did.
To access this we need to get hold of the performance object and then get it to return a dictionary of all the timing data. The values that are returned are milliseconds from 1/1/1970. They give you all cool bits of information like how long it takes to unload a page you're on before navigating to the new page and how long that takes to load. It also tells you how long domain lookups take and how long redirects take. These are all neat tidbits of information when performance tuning your web application.
So below is a C# extension method that I have created that extends the WebDriver object to collect the information for you. Not all
browsers support this at the moment but as web timings becomes the standard the code will start returning data. Current browsers that
support this are Chrome 6 and IE9 pre3. A patch has been submitted to Mozilla for Firefox 4 so hopefully this will be applied soon.