Re: dynamic input to be chosen from drop down (289 Views)
Reply
Occasional Contributor
Saumi
Posts: 6
Registered: ‎01-09-2013
Message 1 of 3 (308 Views)

dynamic input to be chosen from drop down

Hello Everybody,

 

I have an application where a random value needs to be selected for "Person Responsible" from a drop down. The selected value has 2 values in the script which are related to each other like below:

 

"Name=prop_12345_1356", "Value=333333", ENDITEM, //<called Responsible_ID>
"Name=objnameprop_12345_1356", "Value=XDEGH - Smith, Will", ENDITEM, //<called Responsible_Name>

 

I have captured the list of values using web_reg_save_param() with ORD = ALL and the results are as below:

 

"CorrelatedValue_1 = 111111"

"CorrelatedValue_2 = AAAAAA - LastName1,  FirsName1"

"CorrelatedValue_3 = "],["BBBBBB - LastName2, FirstName2"

"CorrelatedValue_4 = 222222"

"CorrelatedValue_5 = BBBBBB - LastName2, FirstName2"

"CorrelatedValue_6 = "],["CCCCCC - LastName3, FirstName3"

.

.

.

.

.

"CorrelatedValue_348 ="],["ZZZZZZ - LastNameX, FirstNameX"

"CorrelatedValue_349 = 999999

"CorrelatedValue_350 =ZZZZZZ - LastNameX, FirstNameX"

 

I need to randomly select a Responsible_ID and input the corresponding Responsible_Name

e.g. if ordinance of ID is 1, ordinance of corresponding Name is 2

If ordinance of ID is 4, ordinance of corresponding Name is 5

If ordinance of ID is 7, ordinance of corresponding Name is 8

If ordinance of ID is 10, ordinance of corresponding Name is 11

 

Is there any way I can implement this using correlation?

 

P.S. Parameterizing the ID value and Name(with use same line as ID parameter setting) works fine but I was looking for a more dynamic solution since the values in drop down changes often.

 

 

HP Expert
vmanolova
Posts: 536
Registered: ‎05-24-2012
Message 2 of 3 (293 Views)

Re: dynamic input to be chosen from drop down

Hi Saumi,

 

You can find instructions How to randomly select parameters saved by web_reg_save_param in the following document:

http://support.openview.hp.com/selfsolve/document/KM169458

 

Kind regards,

HP Support
If you haven’t tried it yet, come and join us in our entitled forums at Support Customer Forums
If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution and give Kudos to the author for their assistance.
Advisor
randakar
Posts: 15
Registered: ‎11-22-2013
Message 3 of 3 (289 Views)

Re: dynamic input to be chosen from drop down

[ Edited ]


First of all: If you want to make life easier on yourself, change that correlation a bit, so that you capture a single list containing all the relevant data for the chosen person in a single item.

So you get this:

CorrelatedValue_1 = "11111<random_HTML ... more random HTML>AAAAAA - LastName1, FirsName1"
CorrelatedValue_2 = "222222<random_HTML ... more random HTML>BBBBBB - LastName2, FirstName2"
.. etc.

We really don't care for that random HTML in the middle, but saving it probably won't hurt us a lot and it will make this easier since we now only have a single list of items to deal with and all of them look the same.

From there, this is actually an easy problem. I use ylib for this, so I will explain it using those functions, but you can probably get the same effect without it with a little bit of C glue code.

Doing it with y-lib involves these steps:


First, we choose a random element from the correlated values:

y_array_pick_random("CorrelatedValue");

That will save the chosen value in a parameter named "CorrelatedValue".

Second, we split that parameter into it's constituent parts:
y_left("CorrelatedValue", "<RandomHTML", "prop");
y_right("CorrelatedValue", "RandomHTML>", "propobj");

These two functions will basically save the part to the left of your random HTML into the "prop" parameter, and the part to the right of your random HTML into the "propobj" parameter.

Note that the "RandomHTML" thing is basically the right and left boundary of the correlation, just as you would have in a normal web_reg_save_param() call.

 

And that's basically the entire hat trick. Three easy function calls and a bit of smarts when it comes to capturing your input is all it needs.


Documentation for y_left() and y_right() can be found here:
http://randakar.github.io/y-lib/y__string_8c.html#abced95074b83aebcfb1454f15890c2b5
http://randakar.github.io/y-lib/y__string_8c.html#a8fa8cb819a971b562b07cf9ab9c84bba

 

Here is the documentation to y_array_pick_random():
http://randakar.github.io/y-lib/y__param__array_8c.html#a5df2b7be76beae12d6810e49f0f4bb8b


Note that you'll need to put y-lib into your script first. Doing that is easy: Download the files from github (link is in my sig), right-click on extra files, choose "add files to script", and use that to add the ylib files.

Then simply add the following line at the top of vuser_init:

 

#include "y_lib.c"

 

Done.

---
Discover the y-lib loadrunner support library:
https://github.com/randakar/y-lib
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.