SlideShare a Scribd company logo
1 of 29
Download to read offline
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

More Related Content

What's hot

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 CloudJonghyun Park
 
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 applicationsLudmila Nesvitiy
 
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 2014Naresha K
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to ProtractorJie-Wei Wu
 
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 testingdrewz lin
 
Selenium webdriver
Selenium webdriverSelenium webdriver
Selenium webdriversean_todd
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda 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
 
SproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFestSproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFesttomdale
 
How To Write a WordPress Plugin
How To Write a WordPress PluginHow To Write a WordPress Plugin
How To Write a WordPress PluginAndy Stratton
 
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 & SeleniumRoger Barnes
 
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 beginnersLaurence Svekis ✔
 

What's hot (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 to 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
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

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