9 Our Selenium test as a PHPUnit test case
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class seleniumExampleTest extends PHPUnit_Extensions_SeleniumTestCase
{
protected function setUp() A
{
$this->setBrowser('*firefox');
$this->setBrowserUrl('http://www.google.com.au/');
}
function testMyTestCase() B
{
$this->open('http://www.google.com.au/');
$this->type('q', 'zend framework');
$this->click('btnG');
$this->waitForPageToLoad('30000');
try {
$this->assertTrue($this->isTextPresent('framework.zend.com/'));
} catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
}
}
A Setting up the default settings such as the browser to use and the domain name to work under
B Our test case which replicates the test we did in Selenium IDE
If you are being observant you'll notice that our test case is actually missing the part of the test we made
with Selenium IDE which operates within the zend.com domain. Because Selenium RC runs partly outside the
browser we run into issues with the "same origin policy" which prevents a document or script "loaded from
one origin from getting or setting properties of a document from a different origin." The original test we
recorded with Selenium IDE worked because it was running completely inside the browser as an extension.
Pages:
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299