在负载测试完成运行后,从负载测试访问webtest上下文参数

时间:2017-09-27 09:04:52

标签: c# performance-testing load-testing webtest context-param

我正在运行负载测试,并且在负载测试完成后尝试在数据库(版本)中插入webtest上下文参数。但在负载测试中,它没有看到上下文参数。到目前为止,我已经创建了一个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上下文参数。但它没有看到它。

使用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");







    }
}

当我使用webtest插件运行webtest时出现错误: WebTestContext中没有名称为'$ LoadTestUserContext'的上下文参数

0 个答案:

没有答案