Welcome to MSDN Blogs Sign in | Join | Help

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

    }

}

 

 

Published Wednesday, April 18, 2007 1:58 PM by slumley

Comments

# Another Fiddler Web Test Plugin Example

Please see this article for a simple example of a fiddler web test plugin: http://blogs.msdn.com/slumley/pages/another-fiddler-plugin-example.asp

Wednesday, April 18, 2007 9:05 AM by Sean Lumley's Blog

# New Fiddler Release

This is my last post for today, I promise. But Ed Glas (on the VSTS Test team) asked me to help publicize

Wednesday, April 18, 2007 2:06 PM by bharry's WebLog

# VSTS Testing: Using Fiddler to record VSTS web tests

Sean Lumley , a developer on the VSTS web test team, has written a series of posts on using a new version

Wednesday, April 18, 2007 10:52 PM by Buck Hodges

# Fiddler2 HTTP Debugger - 2.0 Release.

沒聽過 fiddler ? 你也應該試試下載 Fiddler2 HTTP Debugger - Fiddler2 Sean Lumley's Blog 整理了一份很詳細的文件, 你可以用 Fiddler

Friday, April 20, 2007 12:47 AM by Refines.Info["Polo Lee"]
Anonymous comments are disabled
 
Page view tracker