lr_save_string function in Loadrunner with examples

In this Loadrunner Tutorial, You will learn how to use lr_save_string.

So, are you wondering why and when you need to use lr_save_string function.

Loadrunner has its own set of functions. In order to communicate with the loadrunner you need to use this lr functions.

Suppose if you define a string in C as shown below and you want to use this string inside the loadrunner functions which will not work. in order to make this work, you need to convert C string to loadrunner string or loadrunner parameter. you use lr_save_string to convert c string to loadrunner string

If you declare order no in C and use it in your web function, it will not work, in order to work, you need to convert C string to LR string.

char OrderNo[]=”45789″;

web_url(“OrderNo”, “URL={OrderNo}“, ……., LAST );

We can use this function in two ways mainly.

  1. To Convert a string to loadrunner parameter and we can pass that parameter wherever we require as shown in the following example.
  2. To save one parameter to another parameter.

For example if you want to pass microsoft.com in url, then we are saving url in a parameter called  Application_URL and using wherever required.

Example 1:

/**
 * Insert your code here
 */
 lr_save_string("https://www.microsoft.com", "Application_URL");
    
    lr_start_transaction("MicrosoftHomePage");

    web_url("Microsoft Home Page",
    "URL={Application_URL}",
    "TargetFrame=", 
    "Resource=0",
    "RecContentType=text/html",
    "Snapshot=t91.inf",
    "Mode=HTML",
    LAST );
    
   lr_end_transaction("MicrosoftHomePage", LR_AUTO);

Example 2:

In this parameter I have taken two parameters  Parameter1 and  Parameter2. I am saving Parameter1 to Parameter2.

Follow this process to create the parameter

 Action()
{		
	/*
	Parameter1
	100011
	100012
	100013	
	*/
	
	lr_save_string(lr_eval_string("{Parameter1}"), "Parameter2");
	
	lr_output_message("%s", lr_eval_string("{Parameter2}"))
	
	return 0;
}

Output:

Starting iteration 1.
Maximum number of concurrent connections per server: 6  	[MsgId: MMSG-26989]
Starting action Action.
Action.c(5): Notify: Parameter Substitution: parameter "Parameter1" =  "100011"
Action.c(5): Notify: Saving Parameter "Parameter2 = 100011".
Action.c(7): Notify: Parameter Substitution: parameter "Parameter2" =  "100011"
Action.c(7): 100011
Ending action Action.
Ending iteration 1.
Starting iteration 2.
Notify: Next row for parameter Parameter1 = 2 [table  = Parameter1].
Notify: Getting new value for parameter 'Parameter1': table = 'Parameter1.dat' column = '0' row = '2'.
Starting action Action.
Action.c(5): Notify: Parameter Substitution: parameter "Parameter1" =  "100012"
Action.c(5): Notify: Saving Parameter "Parameter2 = 100012".
Action.c(7): Notify: Parameter Substitution: parameter "Parameter2" =  "100012"
Action.c(7): 100012
Ending action Action.
Ending iteration 2.
Starting iteration 3.
Notify: Next row for parameter Parameter1 = 3 [table  = Parameter1].
Notify: Getting new value for parameter 'Parameter1': table = 'Parameter1.dat' column = '0' row = '3'.
Starting action Action.
Action.c(5): Notify: Parameter Substitution: parameter "Parameter1" =  "100013"
Action.c(5): Notify: Saving Parameter "Parameter2 = 100013".
Action.c(7): Notify: Parameter Substitution: parameter "Parameter2" =  "100013"
Action.c(7): 100013
Ending action Action.

Leave a Comment