spa 2009 - acceptance testing ajax web applications through the gui

70
Testing Ajax Applications SPA 2009 © 2009 CAPLIN SYSTEMS

Upload: andrewmacleod

Post on 10-May-2015

1.245 views

Category:

Technology


5 download

DESCRIPTION

These are the slides that Andrew MacLeod and Patrick Myles presented at the SPA conference in London, April 2009 http://www.spaconference.org/spa2009/sessions/session219.html

TRANSCRIPT

Page 1: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

© 2 0 0 9 C A P L I N S Y S T E M S

Testing Ajax ApplicationsSPA 2009

Page 2: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

2© 2 0 0 9 C A P L I N S Y S T E M S

INTRODUCTIONS

Testing AJAX Applications

Page 3: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

3© 2 0 0 9 C A P L I N S Y S T E M S

Who we are

Patrick MylesHead of Engineering, Caplin Systems

Andrew MacLeodJavaScript Architect, Caplin Systems

Page 4: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

4© 2 0 0 9 C A P L I N S Y S T E M S

How this talk came about

We have a big Ajax application We use Agile We needed a way to test each release

This is the overview we wish

we’d had 2 years ago

Page 5: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

5© 2 0 0 9 C A P L I N S Y S T E M S

This is not a Selenium HOWTO

Just enough Selenium to: understand the grammar promote a discussion on frameworks see how good Selenium is!

Not enough Selenium to: lose non-programmers (e.g. QA engineers) get bogged down in Selenium nuts-and-bolts see how frustrating Selenium is!

Page 6: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

6© 2 0 0 9 C A P L I N S Y S T E M S

Frustration

Browsers were never designed as

platforms for automated tests...

...so browser test tools are a hack!

Page 7: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

7© 2 0 0 9 C A P L I N S Y S T E M S

We would like you to leave with...

Confidence automated testing hands-on experience

Ideas designing tests tool selection building a framework planning a test programme

Page 8: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

8© 2 0 0 9 C A P L I N S Y S T E M S

THE PROBLEM

Testing AJAX Applications

Page 9: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

The Problem

How can we ensure that each release of our application works everywhere?

Page 10: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

10© 2 0 0 9 C A P L I N S Y S T E M S

Manual Testing

Repeat for each new feature Repeat for all supported platforms

BrowserApplication

DO

M

Tester(acting as the User)

TestPack

.

Page 11: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

11© 2 0 0 9 C A P L I N S Y S T E M S

Automated Testing

Robot(acting as the User)

BrowserApplication

DO

MTestScript

How intelligent is the robot? How human readable is the script? How much effort does the robot consume? .

Page 12: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

12© 2 0 0 9 C A P L I N S Y S T E M S

DOM browser control

COM browser control

Screen coordinates

TestFramework

Behaviour DrivenDevelopment

Domain SpecificLanguage (DSL)

Tools

FIT

TestNG

Watir

WebDriverMercury

Selenium

Windmill

LoadRunnerAuto-Hotkey

WindowLicker

Cucumber

rspec

hamcrest

WebTest

JSUnit

Fitnesse

HttpUnit

Page 13: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

13© 2 0 0 9 C A P L I N S Y S T E M S

Workshop

Why are browser applications

so difficult to test?

Page 14: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

14© 2 0 0 9 C A P L I N S Y S T E M S

CAPLIN: 5 MINUTE CASE STUDY

Testing AJAX Applications

Page 15: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

Caplin Trader

Quick demonstration

Page 16: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

16© 2 0 0 9 C A P L I N S Y S T E M S

200920082007

Caplin’s Timeline

VM F

arm

Auto

Hot

-Key

Web

Driver

Fire

fox

1.5

IE6/

FF2

x ht

tps

IE6,

FF2

IE6/

FF2

x ht

tps

IE7,

IE8

Smoke Test (continuous integration)

Selenium Framework v1

Performance Tests

Functional Tests (nightly)

Qua

lity

Gat

e

Selenium Framework v2

Development

QA

Reference Implementation

Bespoke Implementations (up to 3 in parallel)

Sco

pe

Ap

ps

Au

tho

rs

Fra

mew

ork

Page 17: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

Our first test...

Page 18: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

... a more recent test

goal: Use product finder portletdo Login (${username}=”user1", ${password}="tester")do CreateNewLayoutdo Insert (${portlet}=“Product Finder”)do AssertPortletPresent (${portlet}=“Product Finder”)do Logout

Page 19: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

19© 2 0 0 9 C A P L I N S Y S T E M S

EXERCISE 1:SELENIUM IDE: SEND AN EMAIL

Testing AJAX Applications

Page 20: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

Objective

To get familiar with the Selenium IDE To produce a simple test script To review the script afterwards Experience some Ajax testing pitfalls

Page 21: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

Schema

record

playback

interact

Page 22: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

22© 2 0 0 9 C A P L I N S Y S T E M S

User Story

“As a user,I want to send an e-mail messageso that I can stay in touch with my friend”

Page 23: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

23© 2 0 0 9 C A P L I N S Y S T E M S

Golden Rule

Put yourself in the user’s position

write the test first watch it fail fix it

Page 24: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

24© 2 0 0 9 C A P L I N S Y S T E M S

Tools: Firefox Add-ons

Firefox Selenium IDE easy authoring tool

Firebug debugger reverse engineering tool

XPather locates UI elements

Page 25: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

25© 2 0 0 9 C A P L I N S Y S T E M S

Demo

Open Firefox IDE Record Save Playback

Page 26: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

26© 2 0 0 9 C A P L I N S Y S T E M S

Setup… Disconnect from LAN Connect to CaplinSpa2009 wireless

network Plug USB key Open Firefox + Selenium IDE (set ?:\Examples\user-extensions.js) Navigate to http://spa2009.com/webmail

Page 27: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

27© 2 0 0 9 C A P L I N S Y S T E M S

Your Turn… Login:

user: spa1 password: caplin2009

Send mail To: [email protected] Insert appropriate actions:

pause waitForElementPresent waitForEditable

Save in /Exercise1-Basic/

Page 28: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

28© 2 0 0 9 C A P L I N S Y S T E M S

Selenium IDE Review

Pros easy to set up easy to write easy to run little Selenium knowledge

required generates code!

Cons no explicit verification locators are unintelligible brittle unstructured desktop orientated feature must exist

Page 29: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

29© 2 0 0 9 C A P L I N S Y S T E M S

SELENIUM: 5 MINUTE TUTORIAL

Testing AJAX Applications

Page 30: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

30© 2 0 0 9 C A P L I N S Y S T E M S

Selenium Test Script

One stepper line...

action thing to act on

optionalargument

Page 31: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

Actions

SeleniumSelenium.prototype.doType(sInputLocator, sInputText)Selenium.prototype.doClick(sLocator)

Custom FrameworkSelenium.prototype.doClickControl(sLocator)

31© 2 0 0 9 C A P L I N S Y S T E M S

Page 32: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

Locators

Seleniumxpath

id

link

...

Custom Framework

PageBot.prototype.locateElementByMenuBarItem(sLocatorText, oDocument)

32© 2 0 0 9 C A P L I N S Y S T E M S

Page 33: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

33© 2 0 0 9 C A P L I N S Y S T E M S

Accessors

Selenium

Selenium.prototype.isElementPresent(sLocator)

Custom

Selenium.prototype.getMessageCount(sLocator)

waitForstoreassertverify

ElementPresent

waitForstoreassertverify

MessageCount

Page 34: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

34© 2 0 0 9 C A P L I N S Y S T E M S

SCRIPTS:INTERPRETERS AND RUNNERS

Testing AJAX Applications

Page 35: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

35© 2 0 0 9 C A P L I N S Y S T E M S

Script: Machine vs. Human readable

Pianola(acting as pianist)

Piano Roll

Page 36: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

36© 2 0 0 9 C A P L I N S Y S T E M S

After the break...

BrowserApplication

DOM

LinguisticConstructs

ApplicationAbstractions

COMRunner

SourceCode

Interpreter

• structure• functions• control flow

• locatorstrategies

• applicationoperations

• statetransitions

compiler

Page 37: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

37© 2 0 0 9 C A P L I N S Y S T E M S

COFFEE BREAK (10 MINUTES)

Testing AJAX Applications

Page 38: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

38© 2 0 0 9 C A P L I N S Y S T E M S

Design PrinciplesTesting Ajax applications

Page 39: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

39© 2 0 0 9 C A P L I N S Y S T E M S

Design Principles

Domain Hierarchies how to make my tests more readable? modeling vs. maintainability? how can I isolate application changes?

Test structure and composition how do I avoid duplication? how do my tests map to my requirements? how can I make my framework scalable?

Page 40: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

40© 2 0 0 9 C A P L I N S Y S T E M S

DOMAIN HIERARCHIES

Testing AJAX Applications

Page 41: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

41© 2 0 0 9 C A P L I N S Y S T E M S

System Domain(OO language, may model business domain)

Browser Domain(DOM, text nodes, clicks, etc.)

?

Verification Domain(Locate, input, verify, etc.)

Application

Test tool

Test framework

Page 42: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

42© 2 0 0 9 C A P L I N S Y S T E M S

What to use for framework domain?

1. Don’t bother! ...

Page 43: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

43© 2 0 0 9 C A P L I N S Y S T E M S

System Domain(OO language, may model business domain)

Browser Domain(DOM, text nodes, clicks, etc.)

Verification Domain(Locate, input, verify, etc.)

Application

Test tool

Test framework

?Test framework

Page 44: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

44© 2 0 0 9 C A P L I N S Y S T E M S

1. Don’t bother...Quick to get going

Can use off-the-shelf tools (e.g. Selenium IDE)

Lots of duplication in tests

Maintenance nightmare

Brittle tests

Rapidly become hard to read and author

What to use for framework domain?

Page 45: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

45© 2 0 0 9 C A P L I N S Y S T E M S

What to use for framework domain?

2. Mirror of system domain...

Page 46: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

46© 2 0 0 9 C A P L I N S Y S T E M S

??

System Domain(OO language, may model business domain)

Browser Domain(DOM, text nodes, clicks, etc.)

Verification Domain(Locate, input, verify, etc.)

Application

Test tool

Test framework

System Domain (again)

Browser Domain(DOM, text nodes, clicks, etc.)

Verification Domain(Locate, input, verify, etc.)

Page 47: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

47© 2 0 0 9 C A P L I N S Y S T E M S

2. Mirror of system domain...Usually in same language as System

Seems attractive – particularly if System is well modelled on problem domain

Can “share” domain objects

Often ends up with either tight coupling...

...or duplicated code / abstractions on both sides of the Browser/Verification divide

Using same language as System doesn’t reinforce the domain separation

What to use for framework domain?

Page 48: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

48© 2 0 0 9 C A P L I N S Y S T E M S

What to use for framework domain?

3. Model or DSL that reinforces user’s interactions and use-cases...

Page 49: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

49© 2 0 0 9 C A P L I N S Y S T E M S

?Business (User) Domain / DSL(Inbox, compose, check mail, logout, etc.)

System Domain(OO language, may model business domain)

Browser Domain(DOM, text nodes, clicks, etc.)

Verification Domain(Locate, input, verify, etc.)

Application

Test tool

Test framework

Page 50: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

50© 2 0 0 9 C A P L I N S Y S T E M S

3. Model or DSL that reinforces user’s interactions and use-cases...

Easier to understand for non-programmers

Less brittle when underlying domains change

More natural abstractions

Requires more maintenance of different abstractions

Can make it hard to implement complex interactions

What to use for framework domain?

Page 51: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

51© 2 0 0 9 C A P L I N S Y S T E M S

EXERCISE 2: USING A FRAMEWORK

Testing AJAX Applications

Page 52: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

52© 2 0 0 9 C A P L I N S Y S T E M S

Objectives

Move test script closer to application domain Introduce logical names for screen controls Remove physical references to screen controls

Show Selenium extensions Make tests more readable

Page 53: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

53© 2 0 0 9 C A P L I N S Y S T E M S

Selenium Framework

BrowserApplication

DOM

ApplicationAbstractions

COMRunner

SourceCode

Interpreter

• actions

• locators

Page 54: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

54© 2 0 0 9 C A P L I N S Y S T E M S

Exercise 2 - Framework

Demo

Page 55: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

55© 2 0 0 9 C A P L I N S Y S T E M S

UCD TEST STRUCTURE

Testing AJAX Applications

Page 56: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

56© 2 0 0 9 C A P L I N S Y S T E M S

User Centered Design (UCD)

A powerful way to model and design a system

Like Agile, focuses on Users – their needs and goals

Typically used for UI/UX design, but provides great models for test frameworks

We use with a simple text DSL

Page 57: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

57© 2 0 0 9 C A P L I N S Y S T E M S

User Centered Design (UCD)

Brings focus back to users and their Goals Tasks

• Actions

Fits well with user story structure:

As a [type of user]

I want to [a task or sequence of tasks]

so that I can [achieve some goal]

Page 58: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

58© 2 0 0 9 C A P L I N S Y S T E M S

Use-Cases and UCD

Goal

Task

Action

UCD concepts map well to use-case levels

Page 59: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

59© 2 0 0 9 C A P L I N S Y S T E M S

Story Structure

Send Email Login Action

Action

Send Message Action

Action

Action

Logout Action

Action

Goal Tasks Actions

Page 60: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

60© 2 0 0 9 C A P L I N S Y S T E M S

EXERCISE 3:RUNNING A UCD TEST

Testing AJAX Applications

Page 61: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

61© 2 0 0 9 C A P L I N S Y S T E M S

Objectives

Demonstrate UCD structure Show task re-use Implement a new task

Page 62: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

62© 2 0 0 9 C A P L I N S Y S T E M S

Old Structure

Test Action

Action

Action

Action

Action

Action

Action

Action

Page 63: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

63© 2 0 0 9 C A P L I N S Y S T E M S

UCD Structure

Goal Task Action

Action

Task Action

Action

Action

Task Action

Action

Page 64: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

64© 2 0 0 9 C A P L I N S Y S T E M S

Demonstration

Goal/Task/Action hierarchy Task level convenient for

Reuse Maintenance Communication

Action level too small to be reusable

Page 65: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

65© 2 0 0 9 C A P L I N S Y S T E M S

UCD Structure

Send Email Login Action

Action

Send Message Action

Action

Action

Logout Action

Action

Verify Sent Action

Action

Page 66: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

66© 2 0 0 9 C A P L I N S Y S T E M S

A new story…

“As a user,I want to receive an emailso that I can prove I have a friend!”

Page 67: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

67© 2 0 0 9 C A P L I N S Y S T E M S

Your Turn...

Receive Email Login Action

Action

Logout Action

Action

Verify Inbox non-empty

Action

Action

Page 68: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

68© 2 0 0 9 C A P L I N S Y S T E M S

SUMMARY

Testing AJAX Applications

Page 69: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

Summary

Selenium is not a perfect testing tool, but… Selenium extensions are effective

actions locators accessors

UCD is a good way to structure test cases goals tasks actions

Page 70: SPA 2009 - Acceptance Testing AJAX Web Applications through the GUI

Taking things forward…

-- goal: use product finder portletdo Login (${username}=”user1", ${password}="tester")do CreateNewLayoutdo Insert (${portlet}=“Product Finder”)do AssertPortletPresent (${portlet}=“Product Finder”)do Logout

Develop a simple DSL for testers to use invoke tasks with parameters get rid of ugly HTML “Selenese” use a PATH mechanism to locate tasks