Friday, September 5, 2008

Using Selenium on Windows platform

PHPUnit:
PHPUnit helps test the back-end of your web application by running through certain parts (units) and test them, comparing them with the expected output. It is a testing framework to create and run automated unit tests for your web application.

Selenium:
Selenium is a suite of test tools to help test the front-end of your web application. The front -end being the visual aspect, and browser compatibility. Using Selenium you can create automated tests to ensure your product is less prone to errors.

Steps to install and configure Selenium:

  1. Install PHP
  2. Install jdk (Java)
  3. Go to PHP folder and make sure there is a file "go-pear.bat"
  4. Go to command prompt and go to the PHP directory.
  5. Run the go-pear.bat. You can do it by typing go-pear on the command prompt and pressing enter. It will start the process to install PEAR in your PHP.
  6. After completing the PEAR isntallation, type these two commands and press enter subsequently:
    pear channel-discover pear.phpunit.de
    pear install phpunit/PHPUnit
    These two commands will install PHPUnit on your system.
  7. After PHPUnit installation, you need to install Testing_Selenium. To do so type the following on command prompt and press enter:
    pear install Testing_Selenium-beta
  8. Download Selenium RC (remote control) from http://selenium-rc.openqa.org/download.html.
  9. Unzip the Selenium RC folder and place it to easily accessible place like C:\ drive. (i.e. c:\selenium).
  10. Now run the Selenium server by using the following command on DOS prompt
    java -jar selenium/selenium-server.jar
    (You must be in the Selenium server directory on the command prompt)
  11. Install Selenium IDE to create test cases. Export the test cases as PHP test cases.
  12. After creating the test cases, you need to run them. For that purpose your current directory should be PHP (there will be a batch file named phpunit.bat). Type and enter the following command and the test will run:
    phpunit testname.php

    Thats it, enjoy working with Selenium.

2 comments:

erzf said...

Hi,

can you give another tuto or examples ?

firstly : how can i verify that a given div with an id is present in my page ... background color and so on ...

Prema said...

I tried the method you have mentioned but i am getting following warning.

warning:required_once(PHPUnit/TextUI/TestRunner.php):failed to open stream: No such file or directory in C:\wamp\php\PEAR\PHPUnit\TextUI\Command.php on line 47

Fatal error: require_once(): Failed opening required 'PHPUnit/TextUI/TestRunner.php'(include_path='.;C:\php5\pear') in C:\wamp\php\PEAR\PHPUnit\TextUI\Command.php on line 47

Can you please help me in solving this problem.

Thanks.