Read data from multiple data sources using Visual studio WebTest



Requirement

As a performance tester, I should be able to read the data from any number of the datasource based on the my requirement
(Ex: Different environments Test,UAT,Prod)
We can accomplish the same using below code snippet
    [DataSource("TestDataSource", "System.Data.SqlClient", Constants.TestDataConnectionString, Microsoft.VisualStudio.TestTools.WebTesting.DataBindingAccessMethod.Sequential,
Microsoft.VisualStudio.TestTools.WebTesting.DataBindingSelectColumns.SelectAllColumns, "Users")]
[DataBinding("TestDataSource", "Users", "userid", "TestDataSource.Users.userid")]
[DataSource("UATDataSource", "System.Data.SqlClient", Constants.TestDataConnectionString, Microsoft.VisualStudio.TestTools.WebTesting.DataBindingAccessMethod.Sequential,
Microsoft.VisualStudio.TestTools.WebTesting.DataBindingSelectColumns.SelectAllColumns, "Users")]
[DataBinding("UATDataSource", "Users", "userid", "UATDataSource.Users.userid")]
public class CreateUser : WebTest
{
public CreateUser ()
{
this.PreAuthenticate = true;
this.Proxy = "default";
}
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
if (Env == "Test)
{
string TestUser= Context["TestDataSource.Users.userid"].ToString();
}
else
{
string UatUser = Context["UATDataSource.Users.userid"].ToString();
}
}

Comments (0)

Skip to main content