Forum: Ruby Ruby + Selenium-webdriver

C52c918b7c82ece67eb06f2129ad4090?d=identicon&s=25 Mattias A. (mattias_a)
on 2012-11-26 19:51
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
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2012-11-26 22:19
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.
C52c918b7c82ece67eb06f2129ad4090?d=identicon&s=25 Mattias A. (mattias_a)
on 2012-11-27 17:57
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
C52c918b7c82ece67eb06f2129ad4090?d=identicon&s=25 Mattias A. (mattias_a)
on 2012-11-27 22:06
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
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2012-11-28 09:56
> 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-webdrive...
>
> 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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.