As mentioned before, Selenium supports a wide range of languages to implement your tests. We decided us for PHP in the following explanations.

First we have to install the Selenium Server, a appropriate client driver (PHP client driver, for example) and PHPUnit. To do so, follow the [wiki:completesearch/SeleniumRC/SeleniumServer/Install instructions here].

After all required components are installed, we can have a more detailed look at the testing itself. Here an excerpt from the Selenium documentation:

First, make sure you've already started the Java Selenium Server separately in another process. The Selenium Server should remain up and running throughout this process; you shouldn't need to start/stop it each time you use the Client Driver. (Though, of course, if you need to start and stop the server, you certainly can, just by automatically starting it from the command line.)

Once you've installed the PHP Client Driver in one way or another, you'll need to require_once 'Testing/Selenium.php'; to get access to the Testing_Selenium class. (Make sure this path is in your include path!)

Then you can just create a new Testing_Selenium object, which is full of handy methods that handly your Selenium commands. You'll need to initialize the object using the hostname and port of the Selenium Server, the browser string to use with "getNewBrowserSession" (e.g. "*firefox"), and the base URL at which we'll start testing. When you're ready to begin, run the "start" method on your Testing_Selenium object; when it's time to close the browser, use the "stop" method. If one of the methods has an error, Testing_Selenium will throw a Testing_Selenium_Exception, which you can wrap up in a try/catch block if you like.

While we recommend that you use the PHP Client Driver together with a testing framework like PHPUnit, a testing framework is not required; you can use the PHP Client Driver with any program whatsoever to automate tasks in your browser.

Once you have written your first tests you have to do the following steps to run them:

Starting the Selenium RC Server

> java -jar selenium-server.jar

Calling PHPUnit with your test class

> phpunit AllTests c:\path\to\your\tests\AllTests.php

Where the file AllTests.php contains your test class AllTests. Be sure to wait with this call until the java server is ready to listen. If you call PHPUnit in the folder where your test file is located you don't need the path argument:

> phpunit AllTests

There are some needful options for calling PHPUnit, the following listing (taken from [http://www.phpunit.de/pocket_guide/3.1/en/textui.html here]) shows them:

Usage: phpunit [switches] UnitTest [UnitTest.php]

  --log-graphviz <file>  Log test execution in GraphViz markup.
  --log-json <file>      Log test execution in JSON format.
  --log-tap <file>       Log test execution in TAP format to file.
  --log-xml <file>       Log test execution in XML format to file.

  --coverage-xml <file>  Write code coverage information in XML format.
  --report <dir>         Generate combined test/coverage report in HTML format.

  --test-db-dsn <dsn>    DSN for the test database.
  --test-db-log-rev <r>  Revision information for database logging.
  --test-db-log-info ... Additional information for database logging.

  --testdox-html <file>  Write agile documentation in HTML format to file.
  --testdox-text <file>  Write agile documentation in Text format to file.

  --filter <pattern>     Filter which tests to run.
  --loader <loader>      TestSuiteLoader implementation to use.
  --repeat <times>       Runs the test(s) repeatedly.

  --tap                  Report test execution progress in TAP format.
  --testdox              Report test execution progress in TestDox format.

  --no-syntax-check      Disable syntax check of test source files.
  --stop-on-failure      Stop execution upon first error or failure.
  --verbose              Output more verbose information.
  --wait                 Waits for a keystroke after each test.

  --skeleton             Generate skeleton UnitTest class for Unit in Unit.php.

  --help                 Prints this usage information.
  --version              Prints the version and exits.

  -d key[=value]         Sets a php.ini value.

Very helpful, for example, is the --filter option to run only one test and not the complete sequence:

> phpunit --filter testMoreLess AllTests

Following a batch file to do this both steps for you:

@echo off

echo Starting JAVA server ...
echo.

rem Start the Selenium Proxy Server
start java -jar "C:\Program Files\Entwicklung\SeleniumRC\server\selenium-server.jar"

echo Waiting 3 seconds for start process ...
echo.

rem Trick, use ping with timeout for simulation of sleep functionality
ping -n 3 localhost  > nul

echo Starting test sequence ...
start phpunit AllTests E:\Projekte\Web\MPI\autocomplete-php\tests\AllTests.php

CompleteSearch: completesearch/SeleniumRC/SeleniumServer (last edited 2007-09-28 12:53:53 by dslb-084-058-232-124)