Working with Selenium-IDE & Running PHP Unit tests

By Vaishal,

Working with Selenium-IDE | Running Functional Tests | Runnig PHP Unit Tests

Selenium IDE is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests. Selenium IDE includes the entire Selenium Core, allowing you to easily and quickly record and play back tests in the actual environment that they will run.

Selenium IDE is not only recording tool: it is a complete IDE. You can choose to use its recording capability, or you may edit your scripts by hand. With auto-complete support and the ability to move commands around quickly, Selenium IDE is the ideal environment for creating Selenium tests no matter what style of tests you prefer.

1. Download selenium IDE. This will directly add IDE as fire-fox add-ons.

2. Start Firefox and then Start Selenium IDE: Tools->Selenium IDE.

3. Enter base url or open the site on which you want to perform functional testing. IDE will directly open in play mode with the entry of base url as below.

4. After starting the IDE now simply browse the site. It  makes entry in the table as below

Now the entire test is like

Now stop recording by pressing red button.

In html format it looks like

We can export this file in any format we want as

In PHP format it looks as

5. Now to run the recorded test open new browser and press the green – play button

6. The test will run as follow

7. If there will be any error then that test will be highlighted by red line as

8. If you are on a slow internet connection than it may help to slow the test speed.

9. You can save the test case in php as follow..

Required changes in the exported PHP file is as follow

a. Change the class name same as stored file name as default class name will be “Example”.
b. Enter the web-site name in the
$this->setBrowserUrl(“http://change-this-to-the-site-you-are-testing/”);
Field.
c. Available browser options are
*iexplore
*konqueror
*firefox
*mock
*pifirefox
*piiexplore
*chrome
*safari
*opera
*iehta
*custom
That is write as follow
$this->setBrowser(“*chrome”);
(When we define browser as chrome then no need to get security certificate but in case of firefox or iexplore we need to take certificate. )

10. Downloading and installing Selenium RC
Selenium RC is a Java based command line server that starts browsers and runs commands you pass from your tests.

a. First make sure you have a Java runtime installed on your machine.
Test the version of JRE by entering command on command line as –
java -version
b. Download Selenium RC.
c. After extracting the files from the archive copy the ‘selenium-server.jar’ file to any directory you feel appropriate.
d. Start the Selenium RC server from the command-line by issuing the following command:
java -jar selenium-server.jar
This will start the server on port 4444.
e. Now the server is ready to accept test commands from your PHP script. Make sure you keep this server running till you finish testing.

11. Changes in selenium-server.jar file requires to run in Firefox is as below:

a. Open selenium-server.jar using winrar
b. locate 2 dirs: customProfileDirCUSTFFCHROME and customProfileDirCUSTFF
c. recursively explore each of those dirs, and when you find a file called install.rdf drag it to some temp location, and edit the following line:
<em:maxVersion>2.0.0.*</em:maxVersion>
change it to:
<em:maxVersion>4.0.0.*</em:maxVersion>
d. drag the install.rdf back into the archive and overwrite the old one.
e. do this for all the install.rdf files in those 2 dirs.

12. Installing PHPUnit
a. An easy way to install PHPUnit is to use the PEAR installer. The PEAR channel (pear.phpunit.de) is used to distribute PHPUnit so make sure that it is registered with your local PEAR environment:
pear channel-discover pear.phpunit.de
After the channel is registered install PHPUnit:
pear install phpunit/PHPUnit
Actual testing

Now that PHPUnit is installed and the Selenium RC server is up and running, it’s time to run our test we saved before in our ‘Example.php’ file. Type the following on your command-line:
phpunit Example

13. This will start the test. The PHPUnit Selenium driver will execute each test command from your file and send it to the Selenium server, which does the job of launching the appropriate browser, opening web pages, and performing various specified actions; and closing the browser after the test completes.

This will open new browser as

After successful execution the output will be as

Note: All Images will coming soon.