WebTest Plugin : SetMaxMinThinkTime

WebTest Plugin that dynamically Sets the Maximum or Minimum think time value for each request. Options to throw exception if it encounters a think time larger than your max value so it can help to track down tests that have requests with large think times. Overrides the PreRequest event


 [Description("WebTest Plugin that dynamically Sets the Maximum or Minimum think time value for each request. Overrides the PreRequest event")]
    public class SetMaxMinThinkTime : WebTestPlugin
        public SetMaxMinThinkTime()
            MaxThinkTime = 60;
            MinThinkTime = 0;
            OutputComments = false;
            Enabled = true;
            ThrowExceptionIfThresholdExceeded = false;
        public override void PreRequest(object sender, PreRequestEventArgs e)
            //if plugin is disabled output a comment and return
            if (Enabled == false)
                if (OutputComments)
                    e.WebTest.AddCommentToResult(this.ToString() + " Plugin is Disabled, no processing occured.");
            //determine if threshold values exceeded and throw if exception enabled
            if (((e.Request.ThinkTime > MaxThinkTime) || (e.Request.ThinkTime < MinThinkTime)) && (ThrowExceptionIfThresholdExceeded))
                e.WebTest.AddCommentToResult(this.ToString() + " Think Time Threshold value exceeded. Think Time = " + e.Request.ThinkTime.ToString());
                throw new Exception("A Think Time threshold value was exceeded.");
            //update think time if greater than MaxThinkTime
            if (e.Request.ThinkTime > MaxThinkTime)
                e.Request.ThinkTime = MaxThinkTime;
            //update think time if less than MinThinkTime
            if (e.Request.ThinkTime < MinThinkTime)
                e.Request.ThinkTime = MinThinkTime;
            if (OutputComments)
                e.WebTest.AddCommentToResult("SetMaxMinThinkTime value = " + e.Request.ThinkTime.ToString());
        [Description("Maximum Think Time value for any request")]
        public int MaxThinkTime { get; set; }
        [Description("Minimum Think Time value for any request")]
        public int MinThinkTime { get; set; }
        [Description("Enable output comments added to the test results view. Default is false")]
        public bool OutputComments { get; set; }
        [Description("Enable or Disable the plugin execution. Default is Enabled (true)")]
        public bool Enabled { get; set; }
        [Description("Throw exception when encountering Min or Max values that exceed threshold value. Default is false")]
        public bool ThrowExceptionIfThresholdExceeded { get; set; }
Comments (0)

Skip to main content