Tuesday, September 28, 2010

How to manual install PEAR PHP extension

1. Load http://pear.php.net/go-pear in your browser.
2. Save the output to a local file go-pear.php on your php installation folder.
2. Then run:
php go-pear.php

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]

Wednesday, September 8, 2010

CI_Reporter customized XSL

<?xml version="1.0" encoding="UTF-8"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns="http://www.w3.org/1999/xhtml">
<xsl:if test="system-property('xsl:vendor')='Transformiix'"></xsl:if>
    <body style="font-family: Verdana, Arial, Helvetica, 
    sans-serif;font-size:11px;background-color:#EEEEEE">
        <xsl:for-each select="testsuite">
            <div style="background-color:blue;color:white;padding:4px">
                <span style="font-weight:bold">
                    <xsl:value-of select="@name"/>
                    <xsl/> Overall Results
                </span>
            </div>
            <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
                <span>
                    <xsl/> tests:
                </span>
                <xsl:value-of select="@tests"/>
            </div>
            <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
                <span>
                    <xsl/> assertions:
                </span>
                <xsl:value-of select="@assertions"/>
            </div>
            <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
                <span>
                    <xsl/> failures:
                </span>
                <xsl:value-of select="@failures"/>
            </div>
            <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
                <span>
                    <xsl/> errors:
                </span>
                <xsl:value-of select="@errors"/>
            </div>
            <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
                <span>
                    <xsl/> time (seconds):
                </span>
                <xsl:value-of select="@time"/>
            </div>
        </xsl:for-each>
        <xsl:for-each select="testsuite/testcase">
            <div style="color:white;padding:4px">
                <xsl:attribute name="style">
                    <xsl:choose>
                        <xsl:when test="failure">background-color:red;
                        color:white;padding:4px;font-weight:bold</xsl:when>
                        <xsl:when test="@time=0.0">background-color:gray;
                        color:white;padding:4px;font-weight:bold</xsl:when>
                        <xsl:otherwise>background-color:green;
                        color:white;padding:4px;font-weight:bold
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
                <span><xsl:value-of select="@name"/></span>
            </div>
            <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
                <span>
                    <xsl/> assertions:
                </span>
                <xsl:value-of select="@assertions"/>
            </div>
            <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
                <span>
                    <xsl/> time (seconds):
                </span>
                <xsl:value-of select="@time"/>
            </div>
            <xsl:for-each select="failure">
                <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
                    <span>
                        <xsl:value-of select="time"/> failure type:
                    </span>
                    <xsl:value-of select="@type"/>
                </div>
                <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
                    <span>
                        <xsl/> failure message:
                    </span>
                    <xsl:value-of select="@message"/>
                </div>
            </xsl:for-each>
        </xsl:for-each>
        <div style="background-color:black;color:white;padding:4px">
            <span style="font-weight:bold">
                <xsl/> Console Output
            </span>
        </div>
        <xsl:value-of
        select="."
        disable-output-escaping="yes"/>
    </body>
</html>

CI_Reporter - How to add date on result file filename

First, locate report_manager.rb. This is usually located on the installation folder ex. C:\ruby\lib\ruby\gems\1.8\gems\ci_reporter-1.6.0\lib\ci\reporter\report_manager.rb. Then edit this portion of the code.

def write_report(suite)
  File.open("#{@basename}-#{suite.name.gsub(/[^a-zA-Z0-9]+/, '-')}--
  #{Time.now.strftime("%m-%d-%Y--%H-%m")}.xml", "w") do |f|
    f << suite.to_xml
  end
 end


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","");
        }
    }
}
?>

Connecting to MySQL Database in PHP

<?php

    $dbname="{database name}";
    $cn=mysql_connect('{host}','{username}','{password}') or 
    die("I Couldn't connect");
    $db=mysql_select_db($dbname,$cn) or die("I Couldn't select your database");
    $app_table1="{table name}";

?>