Control code execution between Load and Webtests

Requirement
As a performance tester, I would like to
Execute a specific plugin/block of Code during Webtest and skip the same code, when I execute the load test(Which has this WebTest) and ViceVersa
This need to done without making any configuration changes while running web or loadtest.
We can use below sample codesnippet to accomplish the same
********Execute specific block of code during WebTest and loadTest*********
public class MySampleWebTest: WebTest
{
        public MySampleWebTest()
{
this.PreAuthenticate = false;
this.Proxy = “default”;
}
        public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
if (this.Context.ContainsKey(“$LoadTestUserContext”))
{
// ***********Below code will be automatically executed when we run load Test***********
//this.Context.Add(“Debug”, “InLoadTestMode”);
//
}
else
{
// ***********Below code will be automatically executed when we run WebTest***********
//this.Context.Add(“Debug”, “InWebTestMode”);
}
}
}
********Execute specific plugin of code during WebTest and loadTest*********
//  Execte a plugin that reads test data from Csv file during LoadTest and a hardcoded value during webtest execution
    public class MySampleWebTest: WebTest
{
// Plugin initialization, to be executed only during LoadTest not during webTest
private SetUnqiueLoginName testPlugin0 = new SetUnqiueLoginName();
        public MySampleWebTest()
{
this.PreAuthenticate = true;
this.Proxy = “default”;
this.StopOnError = true;
if (this.Context.ContainsKey(“$LoadTestUserContext”))
{
// Below plugin code will be executed during LoadTest that reads data from Csv file
this.PreWebTest += new EventHandler<PreWebTestEventArgs>(this.testPlugin0.PreWebTest);
}
else
{
// Below plugin code will be executed during Webtest that reads hard coded value
this.Context.Add(“UniqueLoginName”, “smoketestuser”);
}

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.