DCSIMG

 Subscribe in a reader

How to abort a web test on specific request - Guy kolbis
Monday, May 14, 2007 12:36 PM kolbis

How to abort a web test on specific request

By default all requests inside a web test will be executed no matter of the results. In other words, if you got 2 requests inside your web test and the first request fails, the web test will continue to the second request and will execute it.

Sometimes, we do not want to continue running the following requests upon a failure. To do so, we can choose to code our web test or to create a WebTestRequestPlugIn.

Coded web tests are to be avoided as possible and there are only three cases where I would consider using one:

  1. Branching - An IF...Else
  2. Looping
  3. Javascript / ActiveX

I am not going to elaborate about coded web tests in this post.

The second option is to use a WebTestRequestPlugIn. Here is a sample code that will help you understand how to stop a web test upon a validation error:

public class StopTestPlugin : WebTestRequestPlugin
{
public override void PostRequest(object sender, PostRequestEventArgs e)
{

}

void Request_ValidateResponse(object sender, ValidationEventArgs e)
{
ValidationRuleFindText ft = new ValidationRuleFindText();
ft.FindText = "The test to find";
ft.IgnoreCase = true;
ft.PassIfTextFound = true;
ft.Validate(sender, e);

if (!e.IsValid)
{
e.WebTest.Stop();
}
}

public override void PreRequest(object sender, PreRequestEventArgs e)
{
e.Request.ValidateResponse += new EventHandler<ValidationEventArgs>(Request_ValidateResponse);
}
}

You can take this code snippet and extend it for your own needs. Enjoy!

תגים:, , ,

תוכן התגובה

# Advanced issues for VSTS testers - Cross posts

SRLTeam כתב/ה

Sarit Tamir previously submitted a post that introduces SRL's bloggers Guy Kolbis, Maor David and Leon

Monday, June 04, 2007 2:10 PM

# re: How to abort a web test on specific request

nick_relnod כתב/ה

שלח תגובה

(שדה חובה) 
(שדה חובה) 
(אופציונלי)
(שדה חובה) 

Enter the numbers above: