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