Automating ‘Auto Complete’ text field using Watir-WebDriver

Requirement:

1. Navigate to Google.com

2. Type “Ravee” in text Field
 3. Select “Raveendran” from Auto Complete option from Suggested option.
Steps to Solve the issues:
1. Navigate to Google.com
2. Type “Rav” in text Field
3. Using IE Developer Tool Bar –> Click The suggested Option (So You will get the source code for suggestion lists)
4. Find the parent id –> Ex. It should TABLE mostly.
So we have Table id/name/class
5. Collect All the Rows under this table
6. Check the text for each and every row
7. If Any one of the row matches  ”Raveendran”
8. Then Simply Click It
Code:

require 'rubygems'
require 'watir-webdriver'

browser=Watir::Browser.new :ie
browser.goto("google.com")

browser.text_field(:name,"q").set("Ravee")
sleep 3
auto_content=browser.table(:class,'gssb_m').trs

auto_content.each do |g|
  if g.text.downcase == "raveendran"
    g.click
    sleep 3
    break
  end
end

 

Demo –> http://bit.ly/j_autocomplete_watir

Ruby – Some Useful Links

Ruby:
Homepage : http://www.ruby-lang.org

Downlaod : http://www.ruby-lang.org/en/downloads/

Documentation: http://www.ruby-lang.org/en/documentation/

Libraries: http://www.ruby-lang.org/en/libraries/

Community: http://www.ruby-lang.org/en/community/

News: http://www.ruby-lang.org/en/news/

Security: http://www.ruby-lang.org/en/security/

About Ruby: http://www.ruby-lang.org/en/about/

 

Documentation:

Getting Started –>

http://pine.fm/LearnToProgram/

http://www.ruby-lang.org/en/documentation/quickstart/

http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/

http://rubylearning.com/

http://www.techotopia.com/index.php/Ruby_Essentials

http://www.meshplex.org/wiki/Ruby/Ruby_on_Rails_programming_tutorials
Manual –>
http://www.ruby-doc.org/docs/ProgrammingRuby/

http://www.rubyist.net/~slagell/ruby/

http://en.wikibooks.org/wiki/Ruby_programming_language

 

Reference Documentation –>

http://www.ruby-doc.org/core/

http://www.ruby-doc.org/stdlib/

 
Further details –>

http://ruby-doc.org/

 

books –>

http://www.ruby-doc.org/bookstore

http://antoniocangiano.com/ruby-and-rails-recommended-books/

http://www.rubycentral.com/book/

http://www.freeprogrammingresources.com/ruby-tutorial.html

http://www.programmingbooks.org/Ruby

http://pspxworld.com/book/programming/ruby.php

http://www.sitepoint.com/books/rails1/

http://www.buildingwebapps.com/learning_rails

http://lifehacker.com/software/ruby/free-e+book-teaches-ruby-programming-225976.php

http://kickjava.com/books/ruby.htm

http://www.onlinecomputerbooks.com/free-ruby-books.php

http://www.easywebtech.com/ebooks/Free_Ruby_ebooks_Download-0.html

http://www.scribd.com/doc/1622/Free-Ruby-eBook

http://www.infoq.com/minibooks/ruby

http://www.sapphiresteel.com/The-Little-Book-Of-Ruby

http://www.rorsecurity.info/the-book/

http://www.freebooksclub.net/ruby-ebooks/

http://www.freebookcentre.net/programming-books-download/Whys-(Poignant)-Guide-to-Ruby.html

http://knowfree.net/category/it-ebooks/ruby

http://www.webstuffscan.com/2007/07/13/download-free-ruby-ebooks-pdf/

http://www.webappers.com/2007/10/07/sitepoint-giving-away-ruby-on-rails-complete-free-book/

http://www.freetechbooks.com/ruby-f49.html

http://nealenssle.com/blog/2007/01/05/free-ruby-e-book/

http://www.sapphiresteel.com/The-Book-Of-Ruby-free-in-depth

http://www.asiaing.com/mr.-neighborlys-humble-little-ruby-book-free-ebook.html

http://www.humblelittlerubybook.com/book/

http://2020ok.com/books/37/guide-to-ruby-34437.htm

http://www.bookrags.com/shortguide-ruby-in-the-smoke/

 

Course –>

http://h2kinfosys.com

Ruby — Encryption and Decryption using OpenSSL

Code:

require 'rubygems'
require 'openssl'

$key = "A75435F0B240012A9489000C2952E41F"

class String

def encrypt(key=$key)
e = OpenSSL::Cipher::Cipher.new 'DES-EDE3-CBC'
e.encrypt key
s = e.update self
s << e.final
s = s.unpack('H*')[0].upcase
s
end

def decrypt(key=$key)
e = OpenSSL::Cipher::Cipher.new 'DES-EDE3-CBC'
e.decrypt key
s = self.to_a.pack("H*").unpack("C*").pack("c*")
s = e.update s
s << e.final
end
end
puts "raveendran".encrypt("password")
puts "509067DC2076497134DBF9A7DE5992B2".decrypt("password")

Output

509067DC2076497134DBF9A7DE5992B2

raveendran

Note:

You can chnage the $key vlaue.

You can encrypt the string with password. The password should match when trying to decrypt the encrypted string.

To access the elements within IFrame using Selenium WebDriver (Ruby)

Situation :

User want to click the field which is placed within 2 IFrames using selenium webdriver.

Field — Friendship

Source code for “Friendship” — <nobr>Friendship</nobr>

Frame ID’s –” nav”  and “JobplaceFrame”

Code:

require ‘rubygems’

require ‘selenium-webdriver’

$browser = Selenium::WebDriver.for :ie

$browser.get "http://URL.com”

current_title=$browser.title
if current_title == “TITLE OF THE WEBPAGE”
puts “step 1 passed”
else
puts “step1 failed”
exit
end

$browser.switch_to.frame(‘nav’) #parent Frame
$browser.switch_to.frame(“JobplaceFrame”) #Child frame

options=$browser.find_elements(:tag_name=>”nobr”)

options.each do |nobr_field|
if nobr_field.text == 'Friendship'
nobr_field.click
break
end
end

Watir Day 2011 Speakers Announced!

The speakers list for Watir Day 2011 in San Francisco on April 3rd 2011
  • Alister Scott: ThoughtWorks: The Elements of Cucumber Style
  • Andreas Tolfsen: Opera Software: Watir 3 and the future
  • Bret Pettichord: Convio: Opening & Host
  • Hugh McGowan: Convio: Testing with Vision
  • Marek Jastrzebski: Convio: Domain Specific Watir Page Objects
  • Simon Stewart: Google: WebDriver
  • Tim Koopmans: Altentee: WatirGrid
  • Željko Filipin: WA Research: Adventures in promoting Watir

 

Heroku – Rubygem

Introduction to Heroku

Heroku is the instant ruby platform. Deploy any ruby app instantly with a simple and familiar git push. Take advantage of advanced features like HTTP caching, memcached, rack middleware, and instant scaling built into every app. Never think about hosting or servers again.
Multi-Tenant

Heroku is a multi-tenant platform and hosting environment. Your app doesn’t need its own servers, slices, or clusters, and you’ll benefit from continuous platform improvements.
Fully Managed

Each element in this diagram represents a large pool of servers invisibly managed by Heroku. Because we control all the infrastructure and software layers, we can present a clean interface for deploying your code.
Curation

We actively curate each layer, ensuring you have the latest in software and best practices, and that it’s all stable and integrated smoothly.
Everything You Need

Together, these elements provide everything you need to run a modern, high-performance, scalable web app. Click around to understand the path of a request through the system.
More information

See our Architecture description for more details on how Heroku works

 

For more details –> http://heroku.com/

Watir — Verifying the Current style Properties

require ‘rubygems’

require ‘watir’

ie=Watir::IE.new

ie.goto(“google.com”)

ie.image(:id,’logo’).document.currentstyle.height

#=> “190px”

ie.image(:id,’logo’).document.currentstyle.width

#=> “315px”

ie.image(:id,’logo’).document.currentstyle.fontfamily

#=> “arial,sans-serif”

ie.image(:id,’logo’).document.currentstyle.textalign

#=> “center”

ie.image(:id,’logo’).document.currentstyle.borderwidth

#=> “0px”

For more details,

HYDRA – Ruby gem

Hydra is a distributed testing framework. It allows you to distribute your tests locally across multiple cores and processors, as well as run your tests remotely over SSH.

Hydra’s goals are to make distributed testing easy. So as long as you can ssh into a computer and run the tests, you can automate the distribution with Hydra.

nstalling Hydra

Installing Hydra is easy, just install the gem:

gem install hydra
OR Download the gem file from http://gemcutter.org and install it

Setting up Hydra

To set up Hydra, you need to edit your project’s Rakefile and add this code:
# require the hydra codebase
require 'hydra'
# require the hydra rake task helpers
require 'hydra/tasks'

Adding Cucumber Files

# set up a new hydra testing task named 'hydra:cucumber' run with "rake hydra:cucumber"
Hydra::TestTask.new('hydra:cucumber') do |t|
  # add all files in the features directory that end with ".feature"
  t.add_files 'features/**/*.feature'
end

Adding Test::Unit Files

# set up a new hydra testing task named 'hydra:units' run with "rake hydra:units"
Hydra::TestTask.new('hydra:units') do |t|
  # add all files in the test/unit directory recursively that
  # end with "_test.rb"
  t.add_files 'test/unit/**/*_test.rb'
  # and test/functional
  t.add_files 'test/functional/**/*_test.rb'
  # and test/integration
  t.add_files 'test/integration/**/*_test.rb'
end

Adding RSpec Files

# set up a new hydra testing task named 'hydra:spec' run with "rake hydra:spec"
Hydra::TestTask.new('hydra:spec') do |t|
  # you may or may not need this, depending on how you require
  # spec_helper in your test files:
  require 'spec/spec_helper'
  # add all files in the spec directory that end with "_spec.rb"
  t.add_files 'spec/**/*_spec.rb'
end