March 11, 2011 Stoyan Stefanov, the creator of smush.it, architect of YSlow 2.0 and engineer at Facebook, has written an excellent three part guide to controlling HttpWatch from PHP:
He’s even published a class that wraps the HttpWatch API and makes it easier to use from PHP.
In the rest of this blog post we wanted to follow up on a few points mentioned in Stoyan’s blog posts. These items don’t just apply to PHP. You may find them useful when automating HttpWatch using other languages such as C# or Ruby.
The ‘A better experience in IE’ section of Automating HttpWatch with PHP shows how you can hide the IE browser window during tests by separately creating IE and attaching HttpWatch to it.
It’s also possible to do this using the Container property without having to separately create and attach to IE:
$controller = new COM("HttpWatch.Controller"); $plugin = $controller->IE->New(); $browser = $plugin->Container; // Only works with IE $browser->Visible = false;
If you do decide to do this in order to stop windows popping up during a test please bear these points in mind:
It’s often handy to open the HttpWatch window in the browser when you are developing an automation script so that you can check that it is working as expected.
The OpenWindow method allows you to do this and specify whether you want the HttpWatch window docked or undocked. For example, here is the PHP code to open HttpWatch as an embedded window in the browser:
... // Open docked HttpWatch window in browser $plugin->OpenWindow(false); ...
In part 3, Stoyan mentions using try-catch to handle the errors that occur when attempting to access data that is restricted in HttpWatch Basic Edition. While this is a valid approach, there is a risk of hiding other errors that might be occurring that are not due to the restrictions in HttpWatch Basic edition.
There are a couple of properties in the HttpWatch automation interface that help you handle the differences. The first is the IsBasicEdition property on the Controller class.
For example, here’s a high level test in PHP:
$controller = new COM("HttpWatch.Controller"); if ( $controller->IsBasicEdition ) { echo "\nThis test requires HttpWatch Professional Edition"; }
At a lower level, you can also check each request to see if it has been restricted using the IsRestrictedURL property:
... if ( $entry->IsRestrictedURL) { // Goes here in HttpWatch Basic Edition for URLs outside Alexa Top 20 echo "\nSome of the properties for this request are restricted"; } else { // Goes here in HttpWatch Basic Edition for URLs in Alexa Top 20 // or in HttpWatch Professional Edition for any URL echo "\nAll the properties of this request are available"; } ...
Posted on March 11, 2011 in
Automation,HttpWatch
Tags: Automation,HttpWatch,php
RSS for this post |Trackback URL
This is perfect, thanks for the clarifications! Access to the IE container sounds perfect, as does the ability to have the httpwatch window on :)
Pingback: HTTPWatch automation with JavaScript / Stoyan's phpied.com