1

I have written a Visual Studio (2008) Webtest plugin, and need to display the time it takes to run in the playback ui window.

I've tried:

e.WebTest.BeginTransaction("B2BValidate");

// then call my plugin

e.WebTest.EndTransaction("B2BValidate");

This indeed adds a "B2BValidate" transaction to the playback window, but the "Total Time" column displays as 0.000 sec. What am I missing?

-Matt

Matt Frear
  • 52,283
  • 12
  • 78
  • 86

2 Answers2

1

Transactions in Visual Studio expect to contain a request - they simply don't work directly inline in code like that without a request in between.

You'll have to use something like http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx to start and stop a timer and then use the AddCommentToResult() method of the WebTest to show the elapsed time in the webtest results viewer.

Another option is to put your webtest in a loadtest and then refer to the performance counters:

  • % Time in LoadTestPlugin
  • % Time in Rules
  • % Time in WebTest code

although of course that only gives proportions rather than precise timing data.

agentnega
  • 3,478
  • 1
  • 25
  • 31
-1

There is a TransactionTimer class which needs to be instantiated and the request scope for the timer defined.

       public class DynamicTransactionTimer : WebTestRequestPlugin
 {
 public override void PreRequest(object sender, PreRequestEventArgs e)
 {
     TransactionTimer t = new TransactionTimer();
     t.Name = "trx3";
     t.Items.Add(e.Request);
     e.WebTest.BeginTransaction("trx3"); 
 }

     public override void PostRequest(object sender, PostRequestEventArgs e)
     {
         e.WebTest.EndTransaction("trx3");
     }
    }
  • 2
    This doesn't work. If you try it you'll see that 'trx3' reports 0.00 seconds response time and elapsed time, in a standalone web test or a load test. You can't EndTransaction() in the WebTestRequestPlugin PostRequest event or the time of the last request is excluded. Also, your object 't' is not actually used at all in the BeginTransaction/EndTransaction calls. A completely new TransactionTimer object is created by the webtest engine. It does not appear that the TransactionTimer class is intended to be used directly. – agentnega Oct 18 '11 at 21:44