Wednesday, November 20, 2013

Splitting string in performance testing made easy

    In previous blogs, we showed Netgend platform can not only emulate a lot more VUsers than Loadrunner, it's also more flexible and easy to work with.   In this blog, we give 2 more examples, all related to string splitting.  Due to lack of support for it in Loadrunner,  there seems to be a lot of such questions asked in various forums.

     The first example is based on Shankar's blog, we need to split a string like the following using delimiter ';' and access various pieces after the split.
    The solution shows that the author has a pretty good background in C programming that many test engineers don't have, here is the proof :-)
  //Loadrunner code snippet from the above blog
 char *value="040;350;07/05/2012";  
 char *temp;  
 temp=(char *)strtok(lr_eval_string("{TokenValue_1}"),";");  
 lr_output_message("the string a = %s",lr_eval_string("{TokenValue1}"));  
 temp=(char *) strtok(NULL,";");  
 lr_output_message("the string b = %s",lr_eval_string("{TokenValue2}"));  
 temp=(char *) strtok(NULL,";");  
 lr_output_message("the string c = %s",lr_eval_string("{TokenValue3}"));  

    Here is how we do it in netgend javascript:
 //assume str contains above mentioned string
 p = splitStr(str, ';');  
    Now the variable "p" will hold all the pieces after the splitting,   p[0] is the first piece, p[1] is the second piece ...
     Much easier, isn't it?  What's more, you can use a variable to index into the pieces
 i = 2;  
 //now p[i] will contain the 3rd piece (indexing is 0 based)  
     Try doing that with Loadrunner :-)

    The other example is a little trickier.  Here we need to split the following string with a variable delimiter:   + or  /
You can image that the Loadrunner solution would be even more complex than the previous example.   With netgend javascript,  it's still fairly easy, thanks to the support for regular expression in the function splitStr().

 //assume str contains above mentioned string
 p = splitStr(str, '&#4[37];');   
   In the above code snippet, the delimiter is a simple regular expression,  it means string "&#4" followed by either  "3" or "7" and then followed by ";".

   There are lots of interesting and challenging tasks related to string manipulation in performance testing, we will show that anyone  with basic programming skills can do them!

No comments:

Post a Comment