DeclarativeWebTestSerializer Class

Loads the contents of a .webtest file into an instance of the DeclarativeWebTest class.

Inheritance Hierarchy

Object
  Microsoft.VisualStudio.TestTools.WebTesting.DeclarativeWebTestSerializer

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

Syntax

'Declaration
Public Class DeclarativeWebTestSerializer
public class DeclarativeWebTestSerializer
public ref class DeclarativeWebTestSerializer
type DeclarativeWebTestSerializer =  class end
public class DeclarativeWebTestSerializer

The DeclarativeWebTestSerializer type exposes the following members.

Methods

  Name Description
Public method Equals Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as the default hash function. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic member Open(Stream)
Public methodStatic member Open(String) Opens a Web performance test file.
Public methodStatic member Save(DeclarativeWebTest, Stream) Saves a Web performance test to a stream.
Public methodStatic member Save(DeclarativeWebTest, String) Saves a Web performance test file.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

A declarative Web performance tests is a non-coded Web performance test that can be displayed in the Web performance test editor of Visual Studio. You can programmatically create declarative Web performance tests by using the DeclarativeWebTest and DeclarativeWebTestSerializer classes.

Perhaps something in your Web application has changed that affects a large group of your existing Web performance tests. Rather than modify the tests manually, you could write code to do it for you.

DeclarativeWebTestSerializer loads the contents of a .webtest file into an instance of the DeclarativeWebTest class. DeclarativeWebTestSerializer can also save an instance of the DeclarativeWebTest class to a .webtest file.

DeclarativeWebTest exposes all the properties, requests, and rules of a loaded Web performance test so that you can change and save them.

If you create a declarative Web performance test completely programmatically, you can run it in one of two ways:

  • In Visual Studio, add the test to your test project and then run the test from the Visual Studio IDE. 

  • Run the test by using the MSTest.exe command-line utility. Pass the name of the test file as an argument for the /testcontainer option.

Examples

In this example of a C# console application, an existing declarative Web performance test is opened, modified, and saved.

using Microsoft.VisualStudio.TestTools.WebTesting;

public class WebTestSerializerExample
{
    static void Main(string[] args)
    {
        //Open the Web performance test
        DeclarativeWebTest decWebTest = DeclarativeWebTestSerializer.Open(@"c:\test.webtest");

        //Add a Request to this WebTest
        WebTestRequest newRequest = new WebTestRequest("http://newRequest/default.aspx");
        decWebTest.Items.Add(newRequest);

        //Set ExpectedHttpStatus to 404 on the 1st Request

        WebTestRequest reqToModify = null;
        foreach (WebTestItem item in decWebTest.Items)
        {
            if (item is WebTestRequest)
            {
                reqToModify = item as WebTestRequest;
                break;
            }
        }

        if (reqToModify != null)
        {
            reqToModify.ExpectedHttpStatusCode = 404;
        }

        //Save the Web performance test
        DeclarativeWebTestSerializer.Save(decWebTest, @"c:\test.webtest");
    }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.VisualStudio.TestTools.WebTesting Namespace

Other Resources

[retired] Run web performance tests from the command line