- PHP should be installed and set up path in your machine.
- PHPUnit Should be installed in machine.
- Java should be install and setup path in machine.
- Selenium2 jar(selenium-server-standalone-2.**.0.jar) file should in your machine.
If PHP and PHPunit are not installed in machine. We need to follow to installed them using below steps:
- Download PHP exe file from download and install in machine.
- Setup PHP path in environment variable if by default not path set. As if I installed in C:\\PHP drive the we need to setup path “C:\\PHP”
- Now we need to install PEAR for this we open command prompt and go to PHP installation directory and run command
php.exe
PEAR/go-pear.phar
4. After pear installed check version using
command “pear –V” . run below command
to update pear.
pear upgrade
pear
5. Before PHPUnit
installation we need to install below pear channels
a) pear channel-update
pear.php.net
b) pear channel-discover
pear.phpunit.de
c) pear channel-discover
components.ez.no
d) pear channel-discover
pear.symfony-project.com
e) pear config-set
auto_discover 1
6. For PHPUnit
installation run command.
pear install pear.phpunit.de/PHPUnit
7. After
successfully installation check PHPUnit version using command .
Phpunit -version
Screen should be look like below
Create
First Test Scripts:
As selenium does not provide direct any library for PHP Webdriver. For this we need to bind some third party library with our framework.
Download latest third party library from link “download”
Extract and put this library in automation project directory.
Create a “Google.php” file, copy and past below code and put it in automation project directory parallel to “phpwebdriver” library.
Download latest third party library from link “download”
Extract and put this library in automation project directory.
Create a “Google.php” file, copy and past below code and put it in automation project directory parallel to “phpwebdriver” library.
<?php
require_once
'phpwebdriver/WebDriver.php';
/**
*
* @property WebDriver $webdriver
*/
class Google extends PHPUnit_Framework_TestCase
{
//function
set up
public function setUp() {
$this->webdriver
= new WebDriver("localhost", "4444");
$this->webdriver->connect("firefox");
$this->webdriver->get("https://www.google.com");
}
//function
close browser
public function tearDown()
{
$this->webdriver->close();
}
public
function testGoogle()
{
//
input search field
$el
= $this->webdriver->findElementBy(LocatorStrategy::id,
"gbqfq");
$el->clear();
$el->sendKeys(array("testing"));
//click
on search button
$el
= $this->webdriver->findElementBy(LocatorStrategy::id,
"gbqfsa");
$el->click();
}
}
Run selenium Server: Open command prompt goto “selenium-server-standalone-2.**.0.jar” and run below command
Java
–jar selenium-server-standalone-2.**.0.jar
Below screen should be appear.
Run Test scripts:
Open command go to go to automation framework directory and run below command.
Phpunit
Google.php
After successfully execution screen should be look like as below.
No comments:
Post a Comment
Leave your comments, queries, suggestion I will try to provide solution