Sean’s Obsessions

Sean Walberg’s blog

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:


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

Comments

I’m trying something new here. Talk to me on Twitter with the button above, please.