SlideShare a Scribd company logo
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?
watir-webdriver
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
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

More Related Content

PDF
Watir web automated tests
PPT
What you can do In WatiR
PPT
Automated Testing With Watir
PPT
Introduction To Ruby Watir (Web Application Testing In Ruby)
PPT
Watir Presentation Sumanth Krishna. A
PDF
Introduction to Selenium and Ruby
PDF
Automated Testing with Ruby
DOC
Selenium Automation Using Ruby
Watir web automated tests
What you can do In WatiR
Automated Testing With Watir
Introduction To Ruby Watir (Web Application Testing In Ruby)
Watir Presentation Sumanth Krishna. A
Introduction to Selenium and Ruby
Automated Testing with Ruby
Selenium Automation Using Ruby

What's hot (20)

PDF
Automating Django Functional Tests Using Selenium on Cloud
PPTX
Web driver training
PPTX
Protractor framework – how to make stable e2e tests for Angular applications
PDF
Better Selenium Tests with Geb - Selenium Conf 2014
PPT
PDF
Introduction to Protractor
PDF
Top100summit 谷歌-scott-improve your automated web application testing
PDF
Selenium webdriver
PDF
Rails 3: Dashing to the Finish
DOCX
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
PDF
Selenium bootcamp slides
PPTX
End-to-end testing with geb
PDF
Django Heresies
PPTX
Test automation
KEY
SproutCore is Awesome - HTML5 Summer DevFest
PDF
BDD with cucumber
KEY
How To Write a WordPress Plugin
PPT
Selenium testing - Handle Elements in WebDriver
PDF
Scraping recalcitrant web sites with Python & Selenium
PPTX
Local SQLite Database with Node for beginners
Automating Django Functional Tests Using Selenium on Cloud
Web driver training
Protractor framework – how to make stable e2e tests for Angular applications
Better Selenium Tests with Geb - Selenium Conf 2014
Introduction to Protractor
Top100summit 谷歌-scott-improve your automated web application testing
Selenium webdriver
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...
Selenium bootcamp slides
End-to-end testing with geb
Django Heresies
Test automation
SproutCore is Awesome - HTML5 Summer DevFest
BDD with cucumber
How To Write a WordPress Plugin
Selenium testing - Handle Elements in WebDriver
Scraping recalcitrant web sites with Python & Selenium
Local SQLite Database with Node for beginners
Ad

Similar to watir-webdriver (20)

PPTX
Escape from the automation hell
PPTX
Jquery
PPTX
Android development with Scala and SBT
PDF
HTML5 New and Improved
PDF
Selenium Introduction by Sandeep Sharda
PDF
What you need to know bout html5
PDF
Html5 intro
PDF
Selenium testing
PPTX
PPTX
5 x HTML5 worth using in APEX (5)
PDF
Mojolicious
PPTX
PDF
Resource registries plone conf 2014
KEY
Html5 For Jjugccc2009fall
PDF
Javascript projects Course
PDF
J querypractice
KEY
Workshop quality assurance for php projects tek12
PPTX
Introduction to JQuery
Escape from the automation hell
Jquery
Android development with Scala and SBT
HTML5 New and Improved
Selenium Introduction by Sandeep Sharda
What you need to know bout html5
Html5 intro
Selenium testing
5 x HTML5 worth using in APEX (5)
Mojolicious
Resource registries plone conf 2014
Html5 For Jjugccc2009fall
Javascript projects Course
J querypractice
Workshop quality assurance for php projects tek12
Introduction to JQuery
Ad

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
A Presentation on Artificial Intelligence
PPTX
Big Data Technologies - Introduction.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Cloud computing and distributed systems.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Unlocking AI with Model Context Protocol (MCP)
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
A Presentation on Artificial Intelligence
Big Data Technologies - Introduction.pptx
Review of recent advances in non-invasive hemoglobin estimation
Cloud computing and distributed systems.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectral efficient network and resource selection model in 5G networks
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation_ Review paper, used for researhc scholars
20250228 LYD VKU AI Blended-Learning.pptx
The AUB Centre for AI in Media Proposal.docx
Per capita expenditure prediction using model stacking based on satellite ima...
Empathic Computing: Creating Shared Understanding
Unlocking AI with Model Context Protocol (MCP)

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?
  • 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
  • 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