Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'selenium-webdriver'
- browser = Selenium::WebDriver.for :firefox
- browser.get "http://localhost/page2"
- wait = Selenium::WebDriver::Wait.new(:timeout => 15)
- # Verify the existence of different elements and text
- puts "Test Passed: Link with the href 'http://www.elegantcode.com/' found by XPATH" if wait.until {
- browser.find_element(:xpath => "//a[@href='http://www.elegantcode.com/']").displayed?
- }
- puts "Test Passed: Link with the id '2' found by XPATH" if wait.until {
- browser.find_element(:xpath => "//a[@id='2']").displayed?
- }
- puts "Test Passed: Link with the name 'slashdotlink' found by NAME locator" if wait.until {
- browser.find_element(:name => "slashdotlink").displayed?
- }
- puts "Test Passed: Link with the id '4' found by ID locator" if wait.until {
- browser.find_element(:id => 4).displayed?
- }
- puts "Display the text for link 1: " + browser.find_element(:id, 1).text if wait.until {
- browser.find_element(:id, 1).displayed?
- }
- # Direct match
- puts "Test Passed: Link with id 2 and text containing the text 'Yahoo' found" if wait.until {
- browser.find_element(:id, 2).text == 'Yahoo'
- }
- # Regexp match
- puts "Test Passed: Link with id 2 and text containing the text '...hoo...' found" if wait.until {
- browser.find_element(:id, 2).text =~ /hoo/
- }
- # Click on a link
- link = wait.until {
- element = browser.find_element(:id, 3)
- element if element.displayed?
- }
- link.click
- # Check that the link with the given title is displayed
- puts "Test Passed: 'Submit Story' Link on slashdot found" if wait.until {
- browser.find_element( :xpath, "//*[@title='Submit a story to Slashdot']" ).displayed?
- }
- browser.quit
Advertisement
Add Comment
Please, Sign In to add comment