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

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.