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

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 (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

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Último (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

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