Differences between revisions 8 and 9
Revision 8 as of 2007-09-28 11:35:02
Size: 9287
Editor: dslb-084-058-232-124
Comment:
Revision 9 as of 2007-09-28 12:28:40
Size: 1163
Editor: dslb-084-058-232-124
Comment:
Deletions are marked like this. Additions are marked like this.
Line 17: Line 17:
== 1 Selenium IDE ==
Testing with the Selenium IDE is the easiest way but only works with firefox, that means no cross browser testing. You have to open the following url with Selenium IDE extension installed in your firefox browser:
{{{
chrome://selenium-ide/content/selenium/TestRunner.html?baseURL=http://search.mpi-inf.mpg.de/markus/&test=http://search.mpi-inf.mpg.de/markus/tests/TestSuite.html&auto=true
}}}
where baseURL is the location of the web site to test and test is the start location of the test suite, means the code of the tests generated with the Selenium IDE

== 2 Selenium server ==
Install the following:

=== 2.1 Selenium Java Server ===
The Selenium Server is written in Java, and requires the Java Runtime Environment (JRE) version 1.5.0 or higher in order to start. To use this package, you need to have selenium-server.jar. You can download selenium-server.jar from http://www.openqa.org/selenium-rc/ (be sure to get 0.9.1 or higher) or get it from [http://search.mpi-sb.mpg.de/markus/tests/selenium-remote-control-0.9.1-SNAPSHOT.zip here].

=== 2.2 PHP ===
If you use PHP to write tests you must install the PHP Client Driver. It's recommended to use your PHP tests together with a testing framework like PHPUnit (althought a testing framework is not required because you can use the PHP Client Driver with any program whatsoever to automate tasks in your browser). Note: a short overview about PHPUnit and Selenium you will find [http://www.phpunit.de/pocket_guide/3.0/en/selenium.html here].

==== 2.2.1 Installing the PHP Client Driver and PHPUnit ====
The easiest way to install PHPUnit and the Selenium PHP client driver is using PEAR. On Linux systems it's normally already installed, on Windows you can follow the next paragraph.

Note: our PHP installation (PHP 5.2.1) results in errors when try to install PEAR. Updating to PHP 5.2.3 fixed this failure.

==== 2.2.1.1 Excursus: Installing PEAR on Microsoft Windows ====
On Windows, PEAR is included in current PHP releases (> PHP 5.2). Look for a file named "go-pear.bat". Execute this file and follow the intructions. Note, that there is a known bug with go-pear bundled with PHP 5.2.0. So use a newer PHP release.

If you don't have PEAR bundled with you PHP [#1 here] is an alternative to install PEAR.

Ok, now PEAR is installed, we can use it to install PHPUnit and the PHP client driver.

==== 2.2.1.2 Installing PHPUnit ====
Homepage: [http://phpunit.de/]

The [http://www.phpunit.de/pocket_guide/3.1/en/index.html pocket guide] of Sebastian Bergmann give a detailed view in PHPUnit (german version [http://www.phpunit.de/pocket_guide/index.de.php here]).

The PEAR channel (pear.phpunit.de) that is used to distribute PHPUnit needs to be registered with the local PEAR environment (be sure to be in the folder where pear.bat is located or to have add the path of pear.bat to the PATH varibale before):
{{{
> pear channel-discover pear.phpunit.de
}}}
This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel:
{{{
> pear install phpunit/PHPUnit
}}}
Ok, now PHPUnit is installed.

==== 2.2.1.3 Installing the PHP client driver ====
The current version auf the PHP client driver is Testing_Selenium-0.3.2. To install it (be sure to be in the folder where pear.bat is located or to have add the path of pear.bat to the PATH varibale before):
{{{
> pear install Testing_Selenium-beta
}}}
Ok, now the PHP client driver is installed.


=== 2.2.2 Testing with Selenium ===

Following 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.

==== 2.2.2.1 Starting the Selenium RC Server ====
{{{
> java -jar selenium-server.jar
}}}
==== 2.2.2.2 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
}}}

== Appendix ==
[[Anchor(1)]] Alternative to install PEAR on Windows: you have to download go-pear first:
{{{
> php -r "readfile('http://pear.php.net/go-pear');" > go-pear
}}}
Now install PEAR:
{{{
> php -q go-pear
}}}
We use a mixture of both ways: writing new tests and debugging is easy with the Selenium IDE. Then we export the test as PHP and integrate the generated code in our test classes.

Testing with Selenium remote control (short: SeleniumRC)

Homepage: [http://www.openqa.org/selenium-rc/ http://www.openqa.org/selenium-rc/]

"Selenium Remote Control (SRC) is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser. SRC provides a Selenium Server, which can automatically start/stop/control any supported browser. It works by using Selenium Core, a pure-HTML+JS library that performs automated tasks in JavaScript; the Selenium Server communicates directly with the browser using AJAX (XmlHttpRequest)." [from: http://pear.php.net/package/Testing_Selenium]

There are two ways to use SeleniumRC:

  • with the Selenium IDE, a firefox extension [wiki:SeleniumIDE [read more]]

  • with test cases written by you in languages like PHP and using the Selenium (proxy) server (written in Java) [wiki:SeleniumServer [read more]].

We use a mixture of both ways: writing new tests and debugging is easy with the Selenium IDE. Then we export the test as PHP and integrate the generated code in our test classes.

CompleteSearch: completesearch/Markus/TestingWithSeleniumRemoteControl (last edited 2007-09-28 12:45:20 by dslb-084-058-232-124)