Доступ к параметру контекста веб-теста из нагрузочного теста после завершения нагрузочного теста
Я запускаю нагрузочное тестирование и после его завершения пытаюсь вставить параметр контекста веб-теста в базу данных (версия). Но в нагрузочном тесте он не видит параметр контекста. Итак, я создал loadtestplugins следующим образом:
[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;
}
}
Версия String используется для хранения параметра контекста webtest. Но он этого не видит.
Отредактировано с помощью плагина для веб-тестирования и плагина для нагрузочного тестирования
[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");
}
}
Когда я запускаю веб-тест с помощью плагина для веб-тестирования, появляется ошибка: в WebTestContextотсутствует контекстный параметр с именем $LoadTestUserContext.