I have just pushed to the Element 34 PEAR server a new package for manipulating HTTP Archive (HAR) files. PHPHARchive will parse a HAR file and give it a bit of a programatic way of interacting with its contents.

To install…

pear channel-discover
pear install -f element-34/PHPBrowserMobProxy

Teasing out information about requests and responses via a HAR file is the proper way to check response codes, etc. (Please stop adding to the WebDriver issue about this.)

Here is the PHPUnit script thats was used in the Get Rid of 3rd Party Crap post which introduced the BrowserMob proxy (and its integration with SaunterPHP). It has been modified to use HTTP Code 306 rather than 200 for blacklisted sites and then asserts that there is only one that is caught in that web.

namespace WebDriver;

require_once 'tailored/EBayTestCase.php';
require_once 'pages/ShirtPage.php';
require_once 'PHPHARchive/HAR.php';

class BlacklistTest extends EBayTestCase {
    * @test
    * @group shallow
    * @group ebay
    * @group blacklist
    public function collar_style() {
        $this->client->blacklist("http://www\\.facebook\\.com/.*", 306);
        $this->client->blacklist("http://static\\.ak\\.fbcdn\\.com/.*", 306);
        $sp = new ShirtPage($this->session);
        $har = $this->client->har;
        $h = new \PHPHARchive_HAR($har);
        $entries = $h->get_entries_by_page_ref("page_1_0");
        $three_oh_sixes = array();
        foreach ($entries as $entry) {
          if ($entry->response->status == 306) {
            array_push($three_oh_sixes, $entry);

        $this->assertEquals(count($three_oh_sixes), 1);

While you wouldn’t necessarily be checking for 306s in your scripts, 404 and 302 could be interesting to capture and make pass/fail decisions upon.

Post a Comment

Your email is never published nor shared. Required fields are marked *