Add Header - Cookie does NOT work?
In WebTest, there is an option to add headers, but it does not seem to be working.
After I "Add Header", and choose "Cookie" as the name of the header and specify some value, when I replay the sequence back and look at the Request tab, the cookie shown does not match what I specified, but rather what the value that was set by a "Set-Cookie" call in one of the previous requests.
Has anybody got set Cookie header to work?
Hi John,
What you'll need to do for Beta2 is create a WebRequestPlugin that changes the value of the cookie coming back from the server in a PostRequest callout. The proceedure is outlined below:
1. In the solution explorer, right click on the solution and choose Add | New Project.
2. From the Add New Project dialog, select Visual C#\Windows as a project type and then choose Class Library.
3. On the new class library project (ClassLibrary1) node in the Solution Explorer right click and add a reference to Microsoft.VisualStudio.QualityTools.WebTestFramework
4. In you Class1.cs file add a using statement:
using Microsoft.VisualStudio.QualityTools.WebTestFramework;
5. Derive Class1 from WebTestRequestPlugin
6. On the text, WebTestRequestPlugin, right click and choose Implement Abstract Class.
7. Comment the throw statement in the PreRequest method.
8. Use PostRequestEventArgs argument "e" to access the response cookies and override the value returned from the server.
Your class might look something like this:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.QualityTools.WebTestFramework;
namespace ClassLibrary1
{
public class Class1 : WebTestRequestPlugin
{
public override void PostRequest(object sender, PostRequestEventArgs e)
{
if (e.Request.Url.Equals("http://servername/cookiesetter.aspx")) e.Response.Cookies[
"MyCookie"].Value = "MycookieValueOverride"; }
public override void PreRequest(object sender, PreRequestEventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
}
}
}
9. Build your class library project.
10. In your original test project, add a project reference to your class library.
11. On the webtest, select the root of the tree and in the Property Tool Window find the Request Callback property. Click in the value column for this property and then select the drop down button. Choose Class1 from your windows class library project.
We will take a look at checking for cookie overrides using headers and see if we can get this into the product.
Dave