Monday, December 13, 2010

10 Fun Things I Can Do with a new Lenovo Laptop

  1. Visit my favorite online networking site (e.g. Facebook, Twitter)
  2. Play the latest online/offline games
  3. Do school work (e.g. assignments and projects)
  4. Create my blog
  5. Chat with friends
  6. Photo editing
  7. Watch my favorite movies
  8. Do productive work at the office
  9. Store and play my favorite music
  10. Take it anywhere I like

This is official entry to the Lenovo-YugaTech Laptop Giveaway

Sunday, December 12, 2010

Installing the guest additions (Ubuntu Guest)

This is how to install guest additions on Oracle VM Virtualbox. The below example will install guest addition to Ubuntu guest OS.
  1. From the VirtualBox menu select Devices > Install Guest Additions a CDROM will appear on your desktop and give you a warning just click Cancel it’s trying to auto-run as if it was in Windows. 
  2. Navigate to Applications > Accessories > Terminal.
  3. Enter the following command to switch to the CDROM directory
  4. cd /media/cdrom
  5. Invoke the installer by running the following command
  6.  
    • if you have a 32bit platform
    sudo ./VBoxLinuxAdditions-x86.run
            or
    • if you have a 64bit platform.
    sudo ./VBoxLinuxAdditions-amd64.run
  7. Once the Guest Additions are installed, reboot and you will be presented with a window telling you the benefits of them. Click Ok to dismiss the window.

screen_capture Sample in Watir

This simple watir script will take a screenshot and save the to a random number filename.

require 'watir'
require 'watir/screen_capture'
include Watir::ScreenCapture
require 'win32ole'

def take_screenshot
  randfname = Array.new(6) { (rand(122-97) + 97).chr }.join
  begin
    directory_name = File.dirname(__FILE__).gsub('/','\\') +
    "\\screenshots\\#{$randdir}"
    if FileTest::directory?(directory_name)
      filename = "#{directory_name}\\#{randfname}.png"
      screen_capture(filename,false, false)
    else
      Dir::mkdir(directory_name)
      filename = "#{directory_name}\\#{randfname}.png"
      screen_capture(filename,false, false)
    end
  end
end

Sample Driver Script for QTP Keyword Driven Framework

The below mentioned framework script is prepared to add three sheets in the runtime data table and retrieve the data from an external excel file. Based on the retrieved data and keywords remaining functions will be executed. Finally the updated runtime results data is exported to external excel file.

Adding sheets to runtime data table

' Adding sheet for Module
DataTable.AddSheet ("Module")
' Adding  sheet for Testcase
DataTable.AddSheet ("Testcase")
' Adding sheet for Teststep
DataTable.AddSheet ("Teststep")

'-- Importing sheets from an external excel file

' Importing data of Module sheet  from external excel file
DataTable.ImportSheet "Path of the excel file",1,"Module"
' Importing data of Testcase sheet  from external excel file
DataTable.ImportSheet "Path of the excel file",2,"Testcase"
' Importing data of Teststep sheet  from external excel file
DataTable.ImportSheet "Path of the excel file",3,"Teststep"
' Getting the total number of rows in the Module sheet
MrowCount=Datatable.GetSheet("Module").GetRowCount
' For loop is started here for Module data
For i=1 to Mrowcount
    ' Setting the first row in the Module sheet
    DataTable.SetCurrentRow(i)
    ' Getting and Assigning the value of current row  to Mflag
    Mflag=DataTable.Value(3,"Module")
    If Mflag ="Y"  Then
        ' If Mflag = Y, assigning the current row value to ModuleId
        ModuleId= DataTable.Value (1,"Module")
        ' Getting the total number of rows in the Testcase sheet
        TcrowCount=DataTable.GetSheet ("Testcase").GetRowCount
        ' For loop is started here for Testcase data
        For j=1 to TcrowCount
            ' Setting the first row in the Testcase sheet
            Datatable.SetCurrentRow (j)
            ' Getting and Assigning the value of current row  to ModuleId1
            ModuleId1=DataTable.Value(4,"Testcase")
            ' Getting and Assigning the value of current row  to Tcflag
            Tcflag=DataTable.Value(3,"Testcase")
            If ModuleId=ModuleId1 and Tcflag="Y" Then
                ' If  ModuleId = ModuleId1 and Tcflag = Y, assigning the
                  current row value to TcId
                TcId=DataTable.Value(1,"Testcase")
                ' Getting the total number of rows in the Teststep sheet
                TsrowCount=DataTable.GetSheet("Teststep").GetRowCount
                ' For loop is started here for Teststep data
                For k= 1 to TsrowCount
                ' Setting the first row in the Teststep sheet
                Datatable.SetCurrentRow(k)
                ' Getting and Assigning the value of current row  to Tcid1
                Tcid1=DataTable.Value(5,"Teststep")
                    If TcId= TcId1 Then
                        ' If TcId = TcId1, assigning the current row value to
                          keyword
                        keyword= DataTable.Value(3,"Teststep")
                        ' Select Case statement is started here
                        Select Case keyword
                        Case "lN"
                        ' If keyword = IN, execute Login function and assign the
                          value to res
                        res=Login()
                        ' Write the value of res to Teststep in the runtime data
                          table
                        DataTable.Value(6,"Teststep")=res
                        Case "CA"
                            ' If keyword = CA, execute Close_Appl function
                            Close_Appl()
                        Case "OP"
                            ' If keyword = OP, execute OpenOrd function and 
                              assign the value to res
                            res=OpenOrd()
                            ' Write the value of res to Teststep in the runtime
                              data table
                            DataTable.Value(6,"Teststep")=res
                        ' End of Select Case statement
                        End Select
                    ' End of If statement for Test Step sheet
                    End If 
                ' End of For loop for Teststep data
                Next
            ' End of If statement for Testcase sheet
            End If 
        ' End of For loop for Testcase data
        Next
    ' End of If statement for Module sheet
    End If
' End of For loop for Module data
Next

'--- Exporting results
 
' Exporting the runtime data sheet of Teststep to external excel file
Datatable.ExportSheet "Path of the file where you want","Teststep"

' Need to define functions like Login, Close_app and Openord

'---  Login function

' function definition for Login
Function Login()
----
End Function

'--- Close application function

' function definition for Close_Appl
Function Close_Appl()
-----
End Function

'--- Openord function

' function definition for OpenOrd
Function OpenOrd()
----
End Function

Tuesday, December 7, 2010

Diaspora targeting Facebook

Recently, I sent a request to access this Facebook-like social networking application. A diaspora (from Greek διασπορά, "scattering, dispersion"[1]) which clearly define its type. This free software personal webserver is a distributed social networking service that aims to decentralize social networking services like Facebook. The project is currently under development by Dan Grippi, Maxwell Salzberg, Raphael Sofaer, and Ilya Zhitomirskiy student from New York University's Courant Institute of Mathematical Sciences. To send a request to view this exciting application click here

What is Diaspora?

Diaspora is the social network that puts you in control of your information. You decide what you’d like to share, and with whom. You retain full ownership of all your information, including friend lists, messages, photos, and profile details.

Share what you want, with who you want.

[via joindiaspora]

Monday, November 1, 2010

Installing RPM Files Using Alien

  1. Install Alien first
  2. $sudo apt-get update $sudo apt-get install alien
  3. This will convert the .rpm to a .deb.
  4. $sudo alien -k name-of-rpm-file.rpm
  5. Execute .deb package to install
  6. $sudo dpkg -i name-of-deb-file.deb

Virtualbox XP host to Ubuntu 8.04 guest folder sharing

How to share a forder on XP host to Ubuntu 8.04 guest
  1. On XP guest menu, go to Devices -> Shared Folders
  2. Add a new share (ex. C:\SharedFolder)
  3. On Ubuntu 8.04 guest create a new directory (ex. /home/MountFolder)
  4. mkdir /home/MountFolder
  5. Then, run
  6. mount -t vboxsf SharedFolder /home/MountFolder

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}";

?> 

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!

javascript popup clicker

Ruby watir script  for clicking javascript popup.
require 'fileutils'
require 'win32ole'

def check_for_popups(title="Message from webpage", button="OK")
  popup=Thread.new {
    autoit=WIN32OLE.new('AutoItX3.Control')
    ret=autoit.WinWait(title,"",60)
    if (ret==1)
      autoit.WinActivate(title)
      button.downcase!
      if button.eql?("ok") || button.eql?("yes") || button.eql?("continue")
        autoit.Send("{Enter}")
      else
        autoit.Send("{tab}")
        autoit.Send("{Enter}")
      end
    elsif (ret==0)
        puts "No popup, please check your code."
    end
    }
  at_exit { Thread.kill(popup) 
  }
end 
and below for Internet Explorer authetication popup
def login(vusername,vpassword,vtest_site)
    @user = vusername
    @pass = vpassword
    @url = vtest_site
    a = Thread.new {
      FileUtils.rm_rf vcookiedir
      $ie = Watir::Browser.new
      $ie.goto(@url)
      sleep 15  
    }
    sleep 15   
    autoit=WIN32OLE.new('AutoItX3.Control')
    autoit.Send(@user)
    autoit.Send('{TAB}')
    autoit.Send(@pass)    
    autoit.Send('{ENTER}')
    a.join
end 

Virtualbox XP host to XP guest folder sharing

How to share a forder on XP host to XP guest
  1. On XP guest menu, go to Devices -> Shared Folders
  2. Add a new share (ex. C:\SharedFolder)
  3. On XP guest open command prompt then run:
net use z: \\vboxsvr\SharedFolder -p

Deleting cookies in watir

This is how to delete browser cookies in watir.
require ‘fileutils’

$cookieDir = “C:\\Documents and Settings\\#{ENV['USERNAME']}\\Cookies”
FileUtils.rm_rf $cookieDir

Rufus scheduler sample

After creating ruby script, Im using rufus scheduler. I found this simple snippet and so far its helpful. The file filerun.rb is executing every 20 seconds.

Installation

sudo gem install rufus-scheduler
Sample usage:
require 'filetorun'
require 'rufus/scheduler'

class Scheduler
 def start
   scheduler = Rufus::Scheduler.start_new
   scheduler.every '20s', :blocking =>; true do
      puts "running test"
     `ruby filetorun.rb`
   end
   scheduler.join
 end
end

Scheduler.new.start

Sending email with attachment in Ruby using Ruport gem

An example of sending email using Ruport. Sends email to 2 recipients. This example also includes attachment. I'm using this to send ruby script results and images

To install ruport via rubygems:
sudo gem install ruport
Check to see if it installed properly:
ruby -rubygems -e "require 'ruport'; puts Ruport::VERSION"

To use:
require 'ruport'
require 'ruport/util'

r = Ruport::Report.new
r.add_mailer :default,
             :host => "mail.domain.com",
             :address => "email@domain.com"

recipients = ["to1@domain.com","to2@domain.com"]
recipients.each do |recipient|
  r.send_to(recipient) do |mail|
    mail.subject = "Test Email"
    mail.attach "test_file.txt"
    mail.attach "stylesheet.xsl"
    mail.text = "This is an email with attachments"
  end
end