SeleniumTestCase Improvements in PHPUnit 3.2
Version 3.2 of PHPUnit is shaping up nicely. In this blog posting I want to highlight the improvements to
Probably the most important improvement totestTitle() method will be run three times: once using Firefox on Linux, once using Safari on MacOS X, and once using Internet Explorer on Windows XP.
Other improvements to
SeleniumTestCase, PHPUnit's extension for Selenium.Probably the most important improvement to
SeleniumTestCase is the fact that you can now run each test using a set of browsers instead of just one browser:<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class WebTest extends PHPUnit_Extensions_SeleniumTestCase
{
public static $browsers = array(
array(
'name' => 'Firefox on Linux',
'browser' => '*firefox /usr/lib/firefox/firefox-bin',
'host' => 'my.linux.box',
'port' => 4444,
'timeout' => 30000,
),
array(
'name' => 'Safari on MacOS X',
'browser' => '*safari',
'host' => 'my.macosx.box',
'port' => 4444,
'timeout' => 30000,
),
array(
'name' => 'Internet Explorer on Windows XP',
'browser' => '*iexplore',
'host' => 'my.windowsxp.box',
'port' => 4444,
'timeout' => 30000,
)
);
protected function setUp()
{
$this->setBrowserUrl('http://www.example.com/');
}
public function testTitle()
{
$this->open('http://www.example.com/');
$this->assertTitleEquals('Example Web Page');
}
}
?>
Other improvements to
SeleniumTestCase include more robust error handling and better error messages.
06/09/2007 at 16:00 Permalink
thank you for this nice introduction to php unit using selenium. I have more complex scenarion in my mind and perhaps you can point me into the right direction.
Considering multiple TestCases perhaps even grouped in a hierarchy of TestSuites.
How could it be possible to easily switch between executing these test with one specific browser or with a whole set of browsers? Since the static member $browsers must be inside each TestCase this seems to be very problematic.
Reply
06/09/2007 at 20:30 Permalink
creating a subclass of SeleniumTestCase as a base class for your test case classes should do the trick. In this base class you can configure the Selenium RC servers.
Best regards,
Sebastian
Reply
06/09/2007 at 22:21 Permalink
a common baseclass is of course a solution. But then i would have to modify this base class for switching the set of browsers.
I would like to choose between the different browser sets without modifying the code. In the ideal case something loge the TestNG-stuff to select the set of browsers when calling phpunit ;-) It would already be more comfortable if this could be specified in a suite for sub-suites and tests at once.
Best regards,
Dirk
Reply
14/07/2008 at 21:56 Permalink
Reply
29/10/2007 at 11:54 Permalink
I've also hit this limitation. I would like to test with different browsers at different test-runs, depending on where I'm testing and what I want to test. A parametrized test-run, much alike test grouping. I was thinking about a test configuration file that I would specify as a parameter to phpunit. In this configuration file, I'd override the public static property $browsers of the tested class. It's not a serious hack, but it's hack nonetheless. I'm feeling that some kind of test environment configuration would soon come in handy.
Great work on PHPUnit, though. I've switched from SimpleTest and never looked back, what with all these new features. One thing I do miss though is a programmable browser within a test case. Selenium is often an overkill to write and to run every time. Simpletest has this and I used it quite often.
Reply