Saturday, February 1, 2014

Shortest script to performance-test a HTML form

One of the guiding principles for the NetGend performance test platform is to make complex things easier - so easy that it requires no special knowledge to do complex tasks, such as performance testing on a HTML form.

A HTML form may appear simple to an average online user but it's fairly complicated for us, the performance testers. We have to take care of the hidden fields, be able to parameterize the user-visible fields, create the HTTP query and send it to the URL specified in the action attribute of the form.

As we talked about in earlier blogs, on the other platforms, the tester will have to extract the hidden fields in the HTML form, probably with regular expressions, to construct the HTTP query. On the NetGend platform, a tester just needs to supply the customer-visible fields (their names and values) thanks to our function fillHtmlForm which takes care of the hidden fields automatically. While it's a big improvement over the other platforms but it still requires the tester(s) to find the internal names of the visible fields by looking at the HTML data or using tools such as chrome developer console or firebug. Can we do better?

In this blog, we are going to show how to test a HTML form without having to know the internal names of the user-visible fields. All that a tester needs to provide in the scripts are

The URL for the form

The list of values that a normal user will fill.

The name of a label that helps to identify the form - useful when there are multiple forms.

These information can be obtained without special knowledge of HTML or using any developer tools.

Here is an example of a common registration form that you may find on many web pages.

If you are familiar with the other test platforms and have struggled with regular expressions used to extract hidden values, you may be shocked at how short the following script is!

This script essentially consists of one line, a call to the function quickForm. The first parameter of the function is the URL for the registration form. The second parameter is an array, consisting of a list of items: "John", "Smith", "jsmith@example.com", "abc123" that you would otherwise need to fill in manually if you were a typical online user, the last parameter "First Name:" is used to identify the registration form.

The function does a lot of things internally

It does the HTTP transaction to get the HTML page that contains the form,

It uses the third parameter to identify the right form,

It scans through all the fields in the form, constructing the HTTP query along the way, use the values provided in the parameter,

It uses the URL in the action attribute of the form to make the HTTP request and wait for the server reply.

If you want to check if the server reply is as expected, you can add a line after the function quickForm like

quickForm(....);
if (match(http.replyBody, /welcome/)) {
return 1;
}

If all the above looks easy, image 50,000 such clients performing this action. I am sure the server will get a good workout.

We know that it's not always possible to make any complex tasks simple, when the opportunity does present itself, NetGend will not let it slip by.