SlideShare uma empresa Scribd logo
1 de 69
Baixar para ler offline
Browser-level testing
    Martin Kleppmann
           Go Test It
    Email: martin@go-test.it
    Blog: yes-no-cancel.co.uk
       Twitter: @martinkl
“But I have unit
    tests!”
?
Array literals?


var x = [1,];

x.length == 1   // Firefox 3.5
x.length == 2   // IE 7
Uninitialised vars?


<div id="hello"></div>

typeof(hello) == 'undefined' // Firefox 3.5
typeof(hello) == 'object'    // IE 7
Attempt #1:
Simulate events in JavaScript.

       (Selenium, Windmill, Sahi)
Attempt #1: Simulate events in JavaScript.




        Selenium         example.com
Attempt #1: Simulate events in JavaScript.



                   click
        Selenium           example.com
Attempt #1: Simulate events in JavaScript.



                           click
         Selenium                  example.com


   http://localhost:8080      http://test.example.com
Attempt #1: Simulate events in JavaScript.
                                    Cross-domain
                                    security policy


                           click
         Selenium                  example.com


   http://localhost:8080      http://test.example.com
Attempt #1: Simulate events in JavaScript.




        Selenium         example.com
Attempt #1: Simulate events in JavaScript.




        Selenium            example.com



            test.example.com proxy
Attempt #1: Simulate events in JavaScript.




        Selenium             example.com



             test.example.com proxy
    /selenium-server/                 /*
Attempt #1: Simulate events in JavaScript.



                        click
        Selenium                example.com



             test.example.com proxy
    /selenium-server/                  /*
Limitations

• Redirect to other domain or https
• Outside of DOM: pop-ups, Flash, ...
• Slow
Attempt #2:
Browser-specific automation
          APIs.
        (WebDriver, Watir)
IE


  Firefox


  Safari


  Chrome


  Opera


HTMLUnit
IE


              Firefox


              Safari
WebDriver
              Chrome


              Opera


            HTMLUnit
IE


              Firefox


              Safari
WebDriver
              Chrome


              Opera


            HTMLUnit
IE


              Firefox


              Safari
WebDriver
              Chrome


              Opera
  Watir

            HTMLUnit
IE


              Firefox


              Safari
WebDriver
              Chrome


              Opera
  Watir

            HTMLUnit
IE

Selenium
              Firefox


              Safari
WebDriver
              Chrome


              Opera
  Watir

            HTMLUnit
IE

Selenium
              Firefox


              Safari
WebDriver
              Chrome


              Opera
  Watir

            HTMLUnit
IE

Selenium
              Firefox


              Safari
WebDriver
              Chrome


              Opera
  Watir

            HTMLUnit
Selenium   WebDriver   Watir


  IE

  Firefox

  Safari

  Chrome

  Opera

HTMLUnit
Selenium    WebDriver        Watir

  IE        HTA/Proxy    ✔ COM          ✔ COM


  Firefox   Ext/Proxy   ✔ Extension   ✔ Extension


  Safari      Proxy         ✘         ✔ AppleScript


  Chrome      Proxy     ✔ Extension   ✔ V8 Debug


  Opera       Proxy     Dragonfly?          ✘


HTMLUnit       ✘            ✔          ✔ Celerity
Watir
require 'watir'
Watir::Browser.default = 'firefox'

describe 'Google' do
  before(:each) { @browser = Watir::Browser.new }
  after(:each) { @browser.close }

  it 'should return search results for "hello world"' do
    @browser.goto "http://www.google.co.uk"
    @browser.text_field(:name, "q").set("hello world")
    @browser.button(:name, "btnG").click
    @browser.contains_text(
      "Hello world program - Wikipedia").should be_true
  end
end
WebDriver
require 'selenium-webdriver'

describe 'Google' do
  before(:each) { @browser = Selenium::WebDriver.for :firefox }
  after(:each) { @browser.quit }

  it 'should return search results for "hello world"' do
    @browser.navigate.to "http://www.google.co.uk"
    @browser.find_element(:name, "q").send_keys("hello world")
    @browser.find_element(:name, "btnG").submit
    @browser.find_element(:partial_link_text,
      "Hello world program - Wikipedia")
  end
end
Selenium
gem 'selenium-client'; require 'selenium/client'

describe 'Google' do
  before(:each) {
    @browser = Selenium::Client::Driver.new :browser => "*firefox",
      :url => "http://www.google.co.uk"
    @browser.start
  }
  after(:each) { @browser.stop }

  it 'should return search results for "hello world"' do
    @browser.open "/"
    @browser.type "q", "hello world"
    @browser.click "btnG", :wait_for => :text, :text => 'Results'
    @browser.is_text_present("Hello world program - Wikipedia").
      should be_true
  end
end
Go Test It (≈Selenium)
require 'gotest'

gotest "http://www.google.co.uk" do
  open "/"
  type "q", "hello world"
  click "btnG"
  verify_text_present "Hello world program - Wikipedia"
end
Cucumber
Feature: Google search
  In order to learn something new
  As an enthusiast for obscure programming languages
  I want to find "Hello world" programs on Google

  Scenario: Search for "hello world"
    Given that I am on google.co.uk
    When I enter "hello world" into the search box
    And I submit the form
    Then I should be shown a list of results
    And the page should contain "Hello world program -
Wikipedia"
IE

Selenium
              Firefox


              Safari
WebDriver
              Chrome


              Opera
  Watir

            HTMLUnit
IE

Selenium
              Firefox


              Safari
WebDriver
              Chrome


              Opera
  Watir

            HTMLUnit
IE

Selenium
                         Firefox


                         Safari
           WebDriver
                         Chrome


                         Opera
 Watir

                       HTMLUnit
The future?                    IE

    Selenium
  Selenium API
                               Firefox


                               Safari
                 WebDriver
                               Chrome


                               Opera
    Watir
   Watir API

                             HTMLUnit
Ok.
Fundamental goal:
  Robust tests
Choose your locators
     carefully
Choose your locators
     carefully
             id = searchInput
              name = search
xpath = //form[@id='searchform']/input[2]
link = EU makes 7bn euro climate pledge
link = EU makes 7bn euro climate pledge

  xpath = //td[@class='text']/div[1]/a
link = EU makes 7bn euro climate pledge

  xpath = //td[@class='text']/div[1]/a

              css = a.tsh
People are complicated


 Frontend tests are
       messy
2 approaches:

         Disposable tests
   (record/playback, quick&dirty)


   Domain-specific abstractions
       (carefully crafted)
Which
approach will
 you take?
Thank you!
Martin Kleppmann
       Go Test It
Email: martin@go-test.it
Blog: yes-no-cancel.co.uk
   Twitter: @martinkl
Fundamental goal:
 Parallel tests
Don’t assume a clean database
Don’t assume a clean database
Unit tests:

Load fixtures

  Given...

  When...

  Then...

  Reset database
Don’t assume a clean database
Unit tests:        Functional tests:

Load fixtures       Set up example data

  Given...           Do stuff   Do stuff

  When...
                    Check       Check
  Then...           outcome     outcome

  Reset database
Tolerate partially run tests
Tolerate partially run tests


(Assume there is no frob)

Create frob

Check frob was created

Delete frob
Tolerate partially run tests


(Assume there is no frob)

Create frob

Check frob was created

Delete frob
Tolerate partially run tests
Bad:

       Boom!
(Assume there is no frob)

Create frob

Check frob was created

Delete frob
Tolerate partially run tests
Bad:                        Better:

       Boom!
(Assume there is no frob)   Delete frob if it exists

Create frob                 Create frob

Check frob was created      Check frob was created

Delete frob                 Delete frob (optional)
Avoid race conditions: isolation
Avoid race conditions: isolation


 Delete frob if it exists   Delete frob if it exists

 Create frob                Create frob

 Check frob was created     Check frob was created
Avoid race conditions: isolation
Log in as User A            Log in as User B


 Delete frob if it exists   Delete frob if it exists

 Create frob                Create frob

 Check frob was created     Check frob was created
Avoid race conditions: isolation
Log in as User A               Log in as User B


 Delete frob if it exists      Delete frob if it exists

 Create frob                   Create frob

 Check frob was created        Check frob was created



User A and User B: independent & not used concurrently
Make test runs unique
Make test runs unique
Make test runs unique
Take care with external services
Thank you!
Martin Kleppmann
       Go Test It
Email: martin@go-test.it
Blog: yes-no-cancel.co.uk
   Twitter: @martinkl

Mais conteúdo relacionado

Mais procurados

High Performance JavaScript 2011
High Performance JavaScript 2011High Performance JavaScript 2011
High Performance JavaScript 2011Nicholas Zakas
 
Webdriver cheatsheets summary
Webdriver cheatsheets summaryWebdriver cheatsheets summary
Webdriver cheatsheets summaryAlan Richardson
 
2011 a grape odyssey
2011   a grape odyssey2011   a grape odyssey
2011 a grape odysseyMike Hagedorn
 
High Performance JavaScript - jQuery Conference SF Bay Area 2010
High Performance JavaScript - jQuery Conference SF Bay Area 2010High Performance JavaScript - jQuery Conference SF Bay Area 2010
High Performance JavaScript - jQuery Conference SF Bay Area 2010Nicholas Zakas
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015Matt Raible
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Rich Web Experie...
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Rich Web Experie...Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Rich Web Experie...
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Rich Web Experie...Matt Raible
 
Test Automation using Ruby
Test Automation using Ruby Test Automation using Ruby
Test Automation using Ruby Sla Va
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016Matt Raible
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applicationsqooxdoo
 
Join the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.jsJoin the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.jsSeth McLaughlin
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Hazem Saleh
 
React Native in Production
React Native in ProductionReact Native in Production
React Native in ProductionSeokjun Kim
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsLuís Bastião Silva
 
One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.Javier López
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP applicationJavier López
 
Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot ActuatorRowell Belen
 

Mais procurados (20)

Cache is King
Cache is KingCache is King
Cache is King
 
High Performance JavaScript 2011
High Performance JavaScript 2011High Performance JavaScript 2011
High Performance JavaScript 2011
 
Webdriver cheatsheets summary
Webdriver cheatsheets summaryWebdriver cheatsheets summary
Webdriver cheatsheets summary
 
2011 a grape odyssey
2011   a grape odyssey2011   a grape odyssey
2011 a grape odyssey
 
High Performance JavaScript - jQuery Conference SF Bay Area 2010
High Performance JavaScript - jQuery Conference SF Bay Area 2010High Performance JavaScript - jQuery Conference SF Bay Area 2010
High Performance JavaScript - jQuery Conference SF Bay Area 2010
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Rich Web Experie...
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Rich Web Experie...Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Rich Web Experie...
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Rich Web Experie...
 
Test Automation using Ruby
Test Automation using Ruby Test Automation using Ruby
Test Automation using Ruby
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applications
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Join the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.jsJoin the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.js
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
 
React Native in Production
React Native in ProductionReact Native in Production
React Native in Production
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.js
 
One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP application
 
Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot Actuator
 
Dust.js
Dust.jsDust.js
Dust.js
 
Rebooting a Cloud
Rebooting a CloudRebooting a Cloud
Rebooting a Cloud
 

Destaque

Coolblue Behind The Scenes - Feb 2017 - Mikado Method
Coolblue Behind The Scenes - Feb 2017 - Mikado MethodCoolblue Behind The Scenes - Feb 2017 - Mikado Method
Coolblue Behind The Scenes - Feb 2017 - Mikado MethodNathan Johnstone
 
Invoicing Gem - Sales & Payments In Your App
Invoicing Gem - Sales & Payments In Your AppInvoicing Gem - Sales & Payments In Your App
Invoicing Gem - Sales & Payments In Your AppMartin Kleppmann
 
Building domain-specific languages with Groovy
Building domain-specific languages with GroovyBuilding domain-specific languages with Groovy
Building domain-specific languages with GroovyYaroslav Yermilov
 
Groovy for Java Developers
Groovy for Java DevelopersGroovy for Java Developers
Groovy for Java DevelopersPeter Ledbrook
 
User Testing by Example
User Testing by ExampleUser Testing by Example
User Testing by ExampleJeremy Horn
 
Agile testing and_the_banking_domain_2009
Agile testing and_the_banking_domain_2009Agile testing and_the_banking_domain_2009
Agile testing and_the_banking_domain_2009Anil Kumar
 
Advanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakesAdvanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakesMilan Vukoje
 
Is an agile SDLC an oxymoron?
Is an agile SDLC an oxymoron? Is an agile SDLC an oxymoron?
Is an agile SDLC an oxymoron? Dave Sharrock
 
Testing of e-Banking - Case Study
Testing of e-Banking - Case Study Testing of e-Banking - Case Study
Testing of e-Banking - Case Study OAK Systems Pvt Ltd
 
Linking Upstream and Downstream Agile
Linking Upstream and Downstream AgileLinking Upstream and Downstream Agile
Linking Upstream and Downstream AgileCollabNet
 
End-2-End Monitoring – Der Prüfstand jedes SLA´s – in 15 Minuten erklärt!
End-2-End Monitoring – Der Prüfstand jedes SLA´s – in 15 Minuten erklärt!End-2-End Monitoring – Der Prüfstand jedes SLA´s – in 15 Minuten erklärt!
End-2-End Monitoring – Der Prüfstand jedes SLA´s – in 15 Minuten erklärt!MAXXYS AG
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JSMichael Haberman
 
What Mr. Spock would possibly say about modern unit testing: pragmatic and em...
What Mr. Spock would possibly say about modern unit testing: pragmatic and em...What Mr. Spock would possibly say about modern unit testing: pragmatic and em...
What Mr. Spock would possibly say about modern unit testing: pragmatic and em...Yaroslav Yermilov
 
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in JavaYakov Fain
 
The Impact of Big Data On Marketing Analytics (UpStream Software)
The Impact of Big Data On Marketing Analytics (UpStream Software)The Impact of Big Data On Marketing Analytics (UpStream Software)
The Impact of Big Data On Marketing Analytics (UpStream Software)Revolution Analytics
 
Code lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzCode lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzIvan Krylov
 
JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6Bert Ertman
 
Software testing methods, levels and types
Software testing methods, levels and typesSoftware testing methods, levels and types
Software testing methods, levels and typesConfiz
 

Destaque (20)

Coolblue Behind The Scenes - Feb 2017 - Mikado Method
Coolblue Behind The Scenes - Feb 2017 - Mikado MethodCoolblue Behind The Scenes - Feb 2017 - Mikado Method
Coolblue Behind The Scenes - Feb 2017 - Mikado Method
 
Invoicing Gem - Sales & Payments In Your App
Invoicing Gem - Sales & Payments In Your AppInvoicing Gem - Sales & Payments In Your App
Invoicing Gem - Sales & Payments In Your App
 
Building domain-specific languages with Groovy
Building domain-specific languages with GroovyBuilding domain-specific languages with Groovy
Building domain-specific languages with Groovy
 
Groovy for Java Developers
Groovy for Java DevelopersGroovy for Java Developers
Groovy for Java Developers
 
User Testing by Example
User Testing by ExampleUser Testing by Example
User Testing by Example
 
QA Tester Junior
QA Tester JuniorQA Tester Junior
QA Tester Junior
 
Agile testing and_the_banking_domain_2009
Agile testing and_the_banking_domain_2009Agile testing and_the_banking_domain_2009
Agile testing and_the_banking_domain_2009
 
Advanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakesAdvanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakes
 
Is an agile SDLC an oxymoron?
Is an agile SDLC an oxymoron? Is an agile SDLC an oxymoron?
Is an agile SDLC an oxymoron?
 
Testing of e-Banking - Case Study
Testing of e-Banking - Case Study Testing of e-Banking - Case Study
Testing of e-Banking - Case Study
 
Linking Upstream and Downstream Agile
Linking Upstream and Downstream AgileLinking Upstream and Downstream Agile
Linking Upstream and Downstream Agile
 
End-2-End Monitoring – Der Prüfstand jedes SLA´s – in 15 Minuten erklärt!
End-2-End Monitoring – Der Prüfstand jedes SLA´s – in 15 Minuten erklärt!End-2-End Monitoring – Der Prüfstand jedes SLA´s – in 15 Minuten erklärt!
End-2-End Monitoring – Der Prüfstand jedes SLA´s – in 15 Minuten erklärt!
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
 
What Mr. Spock would possibly say about modern unit testing: pragmatic and em...
What Mr. Spock would possibly say about modern unit testing: pragmatic and em...What Mr. Spock would possibly say about modern unit testing: pragmatic and em...
What Mr. Spock would possibly say about modern unit testing: pragmatic and em...
 
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in Java
 
The Impact of Big Data On Marketing Analytics (UpStream Software)
The Impact of Big Data On Marketing Analytics (UpStream Software)The Impact of Big Data On Marketing Analytics (UpStream Software)
The Impact of Big Data On Marketing Analytics (UpStream Software)
 
Code lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzCode lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf Linz
 
JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6
 
Testing web application
Testing web applicationTesting web application
Testing web application
 
Software testing methods, levels and types
Software testing methods, levels and typesSoftware testing methods, levels and types
Software testing methods, levels and types
 

Semelhante a Browser-level testing

Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Ondřej Machulda
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupDave Haeffner
 
Acceptance testing plone sites and add ons with robot framework and selenium
Acceptance testing plone sites and add ons with robot framework and seleniumAcceptance testing plone sites and add ons with robot framework and selenium
Acceptance testing plone sites and add ons with robot framework and seleniumAsko Soukka
 
Integration Test Cucumber + Webrat + Selenium
Integration Test Cucumber + Webrat + SeleniumIntegration Test Cucumber + Webrat + Selenium
Integration Test Cucumber + Webrat + Seleniumtka
 
Selenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver TutorialSelenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver TutorialAlan Richardson
 
Watir Presentation Sumanth Krishna. A
Watir Presentation   Sumanth Krishna. AWatir Presentation   Sumanth Krishna. A
Watir Presentation Sumanth Krishna. ASumanth krishna
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Applitools
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Appschrisb206 chrisb206
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium SuccessfullyDave Haeffner
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)Sauce Labs
 
Testing Web Apps With Scripting Language - Mark Rees, Century Software
Testing Web Apps With Scripting Language - Mark Rees, Century SoftwareTesting Web Apps With Scripting Language - Mark Rees, Century Software
Testing Web Apps With Scripting Language - Mark Rees, Century SoftwareLinuxmalaysia Malaysia
 
Selenium and Sauce Labs
Selenium and Sauce LabsSelenium and Sauce Labs
Selenium and Sauce Labshugs
 
Selenium 2 for PHP(Unit)
Selenium 2 for PHP(Unit)Selenium 2 for PHP(Unit)
Selenium 2 for PHP(Unit)AOE
 

Semelhante a Browser-level testing (20)

Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
 
Selenium.pptx
Selenium.pptxSelenium.pptx
Selenium.pptx
 
Selenium testing - Handle Elements in WebDriver
Selenium testing - Handle Elements in WebDriver Selenium testing - Handle Elements in WebDriver
Selenium testing - Handle Elements in WebDriver
 
Acceptance testing plone sites and add ons with robot framework and selenium
Acceptance testing plone sites and add ons with robot framework and seleniumAcceptance testing plone sites and add ons with robot framework and selenium
Acceptance testing plone sites and add ons with robot framework and selenium
 
Integration Test Cucumber + Webrat + Selenium
Integration Test Cucumber + Webrat + SeleniumIntegration Test Cucumber + Webrat + Selenium
Integration Test Cucumber + Webrat + Selenium
 
Selenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver TutorialSelenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver Tutorial
 
Watir Presentation Sumanth Krishna. A
Watir Presentation   Sumanth Krishna. AWatir Presentation   Sumanth Krishna. A
Watir Presentation Sumanth Krishna. A
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully
 
Automation Zaman Now
Automation Zaman NowAutomation Zaman Now
Automation Zaman Now
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
 
orcreatehappyusers
orcreatehappyusersorcreatehappyusers
orcreatehappyusers
 
orcreatehappyusers
orcreatehappyusersorcreatehappyusers
orcreatehappyusers
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 
Automated ui-testing
Automated ui-testingAutomated ui-testing
Automated ui-testing
 
Introduction to selenium web driver
Introduction to selenium web driverIntroduction to selenium web driver
Introduction to selenium web driver
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
 
Testing Web Apps With Scripting Language - Mark Rees, Century Software
Testing Web Apps With Scripting Language - Mark Rees, Century SoftwareTesting Web Apps With Scripting Language - Mark Rees, Century Software
Testing Web Apps With Scripting Language - Mark Rees, Century Software
 
Selenium and Sauce Labs
Selenium and Sauce LabsSelenium and Sauce Labs
Selenium and Sauce Labs
 
Selenium 2 for PHP(Unit)
Selenium 2 for PHP(Unit)Selenium 2 for PHP(Unit)
Selenium 2 for PHP(Unit)
 

Último

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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
 
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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 

Último (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Browser-level testing

  • 1. Browser-level testing Martin Kleppmann Go Test It Email: martin@go-test.it Blog: yes-no-cancel.co.uk Twitter: @martinkl
  • 2. “But I have unit tests!”
  • 3.
  • 4. ?
  • 5. Array literals? var x = [1,]; x.length == 1 // Firefox 3.5 x.length == 2 // IE 7
  • 6. Uninitialised vars? <div id="hello"></div> typeof(hello) == 'undefined' // Firefox 3.5 typeof(hello) == 'object' // IE 7
  • 7.
  • 8. Attempt #1: Simulate events in JavaScript. (Selenium, Windmill, Sahi)
  • 9. Attempt #1: Simulate events in JavaScript. Selenium example.com
  • 10. Attempt #1: Simulate events in JavaScript. click Selenium example.com
  • 11. Attempt #1: Simulate events in JavaScript. click Selenium example.com http://localhost:8080 http://test.example.com
  • 12. Attempt #1: Simulate events in JavaScript. Cross-domain security policy click Selenium example.com http://localhost:8080 http://test.example.com
  • 13. Attempt #1: Simulate events in JavaScript. Selenium example.com
  • 14. Attempt #1: Simulate events in JavaScript. Selenium example.com test.example.com proxy
  • 15. Attempt #1: Simulate events in JavaScript. Selenium example.com test.example.com proxy /selenium-server/ /*
  • 16. Attempt #1: Simulate events in JavaScript. click Selenium example.com test.example.com proxy /selenium-server/ /*
  • 17. Limitations • Redirect to other domain or https • Outside of DOM: pop-ups, Flash, ... • Slow
  • 18. Attempt #2: Browser-specific automation APIs. (WebDriver, Watir)
  • 19.
  • 20. IE Firefox Safari Chrome Opera HTMLUnit
  • 21. IE Firefox Safari WebDriver Chrome Opera HTMLUnit
  • 22. IE Firefox Safari WebDriver Chrome Opera HTMLUnit
  • 23. IE Firefox Safari WebDriver Chrome Opera Watir HTMLUnit
  • 24. IE Firefox Safari WebDriver Chrome Opera Watir HTMLUnit
  • 25. IE Selenium Firefox Safari WebDriver Chrome Opera Watir HTMLUnit
  • 26. IE Selenium Firefox Safari WebDriver Chrome Opera Watir HTMLUnit
  • 27. IE Selenium Firefox Safari WebDriver Chrome Opera Watir HTMLUnit
  • 28. Selenium WebDriver Watir IE Firefox Safari Chrome Opera HTMLUnit
  • 29. Selenium WebDriver Watir IE HTA/Proxy ✔ COM ✔ COM Firefox Ext/Proxy ✔ Extension ✔ Extension Safari Proxy ✘ ✔ AppleScript Chrome Proxy ✔ Extension ✔ V8 Debug Opera Proxy Dragonfly? ✘ HTMLUnit ✘ ✔ ✔ Celerity
  • 30. Watir require 'watir' Watir::Browser.default = 'firefox' describe 'Google' do before(:each) { @browser = Watir::Browser.new } after(:each) { @browser.close } it 'should return search results for "hello world"' do @browser.goto "http://www.google.co.uk" @browser.text_field(:name, "q").set("hello world") @browser.button(:name, "btnG").click @browser.contains_text( "Hello world program - Wikipedia").should be_true end end
  • 31. WebDriver require 'selenium-webdriver' describe 'Google' do before(:each) { @browser = Selenium::WebDriver.for :firefox } after(:each) { @browser.quit } it 'should return search results for "hello world"' do @browser.navigate.to "http://www.google.co.uk" @browser.find_element(:name, "q").send_keys("hello world") @browser.find_element(:name, "btnG").submit @browser.find_element(:partial_link_text, "Hello world program - Wikipedia") end end
  • 32. Selenium gem 'selenium-client'; require 'selenium/client' describe 'Google' do before(:each) { @browser = Selenium::Client::Driver.new :browser => "*firefox", :url => "http://www.google.co.uk" @browser.start } after(:each) { @browser.stop } it 'should return search results for "hello world"' do @browser.open "/" @browser.type "q", "hello world" @browser.click "btnG", :wait_for => :text, :text => 'Results' @browser.is_text_present("Hello world program - Wikipedia"). should be_true end end
  • 33. Go Test It (≈Selenium) require 'gotest' gotest "http://www.google.co.uk" do open "/" type "q", "hello world" click "btnG" verify_text_present "Hello world program - Wikipedia" end
  • 34. Cucumber Feature: Google search In order to learn something new As an enthusiast for obscure programming languages I want to find "Hello world" programs on Google Scenario: Search for "hello world" Given that I am on google.co.uk When I enter "hello world" into the search box And I submit the form Then I should be shown a list of results And the page should contain "Hello world program - Wikipedia"
  • 35. IE Selenium Firefox Safari WebDriver Chrome Opera Watir HTMLUnit
  • 36. IE Selenium Firefox Safari WebDriver Chrome Opera Watir HTMLUnit
  • 37. IE Selenium Firefox Safari WebDriver Chrome Opera Watir HTMLUnit
  • 38. The future? IE Selenium Selenium API Firefox Safari WebDriver Chrome Opera Watir Watir API HTMLUnit
  • 39. Ok.
  • 40. Fundamental goal: Robust tests
  • 41. Choose your locators carefully
  • 42. Choose your locators carefully id = searchInput name = search xpath = //form[@id='searchform']/input[2]
  • 43.
  • 44.
  • 45. link = EU makes 7bn euro climate pledge
  • 46. link = EU makes 7bn euro climate pledge xpath = //td[@class='text']/div[1]/a
  • 47. link = EU makes 7bn euro climate pledge xpath = //td[@class='text']/div[1]/a css = a.tsh
  • 48. People are complicated Frontend tests are messy
  • 49. 2 approaches: Disposable tests (record/playback, quick&dirty) Domain-specific abstractions (carefully crafted)
  • 51. Thank you! Martin Kleppmann Go Test It Email: martin@go-test.it Blog: yes-no-cancel.co.uk Twitter: @martinkl
  • 53. Don’t assume a clean database
  • 54. Don’t assume a clean database Unit tests: Load fixtures Given... When... Then... Reset database
  • 55. Don’t assume a clean database Unit tests: Functional tests: Load fixtures Set up example data Given... Do stuff Do stuff When... Check Check Then... outcome outcome Reset database
  • 57. Tolerate partially run tests (Assume there is no frob) Create frob Check frob was created Delete frob
  • 58. Tolerate partially run tests (Assume there is no frob) Create frob Check frob was created Delete frob
  • 59. Tolerate partially run tests Bad: Boom! (Assume there is no frob) Create frob Check frob was created Delete frob
  • 60. Tolerate partially run tests Bad: Better: Boom! (Assume there is no frob) Delete frob if it exists Create frob Create frob Check frob was created Check frob was created Delete frob Delete frob (optional)
  • 62. Avoid race conditions: isolation Delete frob if it exists Delete frob if it exists Create frob Create frob Check frob was created Check frob was created
  • 63. Avoid race conditions: isolation Log in as User A Log in as User B Delete frob if it exists Delete frob if it exists Create frob Create frob Check frob was created Check frob was created
  • 64. Avoid race conditions: isolation Log in as User A Log in as User B Delete frob if it exists Delete frob if it exists Create frob Create frob Check frob was created Check frob was created User A and User B: independent & not used concurrently
  • 65. Make test runs unique
  • 66. Make test runs unique
  • 67. Make test runs unique
  • 68. Take care with external services
  • 69. Thank you! Martin Kleppmann Go Test It Email: martin@go-test.it Blog: yes-no-cancel.co.uk Twitter: @martinkl