Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test...

52
Research Issues in the Automated Testing of Ajax Applications Arie van Deursen Ali Mesbah Delft University of Technology 2

Transcript of Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test...

Page 1: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Research Issues in the Automated Testing of Ajax Applications

Arie van Deursen

Ali Mesbah

Delft University of Technology2

Page 2: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Acknowledgments

• SOFSEM Organizers

– Jan van Leeuwen, Bernhard Rumpe, Roman Špánek

• The Delft Ajax team

– Ali Mesbah

– Frank Groeneveld, Stefan Lenselink, Danny Roest

– Cor-Paul Bezemer, Engin Bozdag

3

Page 3: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Web2SE1st ICSE Workshop on Web 2.0 for

Software Engineering

Cape Town, South Africa, May 4, 2010http://sites.google.com/site/web2se/

Important dates:• Submissions: January 31• Notification: February 17• Camera-ready: March 3• Workshop: May 4

Organizers• Christoph Treude (Victoria)• Margaret-Anny Storey (Victoria)• Kate Ehrlich (IBM)• Arie van Deursen (Delft)

4

Page 4: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Today’s Structure

1. (Testing)

2. Web Applications

3. Crawling Ajax

4. Testing Ajax

5. Implications

5

Page 5: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Why I Love Software Testing (1)

6

Dependabilityin practice

Page 6: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Why I Love Software Testing (2)

7

ResearchChallenges

Page 7: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Why I Love Software Testing (3)

8

SystemUnderstanding

Page 8: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

The Great Move to the Web

9

Page 9: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Collaborative Spreadsheets

10

Page 10: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Web-Based Accounting Software

11

Page 11: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

12

Page 12: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

“Why I’m Done Making Desktop Applications”

• Better conversion

• Easier to support

• The end of piracy

• Interaction analytics

• Customization per user

• Short innovation cycles

13

Patrick Mckenziehttp://www.kalzumeus.com/2009/09/05/desktop-aps-versus-web-apps/

Page 13: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Ajax: AsynchronousJavascript And XML

• Asynchronous server communication through XMLHttpRequest

• Web standards-based (HTML, CSS, XML)

• Dynamic display through DOM

• JavaScript binds everything together

Features:

• No full page refresh!

• Single-page web interface

Page 14: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

A. Mesbah and A. van Deursen. A Component- and Push-based Architectural Style for Ajax Applications. Journal of Systems and Software 81(12):2194-2209, 2008.

An Architectural Style for Ajax

15

Page 15: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Frameworks for Programming Ajax

• Javascript programming

• Using libraries (JQuery)

• Code generators (Google Web Toolkit)

16

<a href="#"

onClick="OpenNewsPage();">

<span onClick="OpenNewsPage();">

<div class="news">

$(".news").click(function() {

$("#content").load("news.php");

});

Page 16: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Fault Prone Ajax

• Stateful client;

• Asynchronous communication;

• Delta updates;

• Untyped JavaScript;

• Client-side DOM manipulation;

• Event handling;

• Timing;

• Back/forward, undo/redo

• Browser dependence(IE, FF, Chrome, …

• Focus on client side GUI logic.• Different fault models / test strategies for

server side / database / business etc. logic 17

Page 17: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

How do you test your web app’s?

• Traditional (classical multi-page): server centric:

– extract link,

– send a request to the server and

– analyze the response. i.e., HTML

• Static analysis

– Will miss complex runtime behavior

• Capture/Replay (e.g., Selenium):

– Demands a substantial amount of manual effort

• Fully automatic dynamic analysis: Would that work?

18

Page 18: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

• In order to detect a fault, a testing method should meet the following conditions: 1. reach the fault-execution:

actually execute faulty statements

2. trigger the error creation:actually generate an incorrect intermediate state

3. propagate the error:enable the incorrect intermediate state to propagate to the output and cause actual failure.

• The oracle problem: how can we verify the output?

What are Key Testing Challenges?

19

Page 19: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

The Plan

• Automatically derive a model of the user interaction

– Create a crawler for Ajax applications

– which generates a state-flow graph

• Use the derived graph for generating test cases

• Use invariants on the DOM tree as oracle

20

Page 20: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

• For Ajax we would need:

– A browser that implements DOM, JS, XmlHttpRequest, CSS, ...

– Access to its internal (runtime) DOM tree

– A way to fire real events on its elements

• Furthermore:

– A way to provide sensible data inputs.

Can we create a “crawler” for Ajax?

Our solution: Crawljax21

Page 21: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

State: DOM TreeEdge: Event that is fired and causes a state transition

22

Page 22: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Detecting Clickables

• Candidate elements:– HTML tagnames: DIV, SPAN, A, …

– attribute constraints: DIV:{class=“menuitem”}

– Excluded elements: A:{title=“logout”}

• Expose each element to real events: (click, mouseover, dbclick, …)

• DOM changed after click? Element clickable; new state.

23

Page 23: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Detecting State Changes

Compare DOM Tree before and after event

Levenshteinedit distance

24

Page 24: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Recurse

• Efficiently find new clickables in next state

– Recognize already processed clickables viaXPath expression, tag name, attributes, children

• Backtrack: can’t use the “Back” button

– Refollow x-path expression.

25

Page 25: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Manage Data Entry Points

• First pass to identify input elements

• Ask engineer to provide example data

• Used on subsequent runs

26

Page 26: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Implementation: Crawljax

• Open source: http://crawljax.com

• Java, maven, JUnit, Apache libraries

• Relies on webdriver to access the browser– IE, Firefox, Chrome

• Plugin-based architecture

• Google TechTalk on

27

Page 27: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

28

Crawljax PluginArchitecture

Page 28: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Example: MirrorGenerator

29

package com.crawljax.plugins;

import java.io.FileWriter;

import com.crawljax.core.CrawlSession;

import com.crawljax.core.plugin.OnNewStatePlugin;

public class MirrorGenerator implements OnNewStatePlugin {

@Override public void onNewState(CrawlSession session) {

try { String dom = session.getBrowser().getDom();

String fileName = session.getCurrentState().getName();

FileWriter fw = new FileWriter(fileName, false);

fw.write(dom);

fw.close();

} catch (Exception e) { e.printStackTrace(); } } }

Page 29: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Atusa: Automated Testing with Crawljax

• Crawling = Testing?

• Provide oracles: pass/fail criterion– Web browser eats all problems

• Leverage state flow graph– Generate JUnit test suite

30

Page 30: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Invariant-Based Oracles

• On the DOM-tree state:

– DOM Validity, Error Messages in DOM, Accessibility,, Security constraints...

• Between DOM states in the graph:

– Consistent Back-Button, No Dead Clickables, ...

• Application-specific (design) invariants

– Constraints on specific element and attribute relations in particular DOM states

implement as Crawljax Plugins31

Page 31: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Ajax Regression Testing

• Apply derived test suite to different versions

• Where are relevant changes?

• Apply special state comparators

• Provide visual inspection

32

Page 32: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Empirical Evaluation

Goal: assess usefulness of approach in supporting testing of modern web applications

RQ1: What is the fault revealing capability of Atusa?

RQ2: How well does Atusa perform and scale?

RQ3: What is the automation level when using Atusa? How much manual effort is involved in the testing process?

33

Page 33: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Case Study I: Tudu

• Ajax-based open source todo list manager

– Used by other researchers as well

• J2EE, 12,000 loc Java/JSP, DWR, Scriptaculous

– Javascript: 11,000 libraries, 580 custom code

34

Page 34: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

35

Page 35: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Tudu Atusa Configuration (I)

• Settings (property file)– URL to deployed site

– Included tag elements: A, DIV

– Excluded elements: A:title=“Log out”

– Depth level: 2

– Similarity treshold 0.89

– Maximum crawling time: 60 minutes

• Wrote preCrawling plugin to log into the web application automatically

36

Page 36: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Tudu Atusa Configuration (II)

• Initial run: find new states and data entry points recursively

• Manually stored sensible custom input values for data entry points in database

• Activated 4 generic plugins:

– DOM Validator, Back button, Error Detector, Test Case Generator

• RQ3: Total configuration time: ~ half an hour

37

Page 37: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Tudu Atusa Application: Effectiveness

RQ1: How to assess effectiveness of test suite?

• Approximation I: line coverage

– Java/Clover, Javascript/JSCoverage

– 73% server side; 75% custom JS; 35% library JS

• Approximation II: finding (10) seeded faults:

– Malformed DOM, oversized values, duplicate todo items, removing all items instead of one, …)

– 8 found; 2 swallowed by JS not affecting DOM

38Total time used by runs (RQ2): 6 minutes

Page 38: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Case Study II: “Coach Your Self”

• Commercial application supporting ~5000 teachers in self-assessment

• Migration of Java applet to Ajax

– Synchronized tree-based TOC navigation

• Use to evaluate manual effort (RQ3) and capability to find faults actually occurred during development process (RQ1).

39

Page 39: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

CYS Case Study

• Two developers, two person weeks

• Ajax solution:

– JQuery + treeview, history-remote, listen plugins

– Custom code: 150 loc JS + CSS + HTML

• Developers were asked to

– Document design decisions using invariants

– Turn invariants into Atusa plugins

40

Page 40: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

CYS Invariants (I)

• Invariants to document external “treeview” plugin for JQuery library

– (Un)folded tree based on class attributes in lists

– Collapsable, hit-area, lastExpandable-hitArea, …

– JS intercepts clicks and re-arranges class attrs as needed

– Constraints: Div-element below li.expandableshould have expandable-hitarea as its class.

– Invariants help to document such design decisions

41

Page 41: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

CYS Invariants (II)

• Invariants for CYS custom code.

• Synchronizing interactive display of table of content with actual content shown

– Invariant I: at most one path labeled as “current”

– Invariant II: current page actually displayed

• Invariants effective in finding faults:

42

Page 42: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Threats to Validity

• External? – Cases representative? PetStore, TaskFreak,

PageFlakes, Exact Widget Framework: Similar findings

– Realistic faults? From TUDU bug tracking system / as actually occurred during development

– W.r.t. scaleability the cases were fairly small

• Internal:– Does Crawljax work properly? Extensive unit testing.

– Still Crawljax relies on many (complex) 3d party libs

• Reliability / repeatability?– Crawljax and tudu case open source

43

Page 43: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Further Applications

44

Page 44: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Further Research Topics

• Scalability

• Parallelization

• Automatic invariant detection

• Combinational testing

• Path seeding

• Process integration

– Relation to other tools & practices

45

Page 45: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Invariants in Practice

• Can key Ajax design decisions be captured in invariants?

• Are developers willing to?

• Which notation should be used?

• Are invariants stable across versions?

• Are invariants effective in fault finding?

• Are application-specific invariants the way to go?

• Can we discover invariants (cf. Daikon?)

46

Page 46: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Running Crawljax in Parallel

Address scaleability:

• Turn into multi-threaded Java app?

• Leverage multi-cores?

• Reformulate as map-reduce?

• How to manage the central state flow graph?

47

Page 47: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Abstraction

• Derived state machines easily explode

• Clever abstraction functions?

• Learn from model checking?

• Fault finding impact?

• Chaining “oracle comparators”

• Calling on you!

48

Page 48: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

49

Input Handling /Combinational Testing

Page 49: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Path Seeding

• Current best practice: capture & replay with Selenium

• Use specific paths as starting points for Crawljax?

– Breadth-first exploration along important use case?

50

Page 50: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Contributions

1. Method for crawling and testing AJAX-based web applications automatically;

2. Series of fault models and invariants that can be automatically checked on any user interface state;

3. Algorithm for deriving a test suite achieving all transitions coverage of the inferred stateflow graph;

4. An open source tool called Crawljax, offering i. generic invariant checking components

ii. a plugin-mechanism to add application-specific state validators and test suite generation;

5. An empirical evaluation via several case studies;

6. An inventory of avenues for further research51

Page 51: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

http://crawljax.com

• Crawljax engine: open source project– Delft, Canada, Japan

• Plugins:– Proprietary application specific– Generic open source

• Great research vehicle: for you as well?

• (Beginning to be ) applied by industry

52

ping me for a demo!

Page 52: Research Issues in the Automated Testing of Ajax Applications · 2010-01-28 · How do you test your web app’s? • Traditional (classical multi-page): server centric: –extract

Further Reading

• Invariant-Based Automatic Testing of Ajax User Interfaces. Ali Mesbah and Arie van Deursen (2009). ICSE'09

• Automated Security Testing of Web Widget Interactions. Cor-Paul Bezemer, Ali Mesbah and Arie van Deursen (2009). ESEC/FSE'09

• Crawling Ajax by Inferring User Interface State Changes. Ali Mesbah, Engin Bozdag and Arie van Deursen (2008). ICWE'08

• Regression Testing Ajax Applications: Coping with DynamismDanny Roest, Ali Mesbah and Arie van Deursen (2010). ICST’10

53

http://crawljax.com

Google Techtalk by Danny Roest on