Showing posts with label rc. Show all posts
Showing posts with label rc. Show all posts

Wednesday, September 15, 2010

How to Setup Selenium in PHP Environment

If you have gone through configuring Selenium in Windows system by Setting up Selenium RC server in Windows and Setting up PHP in Windows using Abyss server, next thing you need to setup is the Selenium PHP client. Let me show you the steps I've gone through to accomplish this:

1. Open up the console with all administrative privileges especially in Vista
2. Go to the directory where PHP is installed
3. Execute command:
php PEAR/go-pear.phar
4. Follow the instructions, and ignore the additional offerings to configure it
5. Install PHPUnit by:
pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit
6. Download Selenium PHP PEAR extension and place into your PHP directory
7. Run:
pear install Testing_Selenium-0.4.3.tar
8. Download the sample GoogleTest and assuming you put it in C:\Tests folder
9. Now run:
phpunit --verbose GoogleTest C:/Tests/GoogleTest.php
10. Remember the class name GoogleTest must be the same as the class name defined in the GoogleTest.php


Source: [Geek With Blogs]

Monday, September 6, 2010

Checking multiple links on page using Selenium RC

A simple script for checking multiple links on page using selenium RC and taking a screenshot of the page. This script will get all the links then throw it to another php file in an array form.

<?php

set_include_path(get_include_path() . PATH_SEPARATOR . './PEAR/');
require_once 'Testing/Selenium.php';
require_once 'PHPUnit/Framework/TestCase.php';

class check_links extends PHPUnit_Framework_TestCase {
    private $sel;

    function setUp() {
        $this->sel = new Testing_Selenium("*firefox", "www.my-test-url.com/");
        $this->sel->start();
        $this->sel->setTimeOut(60000);
    }

    function tearDown() {
        $this->sel->stop();
    }

    function testLinks() {
        //delete screenshot files
        foreach (glob("C:\\screenshot_repo\\*.png") as $filename) {
            unlink($filename);
        }
        $this->sel->open("/");
        $this->linkval = $this->sel->getAllLinks('id=links-div');
        //write all the links found on a separate php file in an array form
        $txtfile = fopen('dump.php', 'w+');
        fwrite($txtfile, "<?php\n\$links_content = array(\n");
        for($i = 0, $size = sizeof($this->linkval); $i < $size; $i++) {
                $txt = $this->sel->getText("id=".$this->linkval[$i]);
                fwrite($txtfile, "array(href=>".'"'.$this->sel->getAttribute(
                'id='.$this->linkval[$i].'@href').'"'.','."text=>".'"'.$txt.'")
                ,'."\t\n");
        }
        fwrite($txtfile, ");\n?>");
        //read the file and get file length
        $txtfile = fopen('dump.php', 'r');
        $count = 0;
        while(fgets($txtfile)) {
            $count++;
        }
        fclose($txtfile);
        include 'dump.php';
        for ($links=0;$links<=$count-5;$links++) {
            $this->sel->open($links_content[$links]['href']);
            $this->sel->waitForPageToLoad(30000);
            //take a screenshot of the page
            $this->sel->windowFocus();
            $this->sel->windowMaximize();
            $SSPath = 'C:\\screenshot_repo\\';
            $this->sel->captureEntirePageScreenshot($SSPath.str_replace(
            " ","_",(strtolower($links_content[$links]['text'])))
            .".png","");
        }
    }
}
?>

Tuesday, May 11, 2010

How to setup/run selenium RC

    Installation
  1. Visit http://seleniumhq.org/download/ then download .zip file
  2. Extract .zip file on on your local machine (in my case “C:\Selenium\selenium-remote-control-x.x.x”)
  3. Running Selenium Server
  4. Before running the selenium server you need to check the java installed in your machine, to check open command prompt then run:
  5. java -version
    NOTE: If you get a version number (which needs to be 1.5 or later), you’re ready to start using Selenium-RC.
  6. Go to the directory where Selenium-RC’s server “.jar” is located (in my case “C:\Selenium\selenium-remote-control-x.x.x\selenium-server-x.x.x”) run:
  7. java -jar selenium-server.jar
    then youre done!