62
Michael Tamm | MOTOR-TALK GmbH Cleverly Testing Webapplications With WebDriver

WebDriver JAX 2008 Slides

  • Upload
    dustaxa

  • View
    270

  • Download
    0

Embed Size (px)

Citation preview

Page 1: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH

Cleverly Testing WebapplicationsWith WebDriver

Page 2: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH2 / 62

Who am I?

Michael Tamm

till 1999 Dipl.-Ing. (BA) Computer Sciencetill 2007 Programmer & System Architect at aperto AGcurrently System Architect at MOTOR-TALK GmbH

furthermore Writer for c't and iX, JAX-Speaker

Page 3: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH3 / 62

Agenda

• Some General Thoughts About Frontend Tests

• WebDriver Concepts & API• Getting Started• Examples for Simple Tests• Best Practices• Future Prospects

Page 4: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH4 / 62

Wherefore Frontend Test?

• Unit Tests• Functional Tests• Acceptance Tests• System Tests

Page 6: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH6 / 62

Agenda

• Some General Thoughts About Frontend Tests

• WebDriver Concepts & API• Getting Started• Examples for Simple Tests• Best Practices• Future Prospects

Page 7: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH7 / 62

Therefore WebDriver!

• Java-API• Simple Java-API• Support for

– HtmlUnit– Firefox– Internet Explorer– Safari– ...

Page 8: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH8 / 62

WebDriver API: Interface WebDriver

Page 9: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH9 / 62

Page 10: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH10 / 62

WebDriver API: Class By

Page 11: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH11 / 62

WebDriver API: Class WebElement

Page 12: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH12 / 62

Page 13: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH13 / 62

Agenda

• Some General Thoughts About Frontend Tests

• WebDriver Concepts & API• Getting Started• Examples for Simple Tests• Best Practices• Future Prospects

Page 14: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH14 / 62

Getting Started

• install Ruby & Rake• svn checkout / export

http://webdriver.googlecode.com/svn/trunk• rake install_firefox• rake

Page 15: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH15 / 62

Page 16: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH16 / 62

Page 17: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH17 / 62

Page 18: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH18 / 62

Page 19: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH19 / 62

Page 20: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH20 / 62

Page 21: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH21 / 62

Agenda

• Some General Thoughts About Frontend Tests

• WebDriver Concepts & API• Getting Started• Examples for Simple Tests• Best Practices• Future Prospects

Page 22: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH22 / 62

Example 1: Google Search

Page 23: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH23 / 62

Example 2: Google Suggest

Page 24: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH24 / 62

Agenda

• Some General Thoughts About Frontend Tests

• WebDriver Concepts & API• Getting Started• Examples for Simple Tests• Best Practices• Future Prospects

Page 25: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH25 / 62

Best Practice

• Jeffrey Fredrick: „The sooner you learn about a problem the cheaper it is to fix, ...“

• Set up a Continuous Integration Server!• Organize your tests and run fast tests first!

Page 26: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH26 / 62

Example 1: TeamCity

Page 27: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH27 / 62

Example 2: Maven

Page 28: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH28 / 62

Page 29: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH29 / 62

Testenvironment: Strategy 1

• Test sets up DB and starts server– Server runs in the

same VM as the test, e.g. embedded Jetty or Tomcat

– Overhead: Startup time of server and webapp

Page 30: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH30 / 62

Testenvironment: Strategy 2

Page 31: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH31 / 62

Best Practices

• Install the WebDriver Firefox Extensioninto your default Firefox profile anddefine the System property

webdriver.firefox.useExisting=true

• Now you can use Firebug for debugging :)

Page 32: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH32 / 62

Best Practices

• Make your tests as readable as possible: Add a DSL like abstraction layer ...

Page 33: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH33 / 62

Google Search Refactored

Page 34: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH34 / 62

Actions

Page 35: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH35 / 62

Finders

Page 36: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH36 / 62

Matchers

Page 37: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH37 / 62

Example 3: Google Image Search

Page 38: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH38 / 62

WebDriver LiFT API

Page 39: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH39 / 62

Best Practices

• Extract website specific HTML knowledge out of your tests and put it into yourabstraction layer

Page 40: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH40 / 62

Finders / Selectors / Locators

• By.id, By.name, By.linkText, By.xpath• Bad XPATH: //table[5]/tbody/tr/td[2]/div/a/b

– Ugly, unreadable, doesn't convey purpose– Breaks easily if the HTML structure changes

• „Good“ XPATH: //div[@id = 'foo']//a• What if HTML structure changes?

– How can you find out,what was selected before?

Page 41: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH41 / 62

Page 42: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH42 / 62

A MOTOR-TALK Test Class

Page 43: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH43 / 62

A MOTOR-TALK Test Class

Page 44: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH44 / 62

MOTOR-TALK Specific Actions

Page 45: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH45 / 62

A MOTOR-TALK Test Class

Page 46: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH46 / 62

MOTOR-TALK Specific Actions

Page 47: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH47 / 62

A MOTOR-TALK Test Class

Page 48: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH48 / 62

MOTOR-TALK Specific Finders

Page 49: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH49 / 62

MOTOR-TALK Specific Finders

Page 50: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH50 / 62

MOTOR-TALK Specific Matchers

Page 51: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH51 / 62

ContainsHeadline Matcher (1/3)

Page 52: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH52 / 62

ContainsHeadline Matcher (2/3)

Page 53: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH53 / 62

ContainsHeadline Matcher (3/3)

Page 54: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH54 / 62

A MOTOR-TALK Test Class

Page 55: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH55 / 62

MOTOR-TALK Specific Finders

Page 56: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH56 / 62

MOTOR-TALK Specific Finders

Page 57: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH57 / 62

Page 58: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH58 / 62

A MOTOR-TALK Test Class

Page 59: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH59 / 62

Agenda

• Some General Thoughts About Frontend Tests

• WebDriver Concepts & API• Getting Started• Examples for Simple Tests• Best Practices• Future Prospects

Page 60: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH60 / 62

The Future

• WebDriver will be part of Selenium 2.0

Page 61: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH61 / 62

Questions

? ? ?

Page 62: WebDriver JAX 2008 Slides

Michael Tamm | MOTOR-TALK GmbH62 / 62

Thank You

http://webdriver.googlecode.com/