Sie sind auf Seite 1von 3

November 2009

The DOM, Your Ally for


Testing Web Applications
Reap the fruit of the DOM (Document Object Model) tree,
Valery Raulet explains the relationship and interaction
of your testing tool with the GUI

S
ince the invention of own way of implementing those
the World Wide Web features, but still relying on the
by Tim Berners-Lee in basic building blocks that are
1989, the browser has HTML, JavaScript and CSS.
evolved quite dramatically and it These complex components are
is now capable of running Web usually the ones that make the
applications using a technology tester worry, as the automation
that initially was not meant tool is often unable to correctly
for that purpose. The HTML1 handle them. The automated
language was created for enabling testing tool will usually fail to
researchers to collaborate and understand the essence of the
share information. component and will instead
record low-level interactions such
Web applications have now as clicks here and clicks there.
become so complex and are Not surprisingly though, as these
using a mixture of HTML/XML, components are formed using
JavaScript and CSS2. Web basic building blocks. So, how do
developers need to spend a fair we overcome this challenge?
amount of time learning this Before answering this question,
technology and all the derivatives let’s have a look at the
(jQuery, Ajax, REST to name a architecture of a Web browser.
few) that enable them to develop Figure 1 shows the components
even more powerful applications. of a typical Browser architecture.

To the automation tester, web The elements are:


applications may look like a
normal application with buttons, HTTP Downloader: it is in
checkboxes, edit fields, and all charge of requesting the various
the basic GUI components. documents (HTML page, images,
However, if we look for a richer CSS, JavaScript and any other
interaction with the end-user, documents).
more complex GUI components
appear such as trees, grids, HTML Parser: it processes
menus, windows, etc. This rich the received HTML documents
set of features often referred as and generates the DOM, a tree
Web 2.0 is not “standardized” representation of the HTML
and everyone comes up with their document.

www.macrotesting.com 21
November 2009 Technical Corner - Document Object Model (DOM)

JavaScript interpreter: it in order to generate Firefox, Internet Explorer, Opera,


interprets the JavaScript code changes in the DOM Safari, and al.) is partly due to
either downloaded separately (.js (dynamic behaviour of the the way this DOM representation
files) or inline (<script> tag). application). The changes is generated.
are reflected in the DOM
DOM: a tree representation of which are reflected on the Any testing tool that seriously
the displayed page. screen, and so on. supports Web applications must
have a means of accessing the
Rendering Engine: the engine As you can see, the DOM plays DOM giving the tester more
in charge of reading the DOM a central role in the Browser freedom. This functionality can
tree and generating a graphic architecture. It is actually the be used to:
representation of it. cornerstone of a browser and (a) Access some DOM objects
the differences you see between that carry information not visible
various browsers (Chrome, on the screen.

A typical flow
consists of the
following steps:
1. A user types a URL which
triggers the download of a
main HTML page and all the
related resources.

2. The HTML parser processes


the HTML code and
generates the static part of
the DOM tree.

3. The downloaded JavaScript


documents and the script
enclosed in the script tag are
parsed. Their code modifies
the DOM tree.

4. The DOM represents the


Web page to be displayed
and each node is a piece of
graphical information with
its own data (type, location,
style).

5. The rendering engine


processes the DOM and
generates the graphical
representation that the user
sees in the browser.

6. The user interactions (mouse


and keyboard) generate
events that are sent to
the JavaScript interpreter

22 www.macrotesting.com
Technical Corner - Document Object Model (DOM) November 2009

(b) Allow more complex Page(“Page”).Object.all. This usually requires a strong


interactions using the structure of tags(“INPUT”)(0).outerHTML knowledge of the Web technology
the data in the DOM. (JavaScript, DOM, and HTML)
To go one step further, if your and also the language used to
(c) Interact with the DOM to
testing tool supports extensibility create these extensions.
perform actions not available to
for the Web, you can amend the
carry out with the testing tool;
behaviour of the tool in order Thanks to the DOM, you now
(d) Carry out any manipulation to automatically recognize your no longer have any limitations to
that JavaScript can do. complex GUI objects. your testing capability!
For instance, Borland SilkTest
and HP QuickTest Professional,
the two major functional testing FURTHER READING:
tools available on the market
allow this type of interaction. Internet Explorer HTML and DHTML Reference
QuickTest Professional has a http://msdn.microsoft.com/en-us/library/ms533050(VS.85).aspx
property Object that gives access
to the corresponding DOM object Mozilla Firefox Gecko DOM Reference
whereas SilkTest has a method https://developer.mozilla.org/en/Gecko_DOM_Reference
ExecMethod() that provides this
access. See both examples below:
Borland SilkTest Valery Raulet
Print(Browser.ExecMethod(“all.
Exposit Ltd
tags(“”INPUT””)(0).
outerHTML”) Director, Senior Consultant
HP QuickTest Professional www.exposit.co.uk
Print Browser(“Browser”).

www.macrotesting.com 23

Das könnte Ihnen auch gefallen