Archive for July, 2012

Selenium Webdriver with Ruby Unit Example of Google Search

Copy the code and save as google_search.rb and run “ruby google_search.rb”

require “selenium-webdriver”
require “test/unit”
class GoogleSearch < Test::Unit::TestCase
  def setup
    @driver = Selenium::WebDriver.for :firefox
    @base_url = “;
    @driver.manage.timeouts.implicit_wait = 30
    @verification_errors = []
  def teardown
    assert_equal [], @verification_errors
  def test_google_search
    @driver.find_element(:name, “q”).clear
    @driver.find_element(:name, “q”).send_keys “Thiyagarajan Veluchamy”
    @driver.find_element(:name, “btnK”).click
  def element_present?(how, what)
    @driver.find_element(how, what)
  rescue Selenium::WebDriver::Error::NoSuchElementError
  def verify(&blk)
  rescue Test::Unit::AssertionFailedError => ex
    @verification_errors << ex
Categories: Uncategorized Tags:

Generate random email id in Ruby


We can return random email using following method

def email
      emailid = (0..8).map{(‘a’..’z’).to_a[rand(26)]}.join+””
      return emailid
while need random email id, just call the method “email()”.
Categories: Selenium Tags:

get tomorrow’s Date using javascript for selenium IDE

Selenium.prototype.doGenerateTomorrowDate = function( varName1, varName2 ) 
    var currentDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
    var day = currentDate.getDate()
    var month = currentDate.getMonth() + 1
    var year = currentDate.getFullYear()
    var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
    var month = monthNames[month];
    storedVars[ varName1 ] =  day;
    storedVars[ varName2 ] =  month;

Categories: Selenium Tags: ,

if statement in Selenium IDE

open  | URL of site
storeTextPresent  | any unique text of page a  | title
gotoIf  | storedVars.title  | true
getEval | alert(“page B”);
gotolabel | finish
label  | true
getEval | alert(“Page A”);
label | finish

This will check whether title is present or not, and if present control will redirect to label true, else will execute next statement after gotoif.

Categories: Selenium Tags: ,

Get id of div from its class name using JavaScript for Selenium IDE

Get id of div from its class name using JavaScript for Selenium IDE
Categories: Selenium Tags:

How to solve the link has target ‘_blank’, which is not supported in Selenium

For the example,

<a target=”_blank” id=”verify_email” href=”″>Verify your email</a>

So We can use following,

<td>echo</td> ‘ this is only optional to see the link


Categories: Selenium Tags: ,

Generates a random word using JavaScript in Selenium IDE

Selenium.prototype.doRandomWord = function( length, varName ) {
    var consonants = ‘bcdfghjklmnpqrstvwxyz’,
        vowels = ‘aeiou’,
        rand = function(limit) {
            return Math.floor(Math.random()*limit);
        i, word=”, length = parseInt(length,10),
        consonants = consonants.split(”),
        vowels = vowels.split(”);
    for (i=0;i<length/2;i++) {
        var randConsonant = consonants[rand(consonants.length)],
            randVowel = vowels[rand(vowels.length)];
        word += (i===0) ? randConsonant.toUpperCase() : randConsonant;
        word += i*2<length-1 ? randVowel : ”;
storedVars[ varName ] =  word;
Categories: Selenium Tags: ,