Highlighted
Absent Member.. Absent Member..
Absent Member..
282 views

Use a variable in data.ws set in script.

Jump to solution
Hi,
i hope i post this in the right subforum 🙂

I recorded a script in VuGen (9.1) using Winsock.
The server is sending a dynamic number (sort of a session) in hex to the client, and the client returns it as integer.

Therefore a direct 1:1 correlation is not possible.
So what i did was transforming the hex code to an integer in the script, but now i'd need to replace the number recorded in data.ws with the variable i set in the script.

Here's the part of the script:

lrs_receive("socket1", "buf3", LrsLastArg);

tmp = lrs_get_received_buffer("socket1", 141, 8, NULL);
lrs_save_param("socket1", NULL, "myHandle", 141, 8);
lr_output_message ("myHandle: %s", lr_eval_string(""));
lrs_hex_string_to_int(tmp,8,&i);
i=i+256;
lr_output_message ("myInt: %d",i);

So, i'd need to insert 'i' in data.ws:

"AMOS-Handle: 681\r\n"

Instead of '681' i'd need the value of 'i'.

Any guidance how i can do that ?
Tried a few things, but always ended up with an empty value instead of the value of 'i'
0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.

Re: Use a variable in data.ws set in script.

Jump to solution
Looking at your original code it looks like your parameter braces are not the default. What is your setting for Tools->General Options->Parameterization->Parameter Braces?

What happens if you use the parameter like below?

Using it in data.ws:
"AMOS-Handle: \r\n"

View solution in original post

0 Likes
10 Replies
Highlighted
Absent Member.
Absent Member.

Re: Use a variable in data.ws set in script.

Jump to solution
It is my understanding that you can use a parameter by referencing it between curly braces. Can you use the following in your script?

"AMOS-Handle: {myHandle}\r\n"

0 Likes
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: Use a variable in data.ws set in script.

Jump to solution
Hello, thanks for the try, but that didn't work out.

"AMOS-Handle: {i}\r\n" just returns:
AMOS-Handle: {i}\r\n

Trying to merge string and variable together
using "{i}", "+{i}+" or even ".{i}." also didn't work, it's not filling in the value of 'i'.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Use a variable in data.ws set in script.

Jump to solution
Looking at the help file for lrs_save_param you have saved the value in the parameter "myHandle". In order to reference this parameter you must use it withing angle brackets. (I have my delimter set to curly braces)

Try "AMOS-Handle: \r\n" and not i.

If you need to use the value in i you will have to use the lrs_save_param function again to update the parameter with the new value.


LR Help file description or lrs_save_param:

After specifying an active socket and buffer, you specify a parameter name to store the data. Specify an offset to indicate the offset of the data in the buffer, and length of the data.

Once you save the parameter, you can use it in both the script and data file. Substitute all of the appropriate constant values with the parameter. Whenever you reference the parameter, enclose it in angle brackets (or other delimiters defined within VuGen options).
0 Likes
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: Use a variable in data.ws set in script.

Jump to solution
The "problem" is, that myHandle is something like "\x00\x00\x00\x00\x00\x00\x02\xa3" and as i need this turned into an integer, the myHandle will not return what i need.
(At least if i understood it right how lrs_save_param works)

I did the lrs_save_param more or less only for debugging to see which hex value i get.
'i' is the variable i'd need in data.ws.

Yet i haven't found a way to turn a defined variable into a parameter.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Use a variable in data.ws set in script.

Jump to solution
I see.

Try the lr_save_int function:

The lr_save_int function converts an integer to a string and saves the string in a parameter. If the parameter does not exist, it is created.



After you save your variable as a parameter you can use it.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Use a variable in data.ws set in script.

Jump to solution
Did my new suggestion work?
0 Likes
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: Use a variable in data.ws set in script.

Jump to solution
Hello,

had another project stopping me from following this issue.

Well, i tried it out, and again no luck.

I saved the value in the param myAmosHandle:
lr_save_int(i,"myAmosHandle");

Using it in data.ws:
"AMOS-Handle: {myAmosHandle}\r\n"

Actual send buffer - what Loadrunner is sending to the server:
"AMOS-Handle: {myAmosHandle}\r\n"

Instead of replacing {myAmosHandle] with it's value, it actually sends exactly this string to the server ... which of course is of no use ...
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Use a variable in data.ws set in script.

Jump to solution
Looking at your original code it looks like your parameter braces are not the default. What is your setting for Tools->General Options->Parameterization->Parameter Braces?

What happens if you use the parameter like below?

Using it in data.ws:
"AMOS-Handle: \r\n"

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Use a variable in data.ws set in script.

Jump to solution
Just an FYI this worked for me:

int i = 55;
lr_output_message("Variable: %d", i);
lr_save_int(i, "testParam");
lr_output_message("Parameter: %s", lr_eval_string("{testParam}"));
0 Likes
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: Use a variable in data.ws set in script.

Jump to solution
Percy, thank you 1.000 times.

Using lr_save_int to store the variable in a parameter and using the correct brackets did the trick.

It's working now.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.