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
Selenium WebDriver Basics – Ruby
August 18, 2011
Installation:
1. Install Ruby
2. In Command Prompt >gem install selenium-webdriver
3. Copy and Paste the below code and save the file as sample_raveendran.rb
require ‘rubygems’
require “selenium-webdriver”
driver = Selenium::WebDriver.for :ie
driver.navigate.to “http://google.com”
if driver.title == “Google”
puts “Testcase 1 passed”
else
puts “Testcase 1 failed”
end
q = driver.find_element(:name, ‘q’)
q.send_keys “Raveendran Selenium”
q.submit
sleep 5
if driver.title == “RAVEENDRAN SELENIUM – Google Search”
puts “Testcase 2 passed”
else
puts “Testcase 2 failed”
end
q=driver.page_source
if q.include?(“raveendran.wordpress.com”)
puts “Testcase 3 passed”
else
puts “Testcase 3 failed”
end
driver.navigate.to “http://google.com”
a=driver.find_element(:link,’Advanced search’)
a.click
if driver.title == “Google Advanced Search”
puts “Testcase 4 passed”
else
puts “Testcase 4 failed”
end
a=driver.find_element(:name,’as_q’)
a.send_keys(“Raveendran Selenium”)
a=driver.find_element(:name,’num’)
options=a.find_elements(:tag_name=>”option”)
options.each do |g|
if g.text == “20 results”
g.click
break
end
end
a=driver.find_elements(:xpath=> ‘/html/body/table[2]/tbody/tr/td/table/tbody/tr/td/div
/form/div/table[4]/tbody/tr/td/input’)
a.each do |b|
b.click
end
sleep 4
if driver.title == “RAVEENDRAN SELENIUM – Google Search”
puts “Testcase 5 passed”
else
puts “Testcase 5 failed”
end
4. Run the ruby code
5. The Output looks like
Testcase 1 passed
Testcase 2 passed
Testcase 3 passed
Testcase 4 passed
Testcase 5 passed
Selenium IDE Installation
September 8, 2010
1. Downlaod Firefox from http://www.mozilla.com/en-US/firefox/upgrade.html
2. Install Firefox
3. Open Firefox and Navigate to “http://seleniumhq.org/download/“
4. Selenium IDE — Click “Download”
5. IF Pop up Blocker appears — Allow Pop up
6. Install Selenium-IDE Add on.
7. Restart Firefox
8. Navigate to Tools tab –> Selenium IDE
Watir vs Selenium
October 28, 2009
Watir — Opens browser as a normal way how the user opens it. Selenium — Create object for browser and works with that object in mentioned/particular port.
Watir — Changing registry details(Proxy-http,socks) is very easy. Selenium — Changing registry details(Proxy-http,socks) is not easy work.
Selenium — If your net connection is very slow then Selenium MAY returns error because of waitForPageToLoad exceeds(We can handle it by its not easy for beginneers) and also sleep commads most of the times fails. Watir — Watir waits until the page was fully loaded. We can use sleep commands
Watir is a Ruby library that wraps the COM interface to Internet Explorer. COM is a long-standing Windows-based technology for making libraries accessible to various languages. This allows access to the Document Object Model (DOM) so it doesn’t matter where on the page an object exists, what matters is how you identify it (id, name, title, etc).
Selenium uses a unique mechanism for driving browsers. Selenium’s automation engine is written in JavaScript and runs inside a browser. The engine, called a browser bot, is embedded in a page that accesses the application under test in a separate frame. Because of cross-site scripting, Selenium’s browser bot has to be served from the same site as the application under test – requiring installation on the server.
Selenium supports a command language, called Selenese. Tests can be embedded in an HTML table, which will be read in by the browser bot and then executed.
Both tools run tests directly in a browser, and both do it in a way that allows the browser to be minimized while the tests are running, which means you don’t have to dedicate a machine to running tests.(if you open more tahn 10 browsers tehn may be your machine hangs depends upon hardware)
Watir was designed to be easy to learn, it allows page elements to be identified by index, name, ID, value or adjacent text. Now Watir supports IE, Firefox,chrome,Safari with the help of Firewatir, SafariWatir,chrome Watir. Complaint: Watir is currently limited to IE browsers on Windows, Firewatir supports firefox browsers. So we need to write separate code(or object) for each and every browsers. But Selenium does in Single attempt.
Selenium was designed for breadth of coverage- multiple browsers and platforms. It was expected to be used by the same developers who built the application. Drawback: Selenium requires a server-side installation.
You can also express Selenium tests in a programming language, taking advantage of language-specific drivers that communicate in Selenese to the browser bot.
Learning Watir –> Without Ruby knowledge its not possible to write the watir script for one web application.
Learning Selenium –> Programming skill is not Major. But the QA should familiar with anyone of the language from Ruby/Java/perl/Puthon/c#/Groovy/PHP to implement the code for any web application.
How to run Selenium RC with Ruby codes
October 12, 2009
1. Download seleniumRC from –> http://seleniumhq.org
2. Unzip the file
3. commans prompt>java -version –> Version should grater than 1.6.0_5
4. command prompt go to –> C:\selenium-remote-control-1.0.1\selenium-server-1.0.1>java -jar selenium-server.jar
Now Selenium runs on 4444 port.
5. a)Download and install Ruby from http://ruby-lang.org/en/downloads/
b) cmd prompt>gem install selenium-client
or
i) Go to http://rubygems.org/gems/selenium-client
ii) Click Download and save the GEM file in C:\ruby\bin\
iii) Cmd Propmt –> C:\ruby\bin>gem install GEMNAME
6. Open new command prompt and goto ruby program path.In Ex, c:\test>ruby code.rb
7. code.rb
require “selenium/client”
require “test/unit”
class Untitled < Test::Unit::TestCase
def setup
@verification_errors = []
if $selenium
@selenium = $selenium
else
@selenium = Selenium::Client::Driver.new(“localhost”, 4444, “*chrome”, “http://jazzez.wordpress.com/”, 10000);
@selenium.start
end
@selenium.set_context(“test_untitled”)
end
def teardown
@selenium.stop unless $selenium
assert_equal [], @verification_errors
end
def test_untitled
@selenium.open “/”
@selenium.click “link=jazzez-news.exe released (using Mechanize – ruby gem)”
@selenium.wait_for_page_to_load “30000″
@selenium.click “link=exact:http://bit.ly/j_news_demo”
end
end
8. Selenium RC will give some outputs in new firefox window.
Any more details need then just ping me at jazzezravi@gmail.com
Selenium On Rails
December 12, 2008
Getting Started
Selenium on Rails is the name of the Selenium product crafted specifically for Rails
developers and is distributed as a Rails plugin. It has been designed to work seamlessly
with the Rails testing environment and fixtures.
It’s easy to install Selenium on Rails and get started.
1. Install the core Selenium files needed by the plugin:
SAMPLE>gem install selenium
2. Install the Selenium on Rails plugin for a given project:
SAMPLE>ruby script/plugin install http://svn.openqa.org/svn/selenium-on-rails/selenium-on-rails/
3. Generate the test directory and a test script:
SAMPLE>ruby script/generate selenium first.rsel
4. Start your Rails server in its test environment:
SAMPLE>ruby script/server -e test
5. Open the Selenium Test Runner in your browser:
http://localhost:3000/selenium
If your installation and setup succeeded, you see the Selenium Test Runner in your browser. You should also know that Selenium tests can be run from the command line and integrated into an automated suite of tests, but for demonstration purposes we will use the built-in web interface to execute our tests.
SAMPLE/test/selenium/first.rsel
setup
open ‘/’
assert_title ‘Ruby on Rails: Welcome aboard’
Run test in –> http://localhost:3000/selenium
For more reference –> http://seleniumhq.org/
Regards,
P.Raveendran
Selenium Grid
July 5, 2008
Selenium Grid:
Selenium Grid allows you to run Selenium tests in parallel, cutting down the time required for running acceptance tests to a fraction of the total time it currently takes. Run them all on a single machine (we’ve run up to 15 parallel processes on a laptop!) or on a server farm.
Technical Mumbo Jumbo:
Selenium Grid runs on top of Selenium Remote Control. Selenium is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser.
Step 1: Download selenium grid
Step 2: Setup your environment
In case you face any path issues then set path into your system following ways.
Way1:
Windows XP SP2 –> 1. Right click “My Computer”
2. Click “Advanced” tab
3. Click “Environment variables” button
4. In System variables –> click path –> Click edit
5. In edit system variable window –> go to end of line In “variable value” field –> [PASTE YOUR PATH]
Ex; C:\Program Files\Java\jdk1.6.0_06\bin;C:\grid\apache-ant-1.7.0-bin\apache-ant-1.7.0\bin;
6. Click ok for all 3 windows
Way2:
In command prompt,
c:\set path=%path%;”C:\grid\apache-ant-1.7.0-bin\apache-ant-1.7.0\bin;”
3. Run the demo