Another Fiddler Plugin Example
Here is another example of a fiddler plugin. This plugin will loop through each request and mark a request to not be written to the web test if it ends in a particular extension. This example shows you how to flag requests to not be written to the web test by setting the WriteToWebTest property on the Session object. Please see my previous post for how to deploy the plugin: Writing Fiddler Web Test Plugins
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fiddler;
using Fiddler.WebTesting;
namespace FiddlerPluginExample
{
public class FilterExtensionExample : IFiddlerWebTestPlugin
{
#region IFiddlerWebTestPlugin Members
public void PreWebTestSave(object sender, PreWebTestSaveEventArgs e)
{
//create a list of extensions to exclude
List<string> extensionsToExclude = new List<string>();
extensionsToExclude.Add(".jpg");
extensionsToExclude.Add(".jpeg");
extensionsToExclude.Add(".gif");
extensionsToExclude.Add(".js");
extensionsToExclude.Add(".css");
for (int i = 0; i < e.FiddlerWebTest.Sessions.Count; i++)
{
//get the path part of the URL
string path = e.FiddlerWebTest.Sessions[i].FiddlerSession.PathAndQuery;
//if there is a query string, strip it off
int idxOfQueryString = path.IndexOf("?");
if (idxOfQueryString > -1)
{
path = path.Substring(0, idxOfQueryString);
}
//get the extension
int idxOfExtension = path.LastIndexOf(".");
if (idxOfExtension > -1)
{
string extension = path.Substring(idxOfExtension);
//if extension is in the exclude list then filter it
if (extensionsToExclude.Contains(extension))
{
//set the WriteToWebTest property to false
//to prevent the request from being written
//during save
e.FiddlerWebTest.Sessions[i].WriteToWebTest = false;
}
}
}
}
#endregion
}
}
Comments
Anonymous
April 18, 2007
Please see this article for a simple example of a fiddler web test plugin: http://blogs.msdn.com/slumley/pages/another-fiddler-plugin-example.aspAnonymous
April 18, 2007
This is my last post for today, I promise. But Ed Glas (on the VSTS Test team) asked me to help publicizeAnonymous
April 18, 2007
Sean Lumley , a developer on the VSTS web test team, has written a series of posts on using a new versionAnonymous
April 19, 2007
沒聽過 fiddler ? 你也應該試試下載 Fiddler2 HTTP Debugger - Fiddler2 Sean Lumley's Blog 整理了一份很詳細的文件, 你可以用 FiddlerAnonymous
December 11, 2011
Dear slumley, I am facing the following problem. can you guide me how to solve it. The type or namespace name 'IFiddlerWebTestPlugin' could not be found The type or namespace name 'PreWebTestSaveEventArgs' could not be found The type or namespace name 'WebTestSession' could not be found I am using latest version of fiddler and vs2008. Regards, ShaheenAnonymous
September 03, 2012
Shaheen, read the following comments in the related post: blogs.msdn.com/.../writing-fiddler-web-test-plugins.aspx EricLaw [MSFT] 12 Aug 2010 8:37 AM
Due to Fiddler's new Import/Export Architecture, this code has changed in Fiddler 2.3. Fiddler 2.3.0.2 (See www.fiddler2.com/.../fiddler2alphasetup.exe until released) re-introduces support for Webtest export plugins. You need to recompile your plugins referencing the new ImportExport VSWebTestExport.dll assembly (which has the WebTest plugin interface). By default, that assembly looks for your plugins in the DocumentsFiddler2ImportExportVSWebTestPlugins folder, unless you've overridden the path using the fiddler.config.path.webtestexport.plugins preference.