• No results found

New Inner-text and Select-tag rules published on Codeplex

In 2008

All of the rules in this release on CodePlex relate to the inner text of a tag. For example, for a select tag (list box and combo box), the option text is stored in inner text rather than an attribute:

<select name="myselect1">

<option>Milk </option>

<option>Coffee</option>

<option selected="selected">Tea</option>

</select>

In order to extract the value of the list box, we need to parse out the inner text of the selected option.

TextArea is another tag that does this, but there are also a lot of other examples in HTML where you might want to extract or validate inner text. The new project has these new rules as well as a parser for inner text and select tag:

1. ExtractionRuleInnerText 2. ExtractionRuleSelectTag 3. ValidationRuleInnerText 4. ValidationRuleSelectTag Download location

http://codeplex.com In 2010

Many of the features above are now built into VS 2010. Here is a list of these:

http://msdn.microsoft.com/en-us/library/bb385904(VS.100).aspx

Changed in 2010

Visual Studio Performance Testing Quick Reference Guide Page 178

How to Add Custom Tabs to the Playback UI

Another new feature of the 2010 Web Test Playback UI is the ability to add new tabs to the WebTestResultViewer. Here is a tab that demonstrates how to get VIEWSTATE data from webtest responses and add that data to a table in a custom results tab:

Visual Studio Performance Testing Quick Reference Guide Page 179 Steps to implement your own custom tab

1) Create the new project

Create a Visual Studio Add-In: Create a new Visual Studio Add-In project (see picture below).

This starts the Add-In Wizard. Complete the wizard

 You should now have a project that looks like:

Visual Studio Performance Testing Quick Reference Guide Page 180

Reference the following assemblies directly in the project:

o Microsoft.VisualStudio.QualityTools.LoadTestFramework o Microsoft.VisualStudio.QualityTools.WebTestFramework

o Any other assemblies or code you will need to do the functional work of your addin.

Add a user control to the project (right click -> Add new -> user control). This will house the items to be displayed on the tab.

Add the necessary controls to the main user control. For my example, I needed a checkbox, textbox and a listbox.

Set the listbox Dock property to Fill: Note that when you do this, it will cause the listbox to cover the other controls. We will fix this next.

Set the margins for the main control. This will correct the size of the listbox from the previous step. Make sure the value for TOP is big enough to uncover the other controls.

Make sure just the listbox is highlighted

Make sure the main control is highlighted

Visual Studio Performance Testing Quick Reference Guide Page 181 2) Modify and add the tab control code

You will need to do a fair amount of work inside the “connect.cs” file to make the plugin work. However, you should have your functional code (or at least the shell of it) in place before doing the connect.cs work so the methods you reference will already exist. For my example, the only extra code I need is the backing code for the user control. Double-Click on the listview and add the following methods:

public void AddAValueToTheListView(string sReqName, string sSize, int iTotalSize) {

tbTotalSize.Text = iTotalSize.ToString();

tbTotalSize.Update();

ListViewItem item = new ListViewItem(new string[] { sReqName, sSize });

listViewTagCounts.Items.Add(item);

}

private void cbShowNonViewState_CheckedChanged(object sender, EventArgs e) {

// Add code to handle hiding non viewstate pages }

sReqName is the URL of the current request.

sSize is the calculated size of the ViewState.

iTotalSize is the cumulative value.

All of these properties are calculated and set in the connect.cs code. The code here is solely for modifying the values displayed in the tab.

Visual Studio Performance Testing Quick Reference Guide Page 182 3) Modify and add the Addin handler code

Now we can jump into the connect.cs code. Here are the main items of interest for us:

public class Connect : IDTExtensibility2 {

Dictionary<Guid, Dictionary<Guid, UserControl>> m_controls = new Dictionary<Guid, Dictionary<Guid, UserControl>>();

LoadTestPackageExt wpe;

int iViewStateTotalSize = 0;

public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)

foreach (WebTestResultViewer p in wpe.WebTestResultViewerExt.ResultWindows) {

WindowCreated(p);

}

wpe.WebTestResultViewerExt.WindowCreated += new

EventHandler<WebTestResultViewerExt.WindowCreatedEventArgs>(wpe_WebtestPlaybackWindowCrea ted);

wpe.WebTestResultViewerExt.WindowClosed += new

EventHandler<WebTestResultViewerExt.WindowClosedEventArgs>(WebTestResultViewerExt_WindowC losed);

wpe.WebTestResultViewerExt.SelectionChanged += new

EventHandler<WebTestResultViewerExt.SelectionChangedEventArgs>(WebTestResultViewerExt_Sel ectionChanged);

wpe.WebTestResultViewerExt.TestCompleted += new

EventHandler<WebTestResultViewerExt.TestCompletedEventArgs>(WebTestResultViewerExt_TestCo mpleted);

iViewStateTotalSize = 0;

}

The iViewStateTotalSize is specific to my particular addin. The highlighted lines need to be added to all web test addins.

This method already exists. Delete

everything in the method and add this code.

This line of code is specific to my addin. You should add any initialization code you might need right here.

The highlighted method names correspond to the matching method definitions below.

Visual Studio Performance Testing Quick Reference Guide Page 183 private void WindowCreated(WebTestResultViewer viewer)

{

UserControl1 c = new UserControl1();

c.Dock = DockStyle.Fill;

//add the dictionary of open playback windows

System.Diagnostics.Debug.Assert(!m_controls.ContainsKey(viewer.TestResultId));

Dictionary<Guid, UserControl> userControls = new Dictionary<Guid, UserControl>();

//add the summary

Guid summaryGuid = Guid.NewGuid();

Guid responseGuid = Guid.NewGuid();

userControls.Add(responseGuid, c);

m_controls.Add(viewer.TestResultId, userControls);

//add tabs to playback control

viewer.AddResultPage(responseGuid, "ViewState Info", c);

}

void WebTestResultViewerExt_TestCompleted(object sender, WebTestResultViewerExt.TestCompletedEventArgs e)

{

foreach (UserControl userControl in m_controls[e.TestResultId].Values) {

if (m_controls.ContainsKey(e.WebTestResultViewer.TestResultId)) {

m_controls.Remove(e.WebTestResultViewer.TestResultId);

}

This is stock code. Copy all of it and simply change the user control name to whatever name you gave your control in the previous section.

The text here is the name that appears on the added tab

Visual Studio Performance Testing Quick Reference Guide Page 184 And here is the workhorse method:

void WebTestResultViewerExt_SelectionChanged(object sender, WebTestResultViewerExt.SelectionChangedEventArgs e)

{

if (e.WebTestRequestResult != null) {

foreach (UserControl userControl in m_controls[e.TestResultId].Values) {

This is code that does the work for the addin. Here I get all of the data and then call my control to populate the tab.

The call to my user control to populate the tab.

Visual Studio Performance Testing Quick Reference Guide Page 185 --NEW-- How to extend recorder functionality with plugins

Taken from Sean Lumley’s Blog Site and reproduced in full.

In this post I am going to talk about a new feature that can help with web test recording. The feature is extensible recorder plug-ins for modifying recorded web tests. Basically we are giving you the

opportunity to modify the recorded web test after you click stop on the web test recorder bar but prior to the web test being fully saved back to the web test editor. So what problems does this help with?

The main one is performing your own custom correlation. In VS 2008 we added a process which runs post recording that attempts to find dynamic fields. You can read this blog post for more information:

http://blogs.msdn.com/slumley/pages/web-test-correlation-helper-feature-in-orcas.aspx

This process still exists, but this process does not always find all dynamic fields for an application. So if we did not find the dynamic fields in your application you had to manually perform the correlation process. Here is a blog post that goes into detail about the manual process:

http://blogs.msdn.com/slumley/pages/how-to-debug-a-web-test.aspx Also there are cases that our correlation process does not find the dynamic values, such as dynamic values in the URL.

At a high level, you have to:

1) Determine what parameters are dynamic

2) Then for each parameter find the first occurrence of this in a response body.

3) Add an extraction rule to pull the value out of the response and add it to the context

4) Then modify each query string or form post parameter that needs this value by changing the

value to pull the value out of the context.

This new feature allows you to write your own plug-in which can perform correlation or modify the web test in many ways prior to it being saved back to the web test editor. So once you figure out that certain dynamic variable have to be correlated for each of your recordings, you can automate the process. To demonstrate how this works, I am going to write a recorder plug-in which will perform the correlation that I manually walked through in my previous post. Please quickly read that:

http://blogs.msdn.com/slumley/pages/vs-2010-feature-web-test-playback-enhancements.aspx Overview

Create the plug-in

Recorder plug-ins follow the same pattern as WebTestPlugins or WebTestRequestPlugins. To create a plug-in, you will create a class that extends WebTestRecorderPlugin and then override the

PostWebTestRecording method:

Applies only to 2010

Visual Studio Performance Testing Quick Reference Guide Page 186 public class Class1 : WebTestRecorderPlugin

{

public override void PostWebTestRecording(object sender, PostWebTestRecordingEventArgs e)

{

base.PostWebTestRecording(sender, e);

} }

Modify the web test

The event args will give you 2 main objects to work with: the recorded result and the recorded web test. This will allow you to iterate through the result looking for certain values and then jump to the same request in the web test to make modifications. You can also just modify the web test if you wanted to add a context parameter or maybe parameterize parts of the URL. If you do modify the web test, you also need to set the ReocrdedWebTestModified property to true.

e.RecordedWebTestModified = true;

Deploy the plug-in

After compiling the plug-in, you will need to place the dll in 1 of 2 spots:

1) Program Files\Microsoft Visual Studio

10.0\Common7\IDE\PrivateAssemblies\WebTestRecorderPlugins

2) %USERPROFILE%\My Documents\Visual Studio 10\WebTestRecorderPlugins Executing the plug-in

After you deploy the plug-in, you will need to restart VS for the plug-in to be picked up. Now when you create a web test, you will see a new dialog. The dialog will display all of the available plug-ins that can be executed. Select your plug-in and hit ok. Once you are done recording your web test, the plug-in will be executed.

Creating the Sample Plug-in

First a quick review of the correlation that we are going to automate. Here is the screen shot from correlation tool after I recorded my web test against a reporting services site.

Visual Studio Performance Testing Quick Reference Guide Page 187 We are going to correlate the ReportSession parameter.

1) Create a class library project

2) Right click references and select Add Reference

3) Choose Microsoft.VisualStudio.QualityTools.WebTestFramework

4) Here is the code for my plug-in:

using System.ComponentModel;

using Microsoft.VisualStudio.TestTools.WebTesting;

using Microsoft.VisualStudio.TestTools.WebTesting.Rules;

namespace RecorderPlugins {

[DisplayName("Correlate ReportSession")]

[Description("Adds extraction rule for Report Session and binds this to querystring parameters that use ReportSession")]

public class CorrelateSessionId : WebTestRecorderPlugin {

public override void PostWebTestRecording(object sender, PostWebTestRecordingEventArgs e)

{

//first find the session id bool foundId = false;

Visual Studio Performance Testing Quick Reference Guide Page 188

foreach (WebTestResultUnit unit in e.RecordedWebTestResult.Children) {

Visual Studio Performance Testing Quick Reference Guide Page 189

a. Iterate through the result to find first page with ReportSession. This code fragment

iterates through each of the recorded objects and searches the response body for ReportSession.

foreach (WebTestResultUnit unit in e.RecordedWebTestResult.Children) {

the extraction rule and then finds the correct request in the web test to add the extraction rule to. Each result object has a property called DeclaraticveWebTestItemId which is what we will use to get correct request from the web test.

ExtractionRuleReference ruleReference = new ExtractionRuleReference();

ruleReference.Type = typeof(ExtractText);

ruleReference.ContextParameterName = "SessionId";

ruleReference.Properties.Add(new PluginOrRuleProperty("EndsWith",

"&ControlID="));

ruleReference.Properties.Add(new PluginOrRuleProperty("HtmlDecode",

"True"));

ruleReference.Properties.Add(new PluginOrRuleProperty("IgnoreCase",

"True"));

ruleReference.Properties.Add(new PluginOrRuleProperty("Index", "0"));

ruleReference.Properties.Add(new PluginOrRuleProperty("Required", "True"));

ruleReference.Properties.Add(new PluginOrRuleProperty("StartsWith",

"ReportSession="));

requestInWebTest.ExtractionRuleReferences.Add(ruleReference);

e.RecordedWebTestModified = true;

}

c. Now we need to find all query string parameters that have ReportSession as name and

change the value to {{SessionId}}

WebTestRequest requestInWebTest =

e.RecordedWebTest.GetItem(page.DeclarativeWebTestItemId) as WebTestRequest;

Visual Studio Performance Testing Quick Reference Guide Page 190

if (requestInWebTest != null) {

foreach (QueryStringParameter param in requestInWebTest.QueryStringParameters)

{

if (param.Name.Equals("ReportSession")) {

param.Value = "{{SessionId}}";

} } }

6) Now that we have our plug-in, I need to compile and deploy it to one of the locations listed

above.

7) Restart VS

8) Open a test project and create a new web test. I now see the following dialog with my plug-in

available:

Visual Studio Performance Testing Quick Reference Guide Page 191

9) Select the plug-in

10) Record the same web test against my reporting services site and click stop to end the web test.

11) Now when the correlation process runs, you will see that it does not find the ReportSession parameter. This is because we have already correlated it.

12) Now look at the first request in the web test and you will see the extraction rule.

Visual Studio Performance Testing Quick Reference Guide Page 192 13) Now look at the other requests to see where we are referencing the extraction rule.

This is a slightly more advanced feature, but it provides a huge time savings for automating changes to your recorded web test. If you have multiple people creating web tests, you can use this plug-in to make sure the same parameters or rules are added to each web test. And of course you can automate correlation of parameters or URLs which the built in correlation tool does not find.

Visual Studio Performance Testing Quick Reference Guide Page 193