Sunday, November 10, 2013

Performance testing on search form

    Searching is as important to an e-commerce web site as google is to the internet.  With a good, responsive search form, user can quickly find the item/product to purchase or book.

   So how should we do performance testing on search form?  simply sending HTTP POST or GET request with something like "search_block=examples" may not work, since there may be some hidden fields present in the form data like "search_block=examples&cpId=12001&_sessionId=100012". That's because the form may look like
 <form action="blabla">  
 <input type="text" name="search_block"/>  
 <input type="hidden" name="cpId" value="12001"/>  
 <input type="hidden" name="_sessionId" value="100012"/>  

   How to send search request and keep the hidden fields?   With netgend javascript, we can use the function "getFormField".  Here is an example.
 function VUSER() {  
      action(http, "");  
      a = getFormField(http.replyBody);  
      a.search_block.value = "examples";  
      http.POSTData = combineHttpParam(a);  
      action(http, "");  
   In the above, "getFormField(http.replyBody)" will parse the form in the http reply body and produce a compound variable with multiple fields, each field has a name and value (if present) from the form. We will assign a value to the "search_block" field and "combine" the fields in the compound variable "a" and create a string like

   Of course, to make it more effective, we can read a list of query phrases from a csv file. This is covered in previous blogs and will be left as an exercise for the reader.

   In addition to query string, sometimes we need to create a pair of random dates when doing search.  This happens, for example, when we reserve a hotel room or air plane tickets.   It's quite easy with netgend javascript.  Here is an example that shows a random start date is picked between now and 7 days later, an end date date that's 2 days later.

 t = time();  
 t += randNumber(0, 86400 *7);  
 a.startDate = toDate(t);  
 //variable "a" will contain "11/18/2013"
 a.endDate = toDate(t + 86400 * 2);  
 http.POSTData = combineHttpParam(a);
 //http action
    For web site that's particular about format of date, you can easily change it using the optional second parameter of "toDate" function.
 a.startDate = toDate(t, "%Y-%m-%d");  
 //will produce something like 2013-12-16  

    Last thing we cover in this blog is related to "suggestions" in search form. We frequently see some suggestions when we are typing queries.  How did the suggestions get to browser?  Turns out that behind the scene, there are ajax calls to server to fetch suggestions as user types the characters in the text box.

   How do we emulate clients talking to server for suggestions?  It's only a few lines on netgend's javascript.

 query = "computer";  
 for (i = 1; i < length(query); i ++) {  
      partial = substr(query, 0, i);  
      //variable "partial" will contain the first i characters of the query string
  Here we use the variable "partial" to hold progressively more characters in the query string and use it to do transaction with server.

   There are lots of interesting questions on performance testing on search forms, we will cover  them in future blogs.

No comments:

Post a Comment