Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DeclarativeWebTestSerializer Class

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

Object
  Microsoft.VisualStudio.TestTools.WebTesting.DeclarativeWebTestSerializer

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

public class DeclarativeWebTestSerializer

The DeclarativeWebTestSerializer type exposes the following members.

  NameDescription
Public methodEqualsDetermines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberOpen(Stream)
Public methodStatic memberOpen(String)Opens a Web performance test file.
Public methodStatic memberSave(DeclarativeWebTest, Stream)Saves a Web performance test to a stream.
Public methodStatic memberSave(DeclarativeWebTest, String)Saves a Web performance test file.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

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

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