Skip to main content

Selenium 2 (WebDriver) and Phpunit?



Any one know how to use Selenium 2 with Phpunit? Are there any Selenium 2 samples in PHP?




Comments

  1. At the time of writing, PHPUnit does not support Selenium 2.

    php-webdriver from facebook allows the complete WebDriver API to be called from PHP in an elegant way. To quote:


    Most clients require you to first read the protocol to see what's
    possible, then study the client itself to see how to call it. This
    hopes to eliminate the latter step.


    It is used by starting up the Selenium 2 server, which provides the interface at localhost:4444/wd/hub.

    /usr/bin/java -jar /path/to/selenium-server-standalone-2.7.0.jar


    then running the PHP test code, which calls that interface. For example:

    <?php

    require '/path/to/php-webdriver/__init__.php';

    $webdriver = new WebDriver();

    $session = $webdriver->session('opera', array());
    $session->open("http://mysite.com");
    $button = $session->element('id', 'my_button_id');
    $button->click();
    $session->close();


    The WebDriver API is mapped to PHP methods, compare calling click on element in the example with the element/click API call in the documentation.

    The test code can then be wrapped in regular phpUnit tests.

    This is not native phpUnit support, but it's a quite robust approach.

    ReplyDelete
  2. PHPUnit Selenium integration code lives as a separate project in github, as far as I can see it does not support Selenium 2, so the answer to your question would be - No, you can not use Selenium 2 with PHPUnit.

    But you can clone the source tree and make it work with Selenium 2.

    ReplyDelete
  3. phpunit webdriver bindings are hosted on google code. There is something we need to understand beyond this.


    PHPUnit needs to be installed. (Either through PEAR package or download and install manually)
    PHP IDE such as Eclipse PDT has to be downloaded and installed.
    Selenium-Stand-Alone server has to be running while executing the WebDriver Selenium test

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?