Monday, May 19, 2014

in LoadRunner Did you Know?

  • Save the current times tamp in Milli seconds to an LR parameter can be achieved with the function web_save_timestamp_param()
  • web_url() and web_submit_data() are capable of the encoding the form data automatically. But web_custom_request() cannot encode the form data automatically. The encoding can be done by the function web_convert_param()
  • Automation of the windows based web applications (that uses NTLM authentication) uses the web_set_user() function for sending the username and passwords. While replaying the script, it is recommended to use the run time setting Preferences --> Advanced -->WinInet Replay instead of Sockets
  • Reading and writing from the same file can be achieved by Virtual Table Server
  • The function lr_paramarr_random("x") first validates if there is an LR parameter called x_count, if there is no such parameter, it returns an error
  •  The function web_global_verification() works same as the run time setting Content check, except that the global verification can be paused and resumed with the functions web_global_verification_pause() and web_global_verification_resume()

Thursday, May 8, 2014

Variable conversion in LoadRunner

In the last post, I have given an overview on what types of variables are seen in an LR Script and where they should be used.

This article covers on conversion of LR Variables to C Variables and viceversa.  There are three important LR functions used for the conversion. 
We'll  see one at a time.

lr_eval_string()
This function evaluates a load runner variable and returns its value if placed in flower braces. Let us try to understand how it really works.

lr_eval_string("test") returns a string called "test"
lr_eval_string("{test}") - Now this function checks if there is LoadRunner variable called test or not. 
If there is a LoadRunner variable named test and its value is "Welcome". Now the function lr_eval_string("{test}") returns a string "Welcome"

If no LoadRunner variable exists with the name test, then the function lr_eval_string("{test}") returns a string "{test}"

Now let us see two more last example of lr_eval_string() function:

Assumption: There is an LR variable called test whose value is "{Welcome}". There is another LR variable called Welcome whose value is "Performance Testing Online".

lr_eval_string("{test}") - This returns a string "{Welcome}"
lr_eval_string() function does not do nested evaluation

lr_eval_string(lr_eval_string("{test}"))
 = lr_eval_string("{Welcome}");
 = "Performance Testing Online"

LR to C String
Now that you understand the usage of lr_eval_string() function let us see how we can convert an LR Variable to C string variable.

char CStr[100];

to save "Performance Testing Online" into the string variable CStr, the syntax is:

strcpy(CStr, lr_eval_string(lr_eval_string("{test}")));

Please note that an equal symbol (=) cannot be used to assign a value to a string variable. We will have a separate article on why.

So, the conclusion is, to save an LR value to a C string variable, the lr_eval_string() function is used.

Now let us see, how we can convert an LR Parameter to C integer variable
 
let us assume that the LR variable test stores a value of "10".

LR to C Integers
This value should be converted to a string format first using lr_eval_string() function. This function returns a string value. To convert a string value into an integer, we have C function called atoi() read it as A to I (meaning alphabets to Integers)

int Count;

Count = atoi(lr_eval_string("{test}"));

This is how a value in LR variable is saved to a C variable. Though the heading says converting an LR variable to C variable, in fact we are storing the value of an LR variable into a C variable.

Now let us see the otherway i.e. converting a C integer / String to an LR parameter.

we have two functions named lr_save_string() and lr_save_int() to save a string and integer values to an LR parameter respectivily.

C to LR
int i = 256;

lr_save_int(i, "Total"); 

Now Total is an LR variable which stored a value of 256 in it. Inside the web_url() or web_submit_data or web_custom_request it can be used as {Total}

char Text[100] = "Welcome to Performance Testing Online";

lr_save_string(text, "Status");
Now Status is an LR variable which stored the entire string in it. In a web request it should be used as {Status}


I hope this article is informative and helpful.  If you have any questions, please feel free to comment.


Thanks,
Ram N

Sunday, May 4, 2014

Variables in a LoadRunner script

We have already seen the various types of functions in a Web (Http/HTML) script. The language used for the Web based script is "C", which means all the C data types can be used in a LoadRunner script.

In a Web protocol script, the variables are classified into two categories.

  • C variables
  • LR variables

C Variables - Being a procedural language, C expects all the variables to be declared at the beginning of the function/action.
For Example:

int randNum;
char Strbuff[100];
float thinktime;

However, any LR variable does not need any declaration as such. But, the script expects the variable name to be specified in the function.

For example

web_reg_save_param("SessID", "LB=............","RB=", LAST);
in the above statement, we are explicitly saying that SessID is an LR variable to which the dynamic data is to be saved.

Let us look at few other examples on how the LR variables specified in the script.

web_reg_find("Text=SampleText", "SaveCount=txt_Count", LAST);
in the above example, the LR variable that is created is txt_Count.

lr_save_string("SampleData", "x"); /lr_save_int(10, "y")

In the above cases, the string "Sample Data" or the integer 10 is stored to  LR variable called x /y ( created first and then value is stored).

So, the conclusion is C variables are to be declared at the beginning of the script and LR variables need not be.

Now the most important aspect is where to use what type of variables? Where can C variables be used, where can LR variables be used.

Putting it in simple terms, the protocol based functions like web_url()/web_submit_data(), LR variables are to be used with in flower braces for example {x} or {SessID} or {txt_Count}

In the Language specific functions, its obvious that only C variables are to be used. For example

randNum = rand()%Count + 1;
sprintf(buff, "Test_%d", i);
strcpy("Welcome", StrBuff);

LR functions accepts either types of parameters. For example, 

lr_save_int(i, "y") - where i is C variable and Y will become an LR variable.

lr_eval_string("{x}"); - here x is an LR parameter.

I hope this article provides you the basic information on types of variables of an LR Script. The next article explains how to convert these parameters from type to the other.