SlideShare una empresa de Scribd logo
1 de 29
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Similar a 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 ✔
 

Similar a 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
 

Último

Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 
Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
Overkill Security
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 

Último (20)

Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfFrisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
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
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
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
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.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
 

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