Sean’s Obsessions

  • Archives

29 Feb

Testing via screen scraping

Trying to figure out how to write a test based on screen scraping. Easiest example is to make sure that certain URIs redirect to the login screen.

Created an “automated” dir under app/tests/cases/, with a file called permissions.test.php:

<?php

class PermissionsTestCase extends CakeWebTestCase {

        var $mysite = "http://test.mysite.com";
        function setUp() {
        }

        function tearDown() {
        }

        function testMe() {

                $this->setMaximumRedirects(0);
                $result = $this->get($this->mysite . "/");
                $this->assertResponse(302);
                $this->assertHeader("Location", $this->mysite . "/users/login", "Homepage redirects to login");
        }
}
?>

The “setMaximumRedirects” is there because WebTestCase will, by default, follow 3 redirects. Here I tell it not to, then I get a page and check the status code and the header.

Lots of stuff you can test specific to a web page: http://simpletest.org/api/SimpleTest/WebTester/WebTestCase.html

Leave a Reply

Your blog, no spam: the intense, fair, and titanic Wordpress Spam-be-gone plugin?

© 2008 Sean’s Obsessions | Entries (RSS) and Comments (RSS)

Powered by Wordpress, design by Web4Sudoku, based on Pinkline byGPS Gazette