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

Skip to main content