Regular Expression Extraction within Web Test Request Plug-In  
Author Message
Lewis Horowitz





PostPosted: Visual Studio Team System - Testing, Regular Expression Extraction within Web Test Request Plug-In Top

In our web app, I need to grab some data and use it as a Form Post Parameter in the following request. I've created a regular expression extraction rule but do not wish to add this to over 75% of the requests in my webtest. Is is possible to code the  extraction rule in a Web Test Request Plug-In and, if so, can you provide an example in VB

If not VB, how about C# (added Sept 7th)

Thanks.

 



Visual Studio Team System37  
 
 
Dennis Stone - MSFT





PostPosted: Visual Studio Team System - Testing, Regular Expression Extraction within Web Test Request Plug-In Top

Hi Lewis, one way you could go about doing this is to add your extraction rule to the PreRequest event in the request plug-in, for example:

C#

public override void PreRequest(object sender, PreRequestEventArgs e)

{

ExtractRegularExpression rule1 = new ExtractRegularExpression();

rule1.RegularExpression = "<title>\\w*</title>";

rule1.IgnoreCase = false;

rule1.Required = true;

rule1.Index = 0;

rule1.ContextParameterName = "extractedValue";

e.Request.ExtractValues += new EventHandler<ExtractionEventArgs>(rule1.Extract);

}

This will add the rule to each request as it runs and update its value in the context.

Dennis



 
 
EdGlas





PostPosted: Visual Studio Team System - Testing, Regular Expression Extraction within Web Test Request Plug-In Top

I don't think we have an example that does exactly this, but you can generate sample code by doing the following:

Add the extraction rule to your test.

Generate code.

The generated code will look a lot like the code you need to write in your plugin.

Ed.



 
 
ChrisPat MSFT





PostPosted: Visual Studio Team System - Testing, Regular Expression Extraction within Web Test Request Plug-In Top

If you want to use the same context parameter name over and over you will have to clear the parameter before each execution of the extraction rule otherwise it will fail saying the context parameter already exists.