The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DeclarativeWebTestSerializer Class


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

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


public class DeclarativeWebTestSerializer


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)



Opens a Web performance test file.

System_CAPS_pubmethodSystem_CAPS_staticSave(DeclarativeWebTest, Stream)

Saves a Web performance test to a stream.

System_CAPS_pubmethodSystem_CAPS_staticSave(DeclarativeWebTest, String)

Saves a Web performance test file.


(Inherited from Object.)

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.

Legacy Code Example

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");

        //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;

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

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

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

Return to top