Dela via


PostWebTestEventArgs.WebTest Property

Gets the WebTest object that completed and caused the PostWebTest event.

Namespace:  Microsoft.VisualStudio.TestTools.WebTesting
Assembly:  Microsoft.VisualStudio.QualityTools.WebTestFramework (in Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)

Syntax

'Declaration
Public ReadOnly Property WebTest As WebTest
public WebTest WebTest { get; }
public:
property WebTest^ WebTest {
    WebTest^ get ();
}
member WebTest : WebTest
function get WebTest () : WebTest

Property Value

Type: Microsoft.VisualStudio.TestTools.WebTesting.WebTest
A WebTest object.

Examples

The following example shows a Web performance test plug-in that adds a random number to the context before the Web performance test is run and displays the length of the last WebTestResponse after the Web performance test has run.

Note how this property provides a reference to the WebTest.

using System;
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.Windows.Forms;

namespace WebTestPluginNamespace
{
    public class MyWebTestPlugin : WebTestPlugin
    {
        public static string NewRandomNumberString(int size)
        {
            byte[] buffer = new byte[size];
            // Seed using system time
            Random random = new Random(unchecked((int)DateTime.Now.Ticks));

            random.NextBytes(buffer);
            return BitConverter.ToInt32(buffer, 0).ToString();
        }

        public override void PreWebTest(object sender, PreWebTestEventArgs e)
        {
            e.WebTest.Context["RandNum"] = NewRandomNumberString(4);
        }
        public override void PostWebTest(object sender, PostWebTestEventArgs e)
        {
            MessageBox.Show(e.WebTest.LastResponse.ContentLength.ToString());
        }
    }
}

.NET Framework Security

See Also

Reference

PostWebTestEventArgs Class

Microsoft.VisualStudio.TestTools.WebTesting Namespace