Thursday, March 17, 2011
Thursday, March 10, 2011
Automation Freamework - Integration of XAMPP, Selenium RC & PHPUnit
Steps to work with Selenium RC and Php Unit client Driver
Hi,
Even though i was successfully using selenium IDE for a quite a months, i just shifted to Selenium RC with PHP client driver.
Even i too also started facing the problems, since not a single doc can give the complete details about " About to start with selenium RC with php client driver"
so, after refering many persons responses, finally i succeeded. Here are the steps;
1. Download XAMPP
2. Install in any window machine
3. Confirm php exists in the c:/xampp/php
4. Install phpunit
pear install PHPUnit
It will install successfully
Try with simple exemple is it executable or not
<?php
echo "Hi";
?>
save the file 1.php in php folder.
e xecute like c:/xampp/php/phpunit 1
You will get echo Hi
5. Install selenium RC in c:/SRC location
6. Now open selenium IDE, record you testing application and export the file as PHP and save at location c:/xampp/php/test.php
7. Do the following changes:
C:\RC\selenium-php-client-driver-
0.9.2\PEAR\Testing\Selenium.php in line no 35 change to C:\RC\selenium-php-client-driver-
0.9.2\PEAR\Testing\Selenium\Exception.php')
C:\RC\selenium-php-client-driver-.9.2\PEAR\Testing\Selenium/Exception.php in line no 26 change to ocate this file c:\xampp\\PHP\PEAR\PEAR\Exception.php
8. Open the file,
c:/xampp/php/test.php do the following changes
require_once 'Testing/Selenium.php'; change to C:\RC\selenium-php-client-driver-0.9.2\PEAR\Testing\Selenium.php
require_once 'PHPUnit/Framework/TestCase.php'; change to c:\xampp\php\PHPUnit\Framework\TestCase.php
9. Open cmd prompt:
goto the location c:\rc\selenium rc\selenium driver\ type here as java -jar selenium-server.jar -interactive
check it is running
1 0. Open another cmd prompt, go to location c:\xampp\php and type phpunit test
Success: Now u can see that, browser is opened with your application and what ever you recorded will replayed and in the both cmd, you will get message as "OK"
Worried ...Not Working ???????
Yes. Due to some version problems.....it may not work..
Hope following steps will be useful to u with latest version:
- Xampp installtion: Install XAMPP 1.7.4 version , location C:\xampp
- Pear Installation:
PEAR package will be found in C:\xampp\php\pear.
But PHPUnit is not compatible with this PEAR package.
So do the following steps to install the latest version of PEAR package.
i. Google go-pear.phar, download in c:\xampp\php location
ii. Then run – c:\xampp\php > php go-pear.phar
iii. Follow the steps & complete the installations.
iv. After the install – a message = WINDOWS ENV means, double click on C:\xampp\php\PEAR_ENV.reg -> this registers into your local system regedit.
v. Try this command to know pear is installed & its available options
c:\xampp\php > pear
c:\xampp\php > pear -config
- Phpunit Installation:
Phpunit & PHPUnit2 will be installed as a part of pear package.
C:\xampp\php\PEAR\PHPUnit2\
and C:\xampp\php\PEAR\PHPUnit\
If not installed correctly means, follow the below instructions to install the phpunit.
C:\xampp\php> pear update-channels
C:\xampp\php> pear channel-discover pear.phpunit.de
C:\xampp\php> pear channel-discover components.ez.no
C:\xampp\php> pear channel-discover pear.symfony-project.com
C:\xampp\php> pear install phpunit/PHPUnit
Above package will be downloaded in c:\xampp\php\tmp, extract phpunit package. Remove the existing packages Phpunit & PHPUnit2 from c:\xampp\php\pear ( which are installed along with xampp). Then move this phpunit from \tmp to c:\xampp\php\pear folder.
4. PHPUnit_Selenium:
Along with pear package, PHPUnit_Selenium will be installed, if not install by following the below steps.
C:\xampp\php> pear install phpunit/PHPUnit_Selenium
NOTE: Default, all installed packages location will be in the c:\xampp\php\tmp, if u have not specifically changed that location.
Extract the files from folder – PHPUnit_Selenium, then upload content of extension folder into C:\xampp\php\PEAR\PHPUnit2\Extensions and C:\xampp\php\PEAR\PHPUnit\Extensions
Depending on which phpunit version u will work.
5. Selenium RC
Download selenium rc jar file & locate @ the PEAR folder.
6. Config changes: ( Optional – means first check without setting below, if not worked then do the following checks)
1.PHP: - For php, check the php.ini is set correctly.
To check, C:\xampp\php> php –ini
It will list the ini setting.
2. Phpunit: - For phpunit, check the below files
i. c:\xampp\php> phpunit.bat
check PHPBIN is set to C:\xampp\php\phpunit
ii. c:\xampp\php> phpunit.php , check the path set in the require, like ‘PHPUnit/TextUI/TestRunner.php’
NOTE: Depending on your usage, either change the phpunit version 2. ie, ‘PHPUnit2/TextUI/TestRunner.php’
7. How to execute php file.
a. Write a simple php file like <?php echo”hi”; ?>, save as test.php in the location c:\xampp\php\
b. Run the file with the command, c:\xampp\php >phpunit test
It will print the message – hi
c. To check php file of any phpunit based code means,
<?php
Require_once ‘PHPUnit/Framework/TestCase.php’
class DataTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider provider
*/
public function testAdd($a, $b, $c)
{
$this->assertEquals($c, $a + $b);
}
public function provider()
{
return array(
array(0, 0, 0),
array(0, 1, 1),
array(1, 0, 1),
array(1, 1, 3)
);
}
}
?>
- Save this file same as with class name ie DataTest.php & run the file as, c:\xampp\php\pear>phpunit DataTest.
- Running Selenium automated PHP scripts.
- In selenium IDE – automate the script & export it as php file
- store this php file in PEAR folder.
One example file is like this ---
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class Example extends PHPUnit_Extensions_SeleniumTestCase
{
protected function setUp()
{
$this->setBrowser("*chrome");
$this->setBrowserUrl("http://www.google.com/");
}
public function testMyTestCase()
{
$this->open("www.google.com");
$this->click("link=Alavuddin 100 W Bulb - Play");
$this->waitForPageToLoad("300");
$this->assertEquals("Alavuddin 100 W Bulb - Play in Bangalore | Alavuddin 100 W Bulb - Play event Bangalore Gayana Samaja, Bangalore | Apr, 2011 - google", $this->getTitle());
}
}
?>
3. Open cmd prompt, go to c:>xampp/php/pear/ and run the below command
java –jar selenium-server-standalone-2.ob3.jar
4. Open another cmd prompt, goto c:>xampp/php/ run the automated script
Phpunit test.php
Success :)
Subscribe to:
Posts (Atom)