SlideShare une entreprise Scribd logo
1  sur  29
Télécharger pour lire hors ligne
watir-webdriver
Who am I?


• Norway’s largest online marketplace
• 900 million page views / month
• 4 million unique users / month
Who am I?

      watir
     celerity
selenium-webdriver
 watir-webdriver
Who am I?

      watir
     celerity
selenium-webdriver
 watir-webdriver
Who am I?


   vnctools                                   childprocess
                  har            ffi-icu
ffi-sybase               webidl            jstd-runner

                  bamboo-client           cukeforker
    cuketagger
Who am I?

http://github.com/jarib

       @jarib
Ruby?
              Selenium RC?


WebDriver?                 Watir?

        Watir-WebDriver?

        Capybara?
selenium-webdriver

•   Official gem for Selenium 2

•   Slightly Rubyfied version of the WebDriver API

•   Also includes the RC API (selenium-client gem no longer maintained)
•   https://rubygems.org/gems/selenium-webdriver

•   http://selenium.googlecode.com
watir-webdriver

• Wraps selenium-webdriver in higher level
  API
• https://rubygems.org/gems/watir-webdriver
• https://github.com/jarib/watir-webdriver
Example
require 'selenium-webdriver'

                                 driver = Selenium::WebDriver.for :firefox
                                 driver.get "http://translate.google.com/"

                                 wait = Selenium::WebDriver::Wait.new(:timeout => 5)

                                 # wait for the language button to be displayed
                                 language_button = wait.until {
                                   element = driver.find_element(:id => "gt-sl-gms")
                                   element if element.displayed?
                                 }

                                 # click the first div to open the menu
                                 language_button.find_element(:tag_name => "div").click

                                 # wait for the menu
                                 menu = wait.until {
                                   element = driver.find_element(:id => "gt-sl-gms-menu")
                                   element if element.displayed?
                                 }


https://gist.github.com/902119   # fetch menu items
                                 langs = menu.find_elements(:class => "goog-menuitem")

                                 # click a language
                                 norwegian = langs.find { |lang| lang.text == "Norwegian" }
                                 norwegian.find_element(:tag_name => "div").click

                                 # print the chosen language
                                 puts language_button.text

                                 # set a string to translate
                                 driver.find_element(:id => "source").send_keys("ost")

                                 # wait for the result
                                 result = wait.until {
                                   result = driver.find_element(:id => "result_box").text
                                   result if result.length > 0
                                 }

                                 puts result
                                 driver.quit
require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox
driver.get "http://translate.google.com/"
wait = Selenium::WebDriver::Wait.new(:timeout => 5)

# wait for the language button to be displayed
language_button = wait.until {
  element = driver.find_element(:id => "gt-sl-gms")
  element if element.displayed?
}
# click the first div to open the menu
language_button.find_element(:tag_name => "div").click

# wait for the menu
menu = wait.until {
  element = driver.find_element(:id => "gt-sl-gms-menu")
  element if element.displayed?
}
# fetch menu items
langs = menu.find_elements(:class => "goog-menuitem")

# click a language
norwegian = langs.find { |lang| lang.text == "Norwegian" }
norwegian.find_element(:tag_name => "div").click

# print the chosen language
puts language_button.text
# set a string to translate
driver.find_element(:id => "source").send_keys("ost")

# wait   for the result
result   = wait.until {
  text   = driver.find_element(:id => "result_box").text
  text   if text.length > 0
}

puts result
driver.quit
selenium-webdriver

              require 'selenium-webdriver'

              driver = Selenium::WebDriver.for :firefox
              driver.get "http://translate.google.com/"




watir-webdriver

              require 'watir-webdriver'

              browser = Watir::Browser.new :firefox
              browser.goto "http://translate.google.com/"
selenium-webdriver

       wait = Selenium::WebDriver::Wait.new(:timeout => 5)

       language_button = wait.until {
         element = driver.find_element(:id => "gt-sl-gms")
         element if element.displayed?
       }

       language_button.find_element(:tag_name => "div").click


watir-webdriver

       language_button = browser.span(:id => "gt-sl-gms")
       language_button.when_present.div.click
selenium-webdriver
       menu = wait.until {
         element = driver.find_element(:id => "gt-sl-gms-menu")
         element if element.displayed?
       }

       langs = menu.find_elements(:class => "goog-menuitem")

       norwegian = langs.find { |lang| lang.text == "Norwegian" }
       norwegian.find_element(:tag_name => "div").click

watir-webdriver

       menu = browser.div(:id => "gt-sl-gms-menu")
       menu.when_present.div(
         :class => "goog-menuitem",
         :text => "Norwegian"
       ).div.click
selenium-webdriver

     driver.find_element(:id => "source").send_keys("ost")

     result = wait.until {
       text = driver.find_element(:id => "result_box").text
       text if text.length > 0
     }

     puts result
     driver.quit


watir-webdriver
      browser.text_field(:id => "source").set("ost")

      result_box = browser.span(:id => "result_box")
      browser.wait_until { result_box.text.length > 0 }

      puts result_box.text
      browser.close
https://gist.github.com/902125
selenium-webdriver


  >> driver.find_element(:id => "country")
  => #<Selenium::WebDriver::Element:0x..fa93ee tag_name="select">




watir-webdriver
  >> browser.select_list(:id => "country")
  => #<Watir::Select:0x..fa349d located=false selector={:id=>"country", :ta

  >> d.text_field(:name => "user")
  => #<Watir::TextField:0x..fb63099fd1e2f6130 located=false selector={:name
Voter turnout: <meter id=turnout value=0.75>75%</meter>




>> meter = browser.meter(:id => "turnout")
#=> #<Watir::Meter:0x3ebf128988f2b418 located=false selector={:
>> meter.value
#=> 0.75
>> meter.value.class
#=> Float
Watir::Anchor      Watir::FileField     Watir::Media       Watir::Style
Watir::Applet      Watir::Font          Watir::Menu        Watir::Table
Watir::Area        Watir::Form          Watir::Meta        Watir::TableCaption
Watir::Audio       Watir::Frame         Watir::Meter       Watir::TableCell
Watir::BR          Watir::FrameSet      Watir::Mod         Watir::TableCol
Watir::Base        Watir::HR            Watir::OList       Watir::TableDataCel
Watir::BaseFont    Watir::HTMLElement   Watir::Object      Watir::TableHeaderC
Watir::Body        Watir::Head          Watir::OptGroup    Watir::TableRow
Watir::Button      Watir::Heading       Watir::Option      Watir::TableSection
Watir::Canvas      Watir::Hidden        Watir::Output      Watir::TextArea
Watir::CheckBox    Watir::Html          Watir::Paragraph   Watir::TextField
Watir::Command     Watir::IFrame        Watir::Param       Watir::Time
Watir::DList       Watir::Image         Watir::Pre         Watir::Title
Watir::DataList    Watir::Input         Watir::Progress    Watir::Track
Watir::Details     Watir::Keygen        Watir::Quote       Watir::UList
Watir::Device      Watir::LI            Watir::Radio       Watir::Unknown
Watir::Directory   Watir::Label         Watir::Script      Watir::Video
Watir::Div         Watir::Legend        Watir::Select
Watir::Embed       Watir::Map           Watir::Source
Watir::FieldSet    Watir::Marquee       Watir::Span
Ruby code generated
from the HTML spec


          module Watir
            class Meter < HTMLElement
              attributes(
                :float        => [:value, :min, :max, :low, :high, :optimum],
                :html_element => [:form],
                :list         => [:labels]
              )
            end
          end
Comparison with Watir 1
https://github.com/jarib/watir-webdriver/wiki/Comparison-with-Watir-1.X


    •   Supports all browsers available in WebDriver

        •   Firefox, IE, Chrome; HtmlUnit, Opera, iPhone,
            Android

    •   Mostly compatible API-wise. Some major changes:

        •   0-indexed instead of 1-indexed

        •   All HTML tags supported (from the HTML5 spec)

        •   Revised table API

        •   New window switching API
Exercises
  gem install watir-webdriver

1. Write a test for http://figureoutwhen.com/
       https://gist.github.com/902139
2. Refactor the Google Translate example into a page
   object
       https://gist.github.com/902125
3. Use watir-webdriver to test your own app
       https://gist.github.com/902141

Contenu connexe

Tendances

Automating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudAutomating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on Cloud
Jonghyun Park
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
drewz lin
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
Rashedul Islam
 
Scraping recalcitrant web sites with Python & Selenium
Scraping recalcitrant web sites with Python & SeleniumScraping recalcitrant web sites with Python & Selenium
Scraping recalcitrant web sites with Python & Selenium
Roger Barnes
 

Tendances (20)

Automating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudAutomating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on Cloud
 
Web driver training
Web driver trainingWeb driver training
Web driver training
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
 
Better Selenium Tests with Geb - Selenium Conf 2014
Better Selenium Tests with Geb - Selenium Conf 2014Better Selenium Tests with Geb - Selenium Conf 2014
Better Selenium Tests with Geb - Selenium Conf 2014
 
Selenium
SeleniumSelenium
Selenium
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to Protractor
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
 
Selenium webdriver
Selenium webdriverSelenium webdriver
Selenium webdriver
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
 
Selenium bootcamp slides
Selenium bootcamp slides   Selenium bootcamp slides
Selenium bootcamp slides
 
End-to-end testing with geb
End-to-end testing with gebEnd-to-end testing with geb
End-to-end testing with geb
 
Django Heresies
Django HeresiesDjango Heresies
Django Heresies
 
Test automation
Test  automationTest  automation
Test automation
 
SproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFestSproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFest
 
BDD with cucumber
BDD with cucumberBDD with cucumber
BDD with cucumber
 
How To Write a WordPress Plugin
How To Write a WordPress PluginHow To Write a WordPress Plugin
How To Write a WordPress Plugin
 
Selenium testing - Handle Elements in WebDriver
Selenium testing - Handle Elements in WebDriver Selenium testing - Handle Elements in WebDriver
Selenium testing - Handle Elements in WebDriver
 
Scraping recalcitrant web sites with Python & Selenium
Scraping recalcitrant web sites with Python & SeleniumScraping recalcitrant web sites with Python & Selenium
Scraping recalcitrant web sites with Python & Selenium
 
Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLocal SQLite Database with Node for beginners
Local SQLite Database with Node for beginners
 

Similaire à watir-webdriver

Selenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep ShardaSelenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep Sharda
Er. Sndp Srda
 
Javascript projects Course
Javascript projects CourseJavascript projects Course
Javascript projects Course
Laurence Svekis ✔
 

Similaire à watir-webdriver (20)

Escape from the automation hell
Escape from the automation hellEscape from the automation hell
Escape from the automation hell
 
Jquery
JqueryJquery
Jquery
 
Android development with Scala and SBT
Android development with Scala and SBTAndroid development with Scala and SBT
Android development with Scala and SBT
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and Improved
 
Selenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep ShardaSelenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep Sharda
 
What you need to know bout html5
What you need to know bout html5What you need to know bout html5
What you need to know bout html5
 
Html5 intro
Html5 introHtml5 intro
Html5 intro
 
Selenium testing
Selenium testingSelenium testing
Selenium testing
 
Jquery
JqueryJquery
Jquery
 
5 x HTML5 worth using in APEX (5)
5 x HTML5 worth using in APEX (5)5 x HTML5 worth using in APEX (5)
5 x HTML5 worth using in APEX (5)
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Html5
Html5Html5
Html5
 
Resource registries plone conf 2014
Resource registries plone conf 2014Resource registries plone conf 2014
Resource registries plone conf 2014
 
JQuery
JQueryJQuery
JQuery
 
JQuery
JQueryJQuery
JQuery
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 
Javascript projects Course
Javascript projects CourseJavascript projects Course
Javascript projects Course
 
J querypractice
J querypracticeJ querypractice
J querypractice
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Introduction to JQuery
Introduction to JQueryIntroduction to JQuery
Introduction to JQuery
 

Dernier

Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 

Dernier (20)

2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 

watir-webdriver

  • 2. Who am I? • Norway’s largest online marketplace • 900 million page views / month • 4 million unique users / month
  • 3. Who am I? watir celerity selenium-webdriver watir-webdriver
  • 4. Who am I? watir celerity selenium-webdriver watir-webdriver
  • 5. Who am I? vnctools childprocess har ffi-icu ffi-sybase webidl jstd-runner bamboo-client cukeforker cuketagger
  • 7. Ruby? Selenium RC? WebDriver? Watir? Watir-WebDriver? Capybara?
  • 8.
  • 9. selenium-webdriver • Official gem for Selenium 2 • Slightly Rubyfied version of the WebDriver API • Also includes the RC API (selenium-client gem no longer maintained) • https://rubygems.org/gems/selenium-webdriver • http://selenium.googlecode.com
  • 10.
  • 11. watir-webdriver • Wraps selenium-webdriver in higher level API • https://rubygems.org/gems/watir-webdriver • https://github.com/jarib/watir-webdriver
  • 13. require 'selenium-webdriver' driver = Selenium::WebDriver.for :firefox driver.get "http://translate.google.com/" wait = Selenium::WebDriver::Wait.new(:timeout => 5) # wait for the language button to be displayed language_button = wait.until { element = driver.find_element(:id => "gt-sl-gms") element if element.displayed? } # click the first div to open the menu language_button.find_element(:tag_name => "div").click # wait for the menu menu = wait.until { element = driver.find_element(:id => "gt-sl-gms-menu") element if element.displayed? } https://gist.github.com/902119 # fetch menu items langs = menu.find_elements(:class => "goog-menuitem") # click a language norwegian = langs.find { |lang| lang.text == "Norwegian" } norwegian.find_element(:tag_name => "div").click # print the chosen language puts language_button.text # set a string to translate driver.find_element(:id => "source").send_keys("ost") # wait for the result result = wait.until { result = driver.find_element(:id => "result_box").text result if result.length > 0 } puts result driver.quit
  • 14. require 'selenium-webdriver' driver = Selenium::WebDriver.for :firefox driver.get "http://translate.google.com/"
  • 15. wait = Selenium::WebDriver::Wait.new(:timeout => 5) # wait for the language button to be displayed language_button = wait.until { element = driver.find_element(:id => "gt-sl-gms") element if element.displayed? }
  • 16. # click the first div to open the menu language_button.find_element(:tag_name => "div").click # wait for the menu menu = wait.until { element = driver.find_element(:id => "gt-sl-gms-menu") element if element.displayed? }
  • 17. # fetch menu items langs = menu.find_elements(:class => "goog-menuitem") # click a language norwegian = langs.find { |lang| lang.text == "Norwegian" } norwegian.find_element(:tag_name => "div").click # print the chosen language puts language_button.text
  • 18. # set a string to translate driver.find_element(:id => "source").send_keys("ost") # wait for the result result = wait.until { text = driver.find_element(:id => "result_box").text text if text.length > 0 } puts result driver.quit
  • 19. selenium-webdriver require 'selenium-webdriver' driver = Selenium::WebDriver.for :firefox driver.get "http://translate.google.com/" watir-webdriver require 'watir-webdriver' browser = Watir::Browser.new :firefox browser.goto "http://translate.google.com/"
  • 20. selenium-webdriver wait = Selenium::WebDriver::Wait.new(:timeout => 5) language_button = wait.until { element = driver.find_element(:id => "gt-sl-gms") element if element.displayed? } language_button.find_element(:tag_name => "div").click watir-webdriver language_button = browser.span(:id => "gt-sl-gms") language_button.when_present.div.click
  • 21. selenium-webdriver menu = wait.until { element = driver.find_element(:id => "gt-sl-gms-menu") element if element.displayed? } langs = menu.find_elements(:class => "goog-menuitem") norwegian = langs.find { |lang| lang.text == "Norwegian" } norwegian.find_element(:tag_name => "div").click watir-webdriver menu = browser.div(:id => "gt-sl-gms-menu") menu.when_present.div( :class => "goog-menuitem", :text => "Norwegian" ).div.click
  • 22. selenium-webdriver driver.find_element(:id => "source").send_keys("ost") result = wait.until { text = driver.find_element(:id => "result_box").text text if text.length > 0 } puts result driver.quit watir-webdriver browser.text_field(:id => "source").set("ost") result_box = browser.span(:id => "result_box") browser.wait_until { result_box.text.length > 0 } puts result_box.text browser.close
  • 24. selenium-webdriver >> driver.find_element(:id => "country") => #<Selenium::WebDriver::Element:0x..fa93ee tag_name="select"> watir-webdriver >> browser.select_list(:id => "country") => #<Watir::Select:0x..fa349d located=false selector={:id=>"country", :ta >> d.text_field(:name => "user") => #<Watir::TextField:0x..fb63099fd1e2f6130 located=false selector={:name
  • 25. Voter turnout: <meter id=turnout value=0.75>75%</meter> >> meter = browser.meter(:id => "turnout") #=> #<Watir::Meter:0x3ebf128988f2b418 located=false selector={: >> meter.value #=> 0.75 >> meter.value.class #=> Float
  • 26. Watir::Anchor Watir::FileField Watir::Media Watir::Style Watir::Applet Watir::Font Watir::Menu Watir::Table Watir::Area Watir::Form Watir::Meta Watir::TableCaption Watir::Audio Watir::Frame Watir::Meter Watir::TableCell Watir::BR Watir::FrameSet Watir::Mod Watir::TableCol Watir::Base Watir::HR Watir::OList Watir::TableDataCel Watir::BaseFont Watir::HTMLElement Watir::Object Watir::TableHeaderC Watir::Body Watir::Head Watir::OptGroup Watir::TableRow Watir::Button Watir::Heading Watir::Option Watir::TableSection Watir::Canvas Watir::Hidden Watir::Output Watir::TextArea Watir::CheckBox Watir::Html Watir::Paragraph Watir::TextField Watir::Command Watir::IFrame Watir::Param Watir::Time Watir::DList Watir::Image Watir::Pre Watir::Title Watir::DataList Watir::Input Watir::Progress Watir::Track Watir::Details Watir::Keygen Watir::Quote Watir::UList Watir::Device Watir::LI Watir::Radio Watir::Unknown Watir::Directory Watir::Label Watir::Script Watir::Video Watir::Div Watir::Legend Watir::Select Watir::Embed Watir::Map Watir::Source Watir::FieldSet Watir::Marquee Watir::Span
  • 27. Ruby code generated from the HTML spec module Watir class Meter < HTMLElement attributes( :float => [:value, :min, :max, :low, :high, :optimum], :html_element => [:form], :list => [:labels] ) end end
  • 28. Comparison with Watir 1 https://github.com/jarib/watir-webdriver/wiki/Comparison-with-Watir-1.X • Supports all browsers available in WebDriver • Firefox, IE, Chrome; HtmlUnit, Opera, iPhone, Android • Mostly compatible API-wise. Some major changes: • 0-indexed instead of 1-indexed • All HTML tags supported (from the HTML5 spec) • Revised table API • New window switching API
  • 29. Exercises gem install watir-webdriver 1. Write a test for http://figureoutwhen.com/ https://gist.github.com/902139 2. Refactor the Google Translate example into a page object https://gist.github.com/902125 3. Use watir-webdriver to test your own app https://gist.github.com/902141