Q101: How to use variables in Web Performance Test, Round 2
-
Thursday, March 08, 2012 3:46 PM
Hi,
This is a follow up question for
Q101: How to use variables in Web Performance Test
still regarding using the variables in Web Performance Test. Very simple,
Q1: How can I use the results from the extraction rules?
E.g., say I've done adding an Extraction Rule to a Web Performance Test
and I can verify that
"Click the Context tab.
A grid of names and values is displayed. The last entry will be the value extracted by the rule, color:Blue;"
Now, how can use the variable?
In other words, I've gone through the Web Performance Test Walkthroughs, but still don't know how to do the data correlation, and url parameterization, etc that sort of thing in MS Web Performance Test, and need pointers for further reading.
Q2: Supposed I have created a Web Performance Test Plug-In, and now have a variable testIterationNumber handy to be used. Now I'd like to append the value of variable to each data binding fields, how can I do that? I.e., for each data binding fields that I originally supplied with {{DataSource1.TableX.FieldN}}, now I want append the value of testIterationNumber to them. How can I do that?
Sorry to ask newbie questions like that, I did my homework but didn't find them in the walk-though. So I need your help.
Thanks a lot!
All Replies
-
Thursday, March 08, 2012 4:06 PM
Try this: http://msdn.microsoft.com/en-us/library/ff357728.aspx or page 3 of this article might be helpful:
If you need to continue to search on the subject search for
vs 2010 + "Context Parameter"
- you will get some good hits
Tim
- Marked As Answer by smetah Friday, March 09, 2012 4:52 PM
-
Thursday, March 08, 2012 5:53 PM
Thank you very much Tim.
Very valuable information.
This definitely answers my question, but please allow me to "leave it open" for an extra while to see if anyone else has some more inputs.
Thank !
-
Thursday, March 08, 2012 6:12 PM
Also, if anyone can answer my specific question, Q2 please?
Thanks
-
Thursday, March 08, 2012 9:14 PM
Hi Smetah,
Here is a WebTestPlugin that does what your asking, it appends the value of one context parameter to another, so in your case you can use the built in "$WebTestIteration" context param as a source value that you append to some value in your data source.
public class AppendValueToContextParameter : WebTestPlugin { //DataSource1.SomeDataFile#csv.FieldName [System.ComponentModel.DefaultValue("DataSource1.SomeDataFile#csv.FieldName")] [System.ComponentModel.Description("The target context parameter that you would like to append the source context param value")] public string ContextParamTarget { get; set; } [System.ComponentModel.DefaultValue("$WebTestIteration")] [System.ComponentModel.Description("The source context parameter that contains the value you would like appended to the target context param")] public string ContextParamSource { get; set; } public override void PreWebTest(object sender, PreWebTestEventArgs e) { //confirm the context param to append and the context param with the value both exist if (e.WebTest.Context.ContainsKey(ContextParamTarget) && (e.WebTest.Context.ContainsKey(ContextParamSource))) { e.WebTest.Context[ContextParamTarget] += e.WebTest.Context[ContextParamSource].ToString(); } else { throw new ArgumentException("A Required Context Parameter was not found"); } } }http://blogs.msdn.com/rogeorge
- Marked As Answer by smetah Friday, March 09, 2012 4:52 PM
-
Thursday, March 08, 2012 9:29 PM
Thanks rogeorge,
Sorry to be dense -- how to use it?
Say this is how I do data binding to one field:
-
In the Properties window, find the Value property. It is currently set to Red because that is what you selected when you recorded the Web performance test. Click the property, and then click the down arrow that appears.
-
Expand ColorsMDB, expand the Colors table, and then select ColorName. TheRadioButtonList is now bound to the data source.
Now how to play the magic to have $WebTestIteration appended to it?
Thanks
-
-
Thursday, March 08, 2012 10:19 PM
- Okay, first you need to add a class.cs file to the project and then put the plugin code above. You need to recompile one time.
- Next, in your webtest you need to right click on the webtest top node - and choose Add WebTest plugin, which brings up a dialog, and the plugin above will now show up. Select that, and fill in the target and source properties for your scenario. Note, there are default values you should see in the plugin, as examples.
- Click okay, and now when the test runs, in the PreWebTest event that fires before the test runs, it will append the values that were loaded into the context parameter.
The databinding loads the values into Context Paramaters (you can view the context in the context tab) in the playback viewer as an example. So, you need to change the property for the ContextParamTarget to match whatever your data source column is, you can get this easily by just looking int he Context tab if your not sure what the name is. In mine, it was DataSource1.SomeDataFile#csv.FieldName, yours will be something else. In the example above it might be ColorsMDB.Colors#csv.ColorName if the datasource was loading a csv file called Colors.
The $WebTestIteration is a built in context param, again you should see this in the Context tab to review it.
So, since the datasource values are loaded into the context params, and your test is using the values by binding the values in your test - all your doing is appending the value of the $WebTestIteration to the existing value in the datasource, thats what the code above is doing. This plugin can apppend any context parameter to any other context parameter by just setting the properties.
http://blogs.msdn.com/rogeorge
- Marked As Answer by smetah Thursday, March 08, 2012 11:59 PM
-
Thursday, March 08, 2012 10:23 PM
Thanks rogeorge,
Will look into it and post back...
-
Friday, March 09, 2012 4:52 PM
Alright, what confused me was that, what I wanted was to append the value of variable to each data binding fields, i.e., do the append to all data binding fields, but couldn't relate that to the code. Now I know that the code only handle one field. No problem. I'll go from here.
Thanks again.
-
Friday, March 09, 2012 6:13 PM
Hi Semtah,
You can add the plugin multiple times, or you can change the code to loop over your context params looking for a StartsWith or Contains match for your context params. If your not sure on the code to do that (not sure your experience) its cool just let me know, I can make an update to the code easily for you.
http://blogs.msdn.com/rogeorge
- Marked As Answer by smetah Friday, March 09, 2012 6:32 PM
-
Friday, March 09, 2012 6:32 PM
"You can add the plugin multiple times"
Oh, super. Better than I planned to do.
Thanks
-
Friday, March 09, 2012 6:55 PM
"You can add the plugin multiple times"
Oh, just found out that it is impossible to add the same plugin multiple times for different fields, but have to alter it a little bit.
So please update the the code so that it reads from DataSource2.SomeDataFile#csv for .FieldName and .FieldVal pair, and loop through them to work on all designated fields. Hmm... hold on, better read them (the .FieldName and ..FieldVal pairs) only once when test starts, into an array or something. Oh, for this time, please make the default append value to be of current date/time, format DDHHMM.
Really appreciate your help. I'm just starting with C# so it would take me quite a while to come up solutions like this.
Thanks!!! -
Friday, March 09, 2012 8:31 PMAs I said, you can add the plugin multiple times in the same webtest to append a value to different fields, there is no need to alter the plugin to do that part of it. Help me understand how that seems impossible to you?
http://blogs.msdn.com/rogeorge
-
Friday, March 09, 2012 8:44 PM
I thought so, but somehow when I test it, I wasn't able to.
Now I'm able to do that.
Again, this is better than I what I planned to do.
Thanks!

