Differences between revisions 39 and 40
Revision 39 as of 2007-09-25 12:48:43
Size: 11245
Editor: guest-214
Comment:
Revision 40 as of 2007-09-25 13:24:56
Size: 11345
Editor: guest-214
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
SeleniumRCTesting Testing with SeleniumRC [wiki:Self:TestingWithSeleniumRemoteControl Testing with SeleniumRC]

[wiki:Self:AboutCharacterEncoding About character encoding (28May07)]

[wiki:TestingWithSeleniumRemoteControl Testing with SeleniumRC]

[wiki:AboutCharacterEncoding About character encoding (28May07)]

About character encoding (28May07 Markus)

CompleteSearch supports ISO-8859-1 and the multibyte character encoding UTF-8. UTF-8 is the default encoding with the following consequences:

  • The $AC->settings->encoding is 'utf-8' unless overriden in autocomplete_config.php

  • The texts in text.php are saved as UTF-8
  • The css file uses '@charset "utf-8";'
  • We use mb_strtolower (instead of strtolower) with parameter $AC->settings->encoding to enable UTF-8

We do the following depending on the defined encoding:

  • We UTF-8 encode $AC->settings->capitals if $AC->settings->encoding is UTF-8

  • In ajax.php we UTF-8 encode the query string if $AC->settings->encoding is UTF-8 and the charset of content_type is not UTF-8 (means the request is sent as a non-UTF-8 type)

  • We set the page encoding of index.php, options.php and change_options.php according to $AC->settings->encoding (<meta http-equiv="content-type" content="text/html;charset=<?php echo $AC->settings->encoding; ?>">)

  • Texts from text.php are UTF-8 decoded by $AC->get_text() if $AC->settings->encoding is ISO-8859-1

  • We url encode the javascript code in function javascript_rhs (in generate_javascript.php) if $AC->settings->encoding is not UTF-8 (this is not necessary if utf-8 is used)

Note: The form attribute accept-charset

If the form attribute accept-charset is set to "UTF-8" the form variables are UTF-8 encoded before sent to server (even if the page encoding is not UTF-8).

The PHP Apache extension php_mbstring

The use of the mb_strtolower function (and other mb_ functions) requires the extension php_mbstring in php.ini:

In windows:
extension=php_mbstring.dll

or in linux:
extension=php_mbstring.so

(On geek, the mb_... functions were available by default, on Markus' laptop the line above had to be added.)

If this is the first extension you use be sure to have specified the location of the extension with the extension_dir directive.

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
  • with test cases written by you in languages like PHP and using the Selenium (proxy) server (written in Java)

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

CompleteSearch: completesearch/Markus (last edited 2007-09-25 13:47:12 by guest-214)