web_reg_save_param value to char

820 views
Skip to first unread message

JG

unread,
Sep 18, 2015, 8:55:12 AM9/18/15
to LoadRunner
Hello

Trying to find a way to get the value from the result of the web_reg_save_param capture to be converted into a char variable to pass into a block of code for further formatting of the captured value.

The block of code will handle some formatting to the string value and spit out the reformatted string to then pass into my transactions for use.

I have looked into the standard lr functions "lr_eval_string" and "lr_save_string" to return the string for captured parameter value.

Want to pass this into my formatting program like such after the capture:
something like this?:

char strParamValue[] = lr_eval_string("{keyValue}");


this then gets worked on by my formatting program. Is this possible to do?

Thank you in advance for your help.

James Pulley

unread,
Sep 18, 2015, 9:05:23 AM9/18/15
to LoadRunner
strcpy() or sprintf() is what you are looking for to move the contents of your LoadRunner variable into a C variable.   Declarations are important here for either a pointer ( char * ) or a packed array ( char ) as this impacts which functions you use and how you are going to manage your memory.  Watch your memory management.  In the above example, assuming it worked like you are thinking, you would be copying something of size (the LoadRunner parameter) to a C variable of no size.  This is a recipe for memory problems.  See malloc() - don't forget to pair with free() or declare as a packed array of characters, such as char foo[2048]=""; at the beginning of the function.

Sagar Aggarwal

unread,
Sep 18, 2015, 12:18:35 PM9/18/15
to LR-Loa...@googlegroups.com

Hi,

This is impossible to do because in C language you define any variable in the beginning of the script only and how will you get the value in correlation variable in the beginning of the script. You will get the errors. Better use strcpy & lr_save_string

Regards,
Sagar Aggarwal
+917875624650

--
You received this message because you are subscribed to the Google Groups "LoadRunner" group.
To unsubscribe from this group and stop receiving emails from it, send an email to LR-LoadRunne...@googlegroups.com.
To post to this group, send email to LR-Loa...@googlegroups.com.
Visit this group at http://groups.google.com/group/LR-LoadRunner.
To view this discussion on the web visit https://groups.google.com/d/msgid/LR-LoadRunner/9dfaa026-0d2f-4d2e-8076-9f1abc9fa3d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mital Majmundar

unread,
Sep 19, 2015, 11:38:01 AM9/19/15
to LR-Loa...@googlegroups.com

Did you try running it with usual lr functions?
What is the error you are getting with it?

André Luyer

unread,
Sep 19, 2015, 11:38:01 AM9/19/15
to LoadRunner
Use the LoadRunner function lr_eval_string to "get the value from the result of the web_reg_save_param capture to be converted into a char variable".
lr_eval_string automatically allocates (writeable) memory and stores the 'evaluated' LR parameter as a C-string into that memory. The memory is also automatically freed when the iteration ends.
So you can use it like this:
char *strParamValue;
web_reg_save_param(...);
//etc.
strParamValue = lr_eval_string("{keyValue}");

And use strParamValue as you would with any other C-string variable. (Read "C for Dummies" if you don't know how.)
E.g.:
lr_output_message("the captured value is: %s", strParamValue);

Thus there is no need to copy the C-string returned by lr_eval_string into another char array (to be exact: like all functions in C that handle strings, a pointer is returned to the allocated memory). In fact the strcpy function is the cause of many buffer overflow vulnerabilities.
You can now use the C-string like it was initialized as:
char *strParamValue = "the value captured by web_reg_save_param";

C variables must be declared at the start of a compound block, which is typically at the start of a function. But in case of a Vugen script the Action function can be quite long. So it can be useful to create a temporary variable only there where you need it by starting a new compound block. Like this:
web_reg_save_param(...);
//etc.

char *strParamValue = lr_eval_string("{keyValue}");
  lr_output_message("the captured value is: %s", strParamValue);
  // etc...
}
// now strParamValue no longer exists.

To do the opposite, store a C-string into a LR parameter, there are several possibilities. Most likely the lr_param_sprintf function is the one to do the reformatting you want. A list formatting options is listed here: http://www.cplusplus.com/reference/cstdio/printf/

André
Reply all
Reply to author
Forward
0 new messages