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

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.