Upload
dustaxa
View
270
Download
0
Embed Size (px)
Citation preview
Michael Tamm | MOTOR-TALK GmbH
Cleverly Testing WebapplicationsWith WebDriver
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
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
Michael Tamm | MOTOR-TALK GmbH4 / 62
Wherefore Frontend Test?
• Unit Tests• Functional Tests• Acceptance Tests• System Tests
Michael Tamm | MOTOR-TALK GmbH5 / 62
Wherefore WebDriver?
• Cactus• HttpUnit, HtmlUnit• Canoo WebTest• Selenium• Watir, Watij• ...
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
Michael Tamm | MOTOR-TALK GmbH7 / 62
Therefore WebDriver!
• Java-API• Simple Java-API• Support for
– HtmlUnit– Firefox– Internet Explorer– Safari– ...
Michael Tamm | MOTOR-TALK GmbH8 / 62
WebDriver API: Interface WebDriver
Michael Tamm | MOTOR-TALK GmbH9 / 62
Michael Tamm | MOTOR-TALK GmbH10 / 62
WebDriver API: Class By
Michael Tamm | MOTOR-TALK GmbH11 / 62
WebDriver API: Class WebElement
Michael Tamm | MOTOR-TALK GmbH12 / 62
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
Michael Tamm | MOTOR-TALK GmbH14 / 62
Getting Started
• install Ruby & Rake• svn checkout / export
http://webdriver.googlecode.com/svn/trunk• rake install_firefox• rake
Michael Tamm | MOTOR-TALK GmbH15 / 62
Michael Tamm | MOTOR-TALK GmbH16 / 62
Michael Tamm | MOTOR-TALK GmbH17 / 62
Michael Tamm | MOTOR-TALK GmbH18 / 62
Michael Tamm | MOTOR-TALK GmbH19 / 62
Michael Tamm | MOTOR-TALK GmbH20 / 62
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
Michael Tamm | MOTOR-TALK GmbH22 / 62
Example 1: Google Search
Michael Tamm | MOTOR-TALK GmbH23 / 62
Example 2: Google Suggest
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
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!
Michael Tamm | MOTOR-TALK GmbH26 / 62
Example 1: TeamCity
Michael Tamm | MOTOR-TALK GmbH27 / 62
Example 2: Maven
Michael Tamm | MOTOR-TALK GmbH28 / 62
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
Michael Tamm | MOTOR-TALK GmbH30 / 62
Testenvironment: Strategy 2
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 :)
Michael Tamm | MOTOR-TALK GmbH32 / 62
Best Practices
• Make your tests as readable as possible: Add a DSL like abstraction layer ...
Michael Tamm | MOTOR-TALK GmbH33 / 62
Google Search Refactored
Michael Tamm | MOTOR-TALK GmbH34 / 62
Actions
Michael Tamm | MOTOR-TALK GmbH35 / 62
Finders
Michael Tamm | MOTOR-TALK GmbH36 / 62
Matchers
Michael Tamm | MOTOR-TALK GmbH37 / 62
Example 3: Google Image Search
Michael Tamm | MOTOR-TALK GmbH38 / 62
WebDriver LiFT API
Michael Tamm | MOTOR-TALK GmbH39 / 62
Best Practices
• Extract website specific HTML knowledge out of your tests and put it into yourabstraction layer
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?
Michael Tamm | MOTOR-TALK GmbH41 / 62
Michael Tamm | MOTOR-TALK GmbH42 / 62
A MOTOR-TALK Test Class
Michael Tamm | MOTOR-TALK GmbH43 / 62
A MOTOR-TALK Test Class
Michael Tamm | MOTOR-TALK GmbH44 / 62
MOTOR-TALK Specific Actions
Michael Tamm | MOTOR-TALK GmbH45 / 62
A MOTOR-TALK Test Class
Michael Tamm | MOTOR-TALK GmbH46 / 62
MOTOR-TALK Specific Actions
Michael Tamm | MOTOR-TALK GmbH47 / 62
A MOTOR-TALK Test Class
Michael Tamm | MOTOR-TALK GmbH48 / 62
MOTOR-TALK Specific Finders
Michael Tamm | MOTOR-TALK GmbH49 / 62
MOTOR-TALK Specific Finders
Michael Tamm | MOTOR-TALK GmbH50 / 62
MOTOR-TALK Specific Matchers
Michael Tamm | MOTOR-TALK GmbH51 / 62
ContainsHeadline Matcher (1/3)
Michael Tamm | MOTOR-TALK GmbH52 / 62
ContainsHeadline Matcher (2/3)
Michael Tamm | MOTOR-TALK GmbH53 / 62
ContainsHeadline Matcher (3/3)
Michael Tamm | MOTOR-TALK GmbH54 / 62
A MOTOR-TALK Test Class
Michael Tamm | MOTOR-TALK GmbH55 / 62
MOTOR-TALK Specific Finders
Michael Tamm | MOTOR-TALK GmbH56 / 62
MOTOR-TALK Specific Finders
Michael Tamm | MOTOR-TALK GmbH57 / 62
Michael Tamm | MOTOR-TALK GmbH58 / 62
A MOTOR-TALK Test Class
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
Michael Tamm | MOTOR-TALK GmbH60 / 62
The Future
• WebDriver will be part of Selenium 2.0
Michael Tamm | MOTOR-TALK GmbH61 / 62
Questions
? ? ?
Michael Tamm | MOTOR-TALK GmbH62 / 62
Thank You
http://webdriver.googlecode.com/