I am running a load test and after the load test has finished am trying to insert a webtest context parameter in database(version). But in the load test it's not seeing the context parameter. So far, i have created a loadtestplugins as follows:
[DisplayName("Build Version Processing")]
[Description("Add the build version for a load test")]
public class BuildVersion : ILoadTestPlugin
{
[DisplayName("Comment")]
[Description("What the plugin is for")]
public string theComment { get; set; }
[DisplayName("Test Type")]
[Description("M for Manual or A for Automatic")]
[DefaultValue("A")]
public string connectionStr { get; set; }
[DisplayName("Version Context Parameter")]
[Description("The Context Parameter for the build version")]
[DefaultValue("{{Param_ClientSoftwareVersion}}")]
public string Version_param { get; set; }
LoadTest m_loadTest;
public void Initialize(LoadTest loadTest)
{
m_loadTest = loadTest;
m_loadTest.LoadTestFinished += new EventHandler(m_loadTest_LoadTestFinished);
}
// Do it *after* the Load Test.
//---------------------------------------------------------------------
void m_loadTest_LoadTestFinished(object sender, System.EventArgs e)
{
String name=m_loadTest.Name;
String version = Version_param;
}
}
The String version is used to store the webtest context parameter. But it's not seeing it.
Edited with webtest plugin and load test plugin
[System.ComponentModel.DisplayName("GetVersion")]
[System.ComponentModel.Description("Get the Build No Version")]
public class GetVersion : WebTestPlugin
{
//Setting the version in the usercontext
public override void PostWebTest(object sender, PostWebTestEventArgs e)
{
String version = e.WebTest.Context["Param_ClientSoftwareVersion"].ToString();
LoadTestUserContext userContext = (LoadTestUserContext)e.WebTest.Context["$LoadTestUserContext"];
userContext["version"] = version;
}
}
/// Specify a name for use in the user interface.
/// The user sees this name in the Add Validation dialog box.
[DisplayName("Build Version Processing")]
/// Specify a description for use in the user interface.
/// The user sees this description in the Add Validation dialog box.
[Description("Add the build version for a load test")]
public class BuildVersion : ILoadTestPlugin
{
[DisplayName("Comment")]
[Description("What the plugin is for")]
public string theComment { get; set; }
[DisplayName("Test Type")]
[Description("M for Manual or A for Automatic")]
[DefaultValue("A")]
public string connectionStr { get; set; }
[DisplayName("Version Context Parameter")]
[Description("The Context Parameter for the build version")]
[DefaultValue("{{Param_ClientSoftwareVersion}}")]
public string Version_param { get; set; }
LoadTest m_loadTest;
public void Initialize(LoadTest loadTest)
{
m_loadTest = loadTest;
m_loadTest.LoadTestFinished += new EventHandler(m_loadTest_LoadTestFinished);
}
// Do it *after* the Load Test.
//---------------------------------------------------------------------
//Getting the version in the usercontext
void m_loadTest_LoadTestFinished(object sender, System.EventArgs e)
{
LoadTestUserContext loadTestUserContext = this.m_loadTest.Context["$LoadTestUserContext"] as LoadTestUserContext;
String name = m_loadTest.Name;
String version = loadTestUserContext.Count.ToString();
bool test = loadTestUserContext.ContainsKey("version");
}
}
When i run a webtest with the webtest plugin am getting error: There is no context parameter with the name '$LoadTestUserContext' in the WebTestContext