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.

1 comment:

  1. Great article. Appriciate your work.

    - PerfRunners (www.perfrunners.com)

    ReplyDelete