Ruby + Selenium-webdriver

Hi,

I am a total beginner of Ruby and Selenium and i want to use both =)

1. Selenium-webdriver gem - How do I find out which methods that this
gem contains or other gems?
2. Catch a bug – If a link or element is missing on the page how do I
catch this defect and output it and then continue with my test script?
Some design tips?

Best Regards,
Mattias

···

--
Posted via http://www.ruby-forum.com/.

I recommend using Watir-Webdriver, as this is Selenium with a great
interface.

Check out tips and examples here:
http://watirwebdriver.com/

Plenty of methods are shown there and in the documentation. As for
catching missing elements, you have methods such as "present?" returning
a boolean value.

···

--
Posted via http://www.ruby-forum.com/.

Try this:

require 'watir-webdriver'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
l = b.link :text => 'Google Docs'
b.goto l.href

···

--
Posted via http://www.ruby-forum.com/.

Joel Pearson wrote in post #1086551:

I recommend using Watir-Webdriver, as this is Selenium with a great
interface.

Check out tips and examples here:
http://watirwebdriver.com/

Plenty of methods are shown there and in the documentation. As for
catching missing elements, you have methods such as "present?" returning
a boolean value.

Thank you Joel I will check this out.

Best Regards
Mattias

···

--
Posted via http://www.ruby-forum.com/\.

Mattias A. wrote in post #1086723:

Joel Pearson wrote in post #1086551:

I recommend using Watir-Webdriver, as this is Selenium with a great
interface.

Check out tips and examples here:
http://watirwebdriver.com/

Plenty of methods are shown there and in the documentation. As for
catching missing elements, you have methods such as "present?" returning
a boolean value.

Thank you Joel I will check this out.

Best Regards
Mattias

Hi again,

What actually happens below? See my comments after #
Would really appreciate if someone wanted to take the time to explain.

require 'rubygems' #lib?
require 'selenium-webdriver' #lib?

driver = Selenium::WebDriver.for :firefox #instantiate driver with
Selenium and Webdriver methods?
driver.get "http://google.com"

element = driver.find_element :name => "q" # What happens here? :name =>
"q"?
element.send_keys "Cheese!"
element.submit

puts "Page title is #{driver.title}"

wait = Selenium::WebDriver::Wait.new(:timeout => 2)#Wait is a new class?
wait.until { driver.title.downcase.start_with? "cheese!" }#Verify that
cheese has been printed?

puts "Page title is #{driver.title}"
driver.quit

Best Regards
Mattias

···

--
Posted via http://www.ruby-forum.com/\.

What actually happens below? See my comments after #
Would really appreciate if someone wanted to take the time to explain.

require 'rubygems' #lib?

You don't need this in Ruby 1.9

require 'selenium-webdriver' #lib?

Have a look at this:
http://watirmelon.com/2011/05/05/selenium-webdriver-vs-watir-webdriver-in-ruby/

driver = Selenium::WebDriver.for :firefox #instantiate driver with
Selenium and Webdriver methods?

This just creates an instance of firefox with a temp profile which can
be controlled via Selenium-webdriver

driver.get "http://google.com"

element = driver.find_element :name => "q" # What happens here? :name =>
"q"?

The element on the page with the name "q" happens to be the search text
field. I recommend using Firebug to find out what each element can be
identified by.

element.send_keys "Cheese!"
element.submit

puts "Page title is #{driver.title}"

wait = Selenium::WebDriver::Wait.new(:timeout => 2)#Wait is a new class?

Watir-webdriver's latest version has waiting built-in, it looks like
Selenium has a seperate wait module.

wait.until { driver.title.downcase.start_with? "cheese!" }#Verify that
cheese has been printed?

You're passing a block to the wait module, until method which will stop
waiting once it evaluates to "true". This waits until the page has
loaded to a point that it has changed the title of the browser window.

puts "Page title is #{driver.title}"
driver.quit

I'm not sure about Selenium, but with watir-webdriver using "close"
rather than "quit" cleans up the temp files as well.

Best Regards
Mattias

This is what the same sequence looks like with watir-webdriver:

require 'watir-webdriver'
driver = Watir::Browser.new :firefox
driver.goto "http://google.com"
element = driver.text_field(:name => "q")
element.set "Cheese!\n"
puts "Page title is #{driver.title}"
driver.wait_until { driver.title.downcase.start_with? "cheese!" }
puts "Page title is #{driver.title}"
driver.close

···

--
Posted via http://www.ruby-forum.com/\.