23.03.2013 Views

Agile Performance Testing - Testing Experience

Agile Performance Testing - Testing Experience

Agile Performance Testing - Testing Experience

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

URLs or form data change dynamically, the logic that builds them<br />

needs to be reproduced in the test scripts.<br />

Besides this, it can be necessary to model periodic AJAX calls, for<br />

example to automatically refresh the content of a ticker that<br />

shows the latest news or stock quotes. For a realistic load simulation,<br />

this also needs to be simulated by the load test scripts.<br />

Challenge 4: Client-Side Web Browser Behavior<br />

For correct and realistic load simulations, the load test tool needs<br />

to implement further web browser features. Here are a few examples:<br />

• caching<br />

• CSS handling<br />

• HTTP redirect handling<br />

• parallel and configurable image loading<br />

• cookie handling<br />

Many of these features are supported by load test tools, even if<br />

the tools act on the HTTP level, but not necessarily all of them are<br />

supported adequately. If, for example, the simulated think time<br />

between requests of a certain test case is varied, a low-level test<br />

script might always load the cacheable content in the same way –<br />

either it was recorded with an empty cache and the requests are<br />

fired, or the requests were not recorded and will never be issued.<br />

DOM-Level Scripting<br />

What is the difference between HTTP-level scripting tools and<br />

DOM-level scripting tools? The basic distinction between the levels<br />

is the degree to which the client application is simulated during<br />

the load test. This also affects the following characteristics:<br />

• Representation of data: DOM-level tools use a DOM tree<br />

instead of simple data structures.<br />

• Scripting API: The scripting API of DOM-level tools works on<br />

DOM elements instead of strings.<br />

• Amount and quality of recorded or hard-coded data: There is<br />

much less URL and form data stored with the scripts. Most of<br />

this data is handled dynamically.<br />

DOM-level tools add another layer of functionality on top. Besides<br />

the handling of HTTP, these tools also parse the contained HTML<br />

and CSS responses to build a DOM tree from this information,<br />

similar to a real web browser. The higher-level API enables the<br />

script creator to access elements in the DOM tree using XPath expressions,<br />

or to perform actions or validations on certain DOM<br />

elements. Some tools even incorporate a JavaScript engine that is<br />

able to execute JavaScript code during the load test.<br />

Advantages<br />

DOM-level scripting has a number of advantages:<br />

• Load test scripts become much more stable against changes<br />

in the web application. Instead of storing hard-coded URLs<br />

or data, they operate dynamically on DOM elements like<br />

“the first URL below the element xyz” or “hit the button with<br />

id=xyz”. This is especially important as long as application<br />

development is still ongoing. As a consequence, you can start<br />

scripting earlier.<br />

• Scripting is easier and faster, in particular if advanced script<br />

functionality is desired.<br />

• Validation of result pages is also easier on the DOM level<br />

compared to low-level mechanisms like regular expressions.<br />

For example, checking a certain HTML structure or the content<br />

of an element, like “the third element in the list below<br />

the second H2” can be easily achieved by using an appropriate<br />

XPath to address the desired element.<br />

• Application changes like changed form parameter names<br />

normally do not break the scripts, if the form parameters are<br />

not touched by the script. But, if such a change does break<br />

the script because the script uses the parameter explicitly,<br />

the error is immediately visible since accessing the DOM tree<br />

element will fail. The same is true for almost all kinds of application<br />

changes described above. Results are more reliable,<br />

because there are fewer hidden differences between the<br />

scripts and the real application.<br />

• CSS is applied. Assume there is a CSS change such that a formerly<br />

visible UI element that can submit a URL becomes invisible<br />

now. A low-level script would not notice this change. It<br />

would still fire the old request and might also get a valid response<br />

from the server, in which case the mismatch between<br />

the script and the changed application could easily remain<br />

unnoticed. In contrast, a DOM-level script that tries to use<br />

this UI element would run into an error that is immediately<br />

visible to the tester.<br />

• If the tool supports it, JavaScript can be executed. This avoids<br />

complicated and error-prone re-modeling of JavaScript<br />

behavior in the test scripts. JavaScript support has become<br />

more and more important in recent years with the evolution<br />

of Web 2.0/AJAX applications.<br />

Disadvantages<br />

There is one disadvantage of DOM-level scripting. The additional<br />

functionality needs more CPU and main memory, for instance to<br />

create and handle the DOM tree. Resource usage increases even<br />

more if JavaScript support is activated.<br />

Detailed numbers vary considerably with the specific application<br />

and structure of the load test scripts. Therefore, the following<br />

numbers should be treated with caution. Table 1 shows a rough<br />

comparison, derived from different load testing projects for largescale<br />

web applications. The simulated client think times between<br />

a received response and the next request were relatively short.<br />

Otherwise, significantly more users might have been simulated<br />

per CPU.<br />

Scripting Level Virtual Users per CPU<br />

HTTP Level 100..200<br />

DOM Level 10..30<br />

DOM Level + JavaScript execution 2..10<br />

If you evaluate these numbers, please keep in mind that machines<br />

are becoming ever more powerful and that there are many flexible<br />

and easy-to-use on-demand cloud computing services today,<br />

so that resource usage should not prevent DOM-level scripting.<br />

Conclusion<br />

Avoid hard-coded or recorded URLs, parameter names and parameter<br />

values as far as possible. Handle everything dynamically.<br />

This is what we have learned. One good solution to achieve this<br />

is to do your scripting on the DOM level, not on the HTTP level.<br />

If working on the DOM level and/or JavaScript execution are not<br />

possible for some reason, you always have to make compromises<br />

and accept a number of disadvantages.<br />

We have created and executed web-application load tests for<br />

many years now, in a considerable number of different projects.<br />

Since 2005, we have mainly used our own tool, Xceptance LoadTest<br />

(XLT), which is capable of working on different levels and supports<br />

fine-grained control over options like JavaScript execution.<br />

In our experience, the advantages of working on the DOM level, in<br />

many cases even with JavaScript execution enabled, generally by<br />

far outweigh the disadvantages. Working on the DOM level makes<br />

scripting much easier and faster, the scripts handle many of the<br />

dynamically changing data automatically, and the scripts become<br />

much more stable against typical changes in the web application.<br />

22 The Magazine for Professional Testers www.testingexperience.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!