SeleniumTestCase Improvements in PHPUnit 3.2

Sebastian Bergmann » 21 August 2007 » in New Features » 5 Comments

Version 3.2 of PHPUnit is shaping up nicely. In this blog posting I want to highlight the 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');
    }
}
?>
In the above example, the test declared in the testTitle() 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 include more robust error handling and better error messages.
Defined tags for this entry: , ,

Trackback specific URI for this entry

5 Comments to "SeleniumTestCase Improvements in PHPUnit 3.2"

Display comments as (Linear | Threaded)
  1. Dirk
    06/09/2007 at 16:00 Permalink
    Hi Sebastian,

    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

  2. Sebastian Bergmann
    06/09/2007 at 20:30 Permalink
    Hello Dirk,

    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

  3. Dirk
    06/09/2007 at 22:21 Permalink
    Hello Sebastian,

    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

  4. Joshua
    14/07/2008 at 21:56 Permalink
    I have ran into this problem as well. I keep all my configuration of the browser values in xml files. I would like to be able to modify the browsers list when the test suite is setup by passing in the values. Having the browsers list static prevents this. =[

    Reply

  5. fett
    29/10/2007 at 11:54 Permalink
    Hi,

    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

0 Trackbacks to "SeleniumTestCase Improvements in PHPUnit 3.2"

  1. No Trackbacks

Add Comment


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Submitted comments will be subject to moderation before being displayed.