Wednesday, July 16, 2014

SetUp Your PHP Selenium Test Project with XAMPP

To Setup the Php Test project with Selenium the following are required:
1.       PHPStorm IDE by Jet brains: http://www.jetbrains.com/phpstorm/
2.       Xampp for Downloading the “PHPUnit” and “PHP Interpreter”. XAMPPhttps://www.apachefriends.org/download.html
        Installing PEAR & PHPUnit with XAMPP
1.        Once you install the Xampp server, launch the XAMPP control panel and start the Apache Server.
Note: If you have Skype or any other application that uses the port 443 then change/reconfigure the Xampp default port.
XAMPP Control Panel

2.        Start the Apache Server Now by clicking the Start button under Actions. Then you should see status message and the port info on which the server is running.
3.        Now Click on Shell button in the XAMPP control panel. Then you should see the XAMPP Admin Console.
4.        Now, go to http://pear.php.net/go-pear.phar and download pear file to download and configure PHPUnit.
Once you download the .phar file place the file in C:\XAMPP\Php folder
5.        In the Console navigate to XAMPP php folder using command line:
# cd c:\xampp\php
and then use the command to install the pear file
# php go-pear.phar
And press Enter.
Then the following should be displayed.
“Are you installing a system-side PEAR or a local copy?
<system|local> [system]: system
And press Enter twice.
6.        Now the PEAR file should be installed on your local at system-wide. And you should see the following message.
7.        Run the C:\xampp\php\PEAR_ENV.reg file created to import your PEAR environment variable settings. This is not a mandatory task(recommended to avoid this Registry setting)
A Confirmation should be displayed up on clicking the Registration file
Click Yes. And you should see the following Information message box.
8.        Log out of Windows and back in - This will load the new environment variables into memory (otherwise the old location for pear.ini will be used).  Confirm your settings by running:
# pear config-show
It should show “C:\xampp\php\pear.ini” for User Configuration File.
9.        Now, install PHPUnit & Skeleton Generator through PEAR using the following commands
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit
pear install phpunit/PHPUnit_SkeletonGenerator

10.     Check your version of PHPUnit - It should be at least version 3.6.x
phpunit –version

You should also now have phpunit-skelgen.bat in the C:\xampp\php folder.
Netbeans NOTE:
Netbeans to do unit testing in PHP refer: http://netbeans.org/kb/docs/php/phpunit.html#installing-phpunit

Install PHPUnit Selenium Extension:
1.        Use the following command to install PHPUnit Selenium Extension
Pear install phpunit/PHPUnit_Selenium

Install PHP Interpreter:
1.       Download Php Windows Installer from the website: http://php.net/downloads.php
2.       Extract the Zip file and copy the extracted folder to xampp folder.


Setting Up the PHP Project:
1.        Launch the PHPStorm IDE that you installed.
2.        Click on Configure and Settings.
3.        Click on PHP Tree Node and Select the Interpreter from Browse dialogue. And then choose the extracted folder path for the interpreter.
Then you should see as below in the Settings window.
4.        Now from the include path add the location paths for referring the pear and php unit. Add the following paths by clicking ‘+’ symbol.
<!--Also include the following which I forgot to add before
C:\xampp\phpMyAdmin
C:\xampp\php-5.5.14-nts-Win32-VC11-x86-->
5.        Apply the above values to include path for references. Now click the PHPUnit tab and select the configuration file that contains the list of tests.
6.        Now go back to Home Page and create a new PHP Project if you do not have an existing php project or use Open Directory to open the existing project.
7.        Assume you have existing project. So use Open directory to open the Project. Now Configure PHP Include Paths to External Library.Click Ok in the configuration window, because you have already configured at the startup.
8.        Now Edit Configuration under Run Menu. Create A New Configuration “PHPUnit” and LoginTest as below
9.        Click Ok and Run the Test Class as shown. Before you run your test start the Selenium Standalone server using command prompt.
Go to the location where the Selenium server is located:
Example:
The selenium standalone server is in c:\seleniumDrivers
In command prompt
Cd\
Cd seleniumDrivers
Java –jar selenium-server-standalone-2.42.2.jar





Running Tests On Multiple Browsers:
To run the tests on multiple browsers change the browser name in setup method.
For
 Internet Explorer use: “internet explorer”
 Firefox use: “firefox”
 Chrome use: “chrome”
 Note: Before you make the changes make sure you have the IE and Chrome Driver downloaded in your local directory.
 Download the drivers from http://seleniumhq.org
 After downloading the drivers keep them in a fixed directory say: c:\seleniumDrivers
 And the set this path in Environment variable (variable Name: Path).

Example:
   $this->setBrowser('internet explorer');




No comments:

Post a Comment