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)
Syntax
'Declaration
Public Class DeclarativeWebTestSerializer
'Usage
Dim instance As DeclarativeWebTestSerializer
public class DeclarativeWebTestSerializer
public ref class DeclarativeWebTestSerializer
public class DeclarativeWebTestSerializer
Remarks
A declarative Web tests is a non-coded Web test that can be displayed in the Web test editor of Visual Studio. You can programmatically create declarative Web 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 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 test so that you can change and save them.
If you create a declarative Web 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 test is opened, modified, and saved.
using Microsoft.VisualStudio.TestTools.WebTesting;
public class WebTestSerializerExample
{
static void Main(string[] args)
{
//Open the Web 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 test
DeclarativeWebTestSerializer.Save(decWebTest, @"c:\test.webtest");
}
}
Inheritance Hierarchy
System.Object
Microsoft.VisualStudio.TestTools.WebTesting.DeclarativeWebTestSerializer
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
DeclarativeWebTestSerializer Members
Microsoft.VisualStudio.TestTools.WebTesting Namespace