why your se tests are so dang brittle… …and what to do about it patrick wilson-welsh dawn cannan

45
Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Post on 21-Dec-2015

219 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Why Your Se Tests are So Dang Brittle…

…and what to do about it

Patrick Wilson-WelshDawn Cannan

Page 2: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Introduction

Patrick WelshSenior Agile ConsultantPillar Technology Grouphttp://[email protected]://patrickwilsonwelsh.comhttp://coderetreat.ning.com/

mobile: 248 565 6130twitter: patrickwelsh

Page 3: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Prerequisites

You’ll need to know some stuff.

To follow, you’ll need to know Selenium, Java, xpath, css, HTML,

and a bit of Object Oriented Design.

And, I will be gentle.

Page 4: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

We’re here to help …

Page 5: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

How hard is it to regression test an entire enterprise web app using any web-app-

GUI-black-box testing tool?

Page 6: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

too hard: avoid

Page 7: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Number #1 Reason Selenium RC, through the web app GUI tests are so brittle?

Page 8: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Because you are writing too many of them.

Let me put that another way.

Page 9: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

You are committing too high a percentage of total test-automation and programming resources to

that specific kind of automated testing.

Have a plan for outgrowing that pattern.Actually, have a fairy tale:

Page 10: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Driving on the ice in Michigan.

Avoid it whenever you can.

Know how to do it well.

Page 11: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

3 kinds of automated tests

Page 12: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

GUI

end-2-end, integration,

story, acceptance

unit/micro/isolation

Page 13: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

TCO

% of automated testing work

Page 14: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

good: least

investment/ROI

good: most

investment/ROI

Page 15: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

least rework & waste; lowest TCO

Page 16: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

But that’s not your triangle, yet.

Page 17: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

we often start here

Page 18: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

for good reason!

good: easy to learn

bad: hard to learn

Page 19: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

But again, the price

bad: high TCO, low ROI

good: low TCO, high ROI

Page 20: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

So, you’re stuck with more Se testing than you should be doing. That’s ok. So am I.

Page 21: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

How can we minimize the brittleness of these inherently brittle tests?

Page 22: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Following are things that help me and my teams.

Page 23: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Don’t tell me testing is “not your job”

Page 24: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Don’t say programming is “not your job”

Page 25: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Automated testing is everybody’s job, because the Definition of Done is

everybody’s job.

Se tests are written by testers and programmers together. Period.

The whole team shares sufficient testing as part of Definition of Done.

Page 26: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Some issues in Java Selenium RC testing: Mixed abstraction layer logic (test + biz domain + testing framework + …)

Obscure page-flow and page verification.

Verifying state across multiple pages.

DefaultSelenium (et al) access control.

Dynamic HTML/Ajax

Page 27: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Example 1: Bad-Ole Se RC Multi-Page-Flow

Procedural code for verifying that the same links show up on each of several pages.

Even method extraction and custom assertions may not help as much as you need.

Page 28: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Se-Specific, General Guidelines : Only use Se as last resort; play to its strengths

Don’t use Se IDE except for prototyping

Hand-roll Object-Oriented Se RC tests

Separate framework code & test code

Page 29: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

A principle to consider for Se testing:

DRY test framework; “wet” test code.

Page 30: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

src source folder: DRY reusability

src folder contains only reusable domain-specific and domain-independent classes.

Domain-specific pages, panes, and common components (nav menus, etc).

Domain-independent framework (page elements/controls, Selenium and jQuery façade/decorator, locator strategy code)

Page 31: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

test source folder: one-off, wet test code

test folder contains behaviorally-organized test scenarios. Nearly all of them happy paths.

Test scenarios for page flow manipulation and state verification can include quite a bit of duplication. If you prefer, extract private helper methods like “loginAndNavigateToSuchAndSuchPage()”

Page 32: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Specific Patterns in the selenium-rc-patterns eclipse project.

Page 33: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Pattern: Reusable Element Objects Framework

• Different kinds of page elements get matching classes; all extend BaseElement.

• All are completely generic; unrelated to biz domain.

Page 34: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Pattern: Reusable Selenium Singleton Facade

• All access to DefaultSelenium and SeleniumServer (jetty proxy) are outside test code.

• All access to them is via singleton inside façade

• Façade decorates DefaultSelenium with other cool stuff you need

Page 35: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Pattern: Self-Verifying, Lazy-Load Page Objects

• Biz-domain-specific classes wrap the behavior of specific pages in your app, in page-specific ways.

• When you navigate to a page by clicking on a link, the matching page object gets launched, and waits until it is fully loaded by that object’s definition (a css locator).

Page 36: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Pattern: Elements that are Page Object Factories

• When you instantiate a DhtmlLink class, you parameterize it with the PageObject.class that you want to be launched when you click on that link.

• This pushes page flow semantics deep into the actual link flow, emulating actual app, and keeps page flow DRY.

Page 37: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Remember the good old days of every browser-resident change resulting from an

HTTP Response to an HTTP Request? (Sigh.)

Well kiss em goodbye. We live in a dynamic, RIA world now. Ajax. Etc.

Whole desktops, coming to browsers near you… except, differently!

Page 38: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Principles to consider for testing dynamic stuff: The rendered HTML is less and less your friend.

XPATH is not standard, thus not your friend.

The in-memory DOM is your friend.

CSS element location strategy is your friend. jQuery is your friend.

Page 39: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Pattern: CSS Element locator strategies for DHTML/Ajax

• Use id or name attributes if you got ‘em • Use css as a second-resort locator• Only use xpath as a last-resort element locator• Actually, forget it. Never use xpath.

Page 40: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Pattern: Using jQuery to Verify Dynamic Visibility

• Consider usingSe to inject jQuery (or some such js library) into a page, to get direct access to the DOM, not the rendered HTML, when you need

• There will increasingly be behaviors for which jQuery, being cross-browser in a fairly standard way, is a better choice for DOM state verification than older techniques

• jQuery support: coming to a Selenium near you?

Page 41: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Pattern: Common Page Element Singletons

• If all pages in an app have certain common elements, consider hanging a static singleton off a BasePage object.

Page 42: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Pattern: Multi-Page Rule Verification

• A MultiPageTraverser is instantiated with a rule that implements a Verifiable interface.

• Verifiable.verify() call on each page does the right thing.

Page 43: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Get this book...

Page 44: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

…and this book.

Page 45: Why Your Se Tests are So Dang Brittle… …and what to do about it Patrick Wilson-Welsh Dawn Cannan

Q/A