+ All Categories
Home > Technology > Cross-browser testing in the real world

Cross-browser testing in the real world

Date post: 06-May-2015
Category:
Upload: martin-kleppmann
View: 9,345 times
Download: 3 times
Share this document with a friend
Description:
What's the best way of automating end-to-end, browser-level tests for web apps? In this talk, I compare Selenium, WebDriver, Watir and other libraries, and share experience of automated browser tests on hundreds of different sites. I also give updates on latest developments in open source functional testing tools.
111
Crossbrowser tes*ng real world Mar*n Kleppmann rapportive in the
Transcript
Page 1: Cross-browser testing in the real world

Cross-­‐browser

tes*ng

real  world

Mar*n  Kleppmann rapportive

in  the

Page 2: Cross-browser testing in the real world

http://www.flickr.com/photos/stuart_spivack/2322070560/

Page 3: Cross-browser testing in the real world

Cross-­‐browser

tes*ng

real  world

Mar*n  Kleppmann rapportive

in  the

Page 4: Cross-browser testing in the real world

Cross-­‐browser

tes*ng

real  world

Mar*n  Kleppmann rapportive

in  the

Cross-­‐browserurgh

Page 5: Cross-browser testing in the real world

Cross-­‐browser

tes*ng

real  world

Mar*n  Kleppmann rapportive

in  the

Page 6: Cross-browser testing in the real world

Cross-­‐browser

tes*ng

real  world

Mar*n  Kleppmann rapportive

in  the

real  worldmessy

Page 7: Cross-browser testing in the real world

Cross-­‐browser

tes*ng

real  world

Mar*n  Kleppmann rapportive

in  the

Page 8: Cross-browser testing in the real world

Cross-­‐browser

tes*ng

real  world

Mar*n  Kleppmann rapportive

in  thetes*ngwhat?

how?

Page 9: Cross-browser testing in the real world

Tes*ng  what?

Page 10: Cross-browser testing in the real world

Tes*ng  what?

Unit  tes(ng

Applica(on

End-­‐to-­‐end(incl.  external  services)

Page 11: Cross-browser testing in the real world

Tes*ng  why?

Page 12: Cross-browser testing in the real world

Tes*ng  why?Func(onalVisual

PerformanceLoad/Scalability

SecurityUsability

Page 13: Cross-browser testing in the real world

Tes*ng  how?

Page 14: Cross-browser testing in the real world

Tes*ng  how?

Automated(TDD,  BDD,  regression  tests,

smoke  tests,  ...)

Manual(exploratory,  scripted,user-­‐centered,  ...)

Page 15: Cross-browser testing in the real world

Tes*ng  dimensionsUnit Applica(on End-­‐to-­‐end

Func(onal Visual Performance

Load Security Usability

Automated Manual

Page 16: Cross-browser testing in the real world

Tes*ng  dimensionsUnit Applica(on End-­‐to-­‐end

Func(onal Visual Performance

Load Security Usability

Automated Manual

Unit

Func(onal

Security

Automated

Page 17: Cross-browser testing in the real world

Tes*ng  dimensionsUnit Applica(on End-­‐to-­‐end

Func(onal Visual Performance

Load Security Usability

Automated Manual

Unit

Func(onal

Security

Automated

RSpec/Shoulda/whatever

Page 18: Cross-browser testing in the real world

Tes*ng  dimensionsUnit Applica(on End-­‐to-­‐end

Func(onal Visual Performance

Load Security Usability

Automated Manual

Page 19: Cross-browser testing in the real world

Tes*ng  dimensionsUnit Applica(on End-­‐to-­‐end

Func(onal Visual Performance

Load Security Usability

Automated Manual

End-­‐to-­‐end

Manual

Usability

Page 20: Cross-browser testing in the real world

(Side-­‐note)

You  can’t  

write

RSpecs

for  usabil

ity

Page 21: Cross-browser testing in the real world

Tes*ng  dimensionsUnit Applica(on End-­‐to-­‐end

Func(onal Visual Performance

Load Security Usability

Automated Manual

Page 22: Cross-browser testing in the real world

Tes*ng  dimensionsUnit Applica(on End-­‐to-­‐end

Func(onal Visual Performance

Load Security Usability

Automated Manual

End-­‐to-­‐end

Func(onal

Automated

Page 23: Cross-browser testing in the real world

Me

Page 24: Cross-browser testing in the real world

http://www.flickr.com/photos/71263221@N00/4230334515/

Page 25: Cross-browser testing in the real world
Page 26: Cross-browser testing in the real world
Page 27: Cross-browser testing in the real world
Page 28: Cross-browser testing in the real world

P.S.  We’re  hiring!http://www.flickr.com/photos/snake-eyes/410092369/

Page 29: Cross-browser testing in the real world

Anyway.

Page 30: Cross-browser testing in the real world

C++

Page 31: Cross-browser testing in the real world

C++

Page 32: Cross-browser testing in the real world

C++

WebDriver

Page 33: Cross-browser testing in the real world

C++WebDriver

Page 34: Cross-browser testing in the real world

WebDriverWebDriver

Page 35: Cross-browser testing in the real world

WebDriver

Page 36: Cross-browser testing in the real world

WebDriver

Selenium  2

Page 37: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Page 38: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Page 39: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Page 40: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Page 41: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Page 42: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

Page 43: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(r

Page 44: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(r

Page 45: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(r

Page 46: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(rCelerity

HTMLUnit

Culerity

Page 47: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(rCelerity

HTMLUnit

Culerity

Page 48: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(rCelerity

HTMLUnit

CulerityOMGWTFBBQ?!

Page 49: Cross-browser testing in the real world
Page 50: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(rCelerity

HTMLUnit

Culerity

Page 51: Cross-browser testing in the real world

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(rCelerity

HTMLUnit

Culerity

Page 52: Cross-browser testing in the real world

http://www.flickr.com/photos/snake-eyes/449442699/

Page 53: Cross-browser testing in the real world

Celerity

Culerity

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(r

HTMLUnit

Page 54: Cross-browser testing in the real world

Celerity

Culerity

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(r

HTMLUnit

Page 55: Cross-browser testing in the real world

Celerity

Culerity

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(r

HTMLUnit

*Wa(r

Page 56: Cross-browser testing in the real world

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 endend

Page 57: Cross-browser testing in the real world

Celerity

Culerity

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(r

HTMLUnit

Page 58: Cross-browser testing in the real world

Celerity

Culerity

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(r

HTMLUnit

WebDriver

Page 59: Cross-browser testing in the real world

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") endend

Page 60: Cross-browser testing in the real world

Celerity

Culerity

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(r

HTMLUnit

Page 61: Cross-browser testing in the real world

Celerity

Culerity

WebDriver

Selenium  2

Cucumber/RSpec/whatever

Capybara

*Wa(r

HTMLUnit

Capybara

Page 62: Cross-browser testing in the real world

require 'capybara'; require 'capybara/dsl'Capybara.default_driver = :selenium

Spec::Runner.configure do |config| config.include(Capybara, :type => :integration) config.before(:each) { Capybara.reset_sessions! }end

describe 'Google' do it 'should return search results for "hello world"' do visit "http://www.google.co.uk" fill_in "q", :with => "hello world" click "Google Search" page.should have_content( "Hello world program - Wikipedia") endend

Page 63: Cross-browser testing in the real world

# API beauty contest!

goto "http://www.google.co.uk" # Watirnavigate.to "http://www.google.co.uk" # WebDrivervisit "http://www.google.co.uk" # Capybara

text_field(:name, "q").set("hello world") # Watirfind_element(:name, "q").send_keys("hello world") # WDfill_in "q", :with => "hello world" # Capybara

button(:name, "btnG").click # Watirfind_element(:name, "btnG").submit # WebDriverclick "Google Search" # Capybara

# You choose...

Page 64: Cross-browser testing in the real world

Celerity

Culerity

WebDriver

Selenium  2

Capybara

*Wa(r

HTMLUnit

Cucumber

Page 65: Cross-browser testing in the real world
Page 66: Cross-browser testing in the real world

Feature: Looking up a contact In order to understand my contacts better As a Gmail user I want to see social information next to my email thread

Scenario: Load an email conversation Given I am logged into Gmail And Rapportive is loaded When I search for "[email protected]" And I click on the conversation with subject "Testing 1 2 3" Then I should be on a conversation view And Rapportive should show "Co-founder at Rapportive"

Page 67: Cross-browser testing in the real world

Given /^I am logged into Gmail$/ do visit 'https://mail.google.com/a/rapportive.com' fill_in 'Email', :with => 'test' fill_in 'Passwd', :with => GMAIL_TEST_ACCOUNT_PASSWORD click 'Sign in'end

Then /^Rapportive should show "([^\"]*)"$/ do |text_to_show| page.within_frame('canvas_frame') do page.within(:css, '#rapportive-sidebar') do page.should have_content(text_to_show) end endend

Page 68: Cross-browser testing in the real world
Page 69: Cross-browser testing in the real world

Ok.

Page 70: Cross-browser testing in the real world

FEI(Frequently  

Encountered  Issues)

Page 71: Cross-browser testing in the real world

10.  Time  dependence

Page 72: Cross-browser testing in the real world
Page 73: Cross-browser testing in the real world
Page 74: Cross-browser testing in the real world

10.  Time  dependence

‣Modify  date(mes  in  DB  using  models

‣ Create  wrapper  around  Time.now

Page 75: Cross-browser testing in the real world

9.  Real-­‐*me  comms

Page 76: Cross-browser testing in the real world

8.  Managing  test  VMs

Page 77: Cross-browser testing in the real world

8.  Managing  test  VMs

‣ Very  tedious  (updates  etc.)‣ Test  management  infrastructure

‣ Commercial  services  (e.g.  Sauce  Labs,  BrowserMob)

Page 78: Cross-browser testing in the real world

7.  Random  DOM  IDs

Page 79: Cross-browser testing in the real world

7.  Random  DOM  IDs

‣ Ext.js,  GWT,  Cappuccino

‣ Use  toolkit  APIs// Selecting an item in a Ext.js Combo Boxvar combo = Ext.getCmp('countryComboBox');combo.setValue('Germany');// setValue() doesn't trigger the eventcombo.fireEvent('select');

Page 80: Cross-browser testing in the real world

6.  Tes*ng  layout

Page 81: Cross-browser testing in the real world

6.  Tes*ng  layout

‣ Automa(cally  spoWng  broken  layout?  srsly?

‣ Interes(ng  experimenth"p://code.google.com/p/figh/ng-­‐layout-­‐bugs/

Page 82: Cross-browser testing in the real world
Page 83: Cross-browser testing in the real world

$(‘*’).css(‘color’,  ‘white’);

Page 84: Cross-browser testing in the real world
Page 85: Cross-browser testing in the real world

$(‘*’).css(‘color’,  ‘black’);

Page 86: Cross-browser testing in the real world
Page 87: Cross-browser testing in the real world

image1  –  image2  =  ...

Page 88: Cross-browser testing in the real world
Page 89: Cross-browser testing in the real world
Page 90: Cross-browser testing in the real world

5.  Unit  tes*ng  JS

Page 91: Cross-browser testing in the real world

5.  Unit  tes*ng  JS

‣ Command  line  &&  browser

‣ DOM  manipula(on  →  HTML  fixtures    (...and  rollback?)

Page 92: Cross-browser testing in the real world

5.  Unit  tes*ng  JS‣ JSpec

h"p://visionmedia.github.com/jspec/

‣ Blue  Ridge/Screw.Unith"p://github.com/relevance/blue-­‐ridge

‣ JsTestDriverh"p://code.google.com/p/js-­‐test-­‐driver/

Page 93: Cross-browser testing in the real world

4.  Model  layer  access

Page 94: Cross-browser testing in the real world

4.  Model  layer  accessTests

HTTP/Framework

Controllers

Views

Models

Page 95: Cross-browser testing in the real world

Factory/Fixtures?

4.  Model  layer  accessTests

HTTP/Framework

Controllers

Views

Models

Page 96: Cross-browser testing in the real world

4.  Model  layer  access

‣ Violates  abstrac(on‣ BUT:  factories  =  only  sane  way  of  managing  DB  state

Page 97: Cross-browser testing in the real world

Factory.define :user do |u| u.first_name 'John' u.last_name 'Doe' u.admin falseend

Given /^I am on John's profile page$/ do user = Factory.create(:user) visit user_url(user)end

Page 98: Cross-browser testing in the real world

3.  Star*ng  state

Page 99: Cross-browser testing in the real world

3.  Star*ng  state

‣ Previous,  failed  tests‣ Cookies,  browser  cache‣ Unexpected  persistent  state

Page 100: Cross-browser testing in the real world

3.  Star*ng  state‣ Long-­‐running  transac(on  &  rollback(e.g.  Cucumber  per-­‐scenario  transac/on  rollback)

‣ Clean  up  databaseh"p://github.com/bmabey/database_cleaner

Page 101: Cross-browser testing in the real world

2.  Parallel  test  runs

Page 102: Cross-browser testing in the real world

2.  Parallel  test  runs‣ End-­‐to-­‐end  tests  are  SLOW‣ Start  up  several  browsers(TestSwarm,  Selenium  Grid,  ...)

‣ BUT:  concurrent  modifica(on  of  DB  state!

Page 103: Cross-browser testing in the real world

2.  Parallel  test  runs

One  DB  per  test  process‣ h"p://github.com/grosser/parallel_tests

‣ h"p://github.com/qxjit/deep-­‐test

Page 104: Cross-browser testing in the real world

2.  Parallel  test  runsCaveat:  state  outside  of  your  control

‣ e.g.  OAuth  status‣ use  mocks,  or  work  around  it

Page 105: Cross-browser testing in the real world

1.

Page 106: Cross-browser testing in the real world

Fragility

Page 107: Cross-browser testing in the real world

Fragility(tests  break  too  easily,  even  if  the  app  is  ok)

Page 108: Cross-browser testing in the real world

2  schools  of  thought

1. “Disposable”  test  scripts(invest  licle  effort,  use  recording  tools)

2. “Engineered”  test  scripts(use  carefully  designed  abstrac(ons)

Page 109: Cross-browser testing in the real world

Feature: Looking up a contact In order to understand my contacts better As a Gmail user I want to see social information next to my email thread

Scenario: Load an email conversation Given I am logged into Gmail And Rapportive is loaded When I search for "[email protected]" And I click on the conversation with subject "Testing 1 2 3" Then I should be on a conversation view And Rapportive should show "Co-founder at Rapportive"

Page 110: Cross-browser testing in the real world

No  silver  bullet,  obvious  stuff:

‣ Consistent  naming  of  IDs  &  CSS  classes

‣Maintain  &  refactor  your  tests

Fragility

Page 111: Cross-browser testing in the real world

kthxbai

Mar*n  Kleppmannmar*n@rappor*ve.com@mar*nkl rapportive


Recommended