0

我正在运行负载测试,负载测试完成后,我尝试在数据库(版本)中插入 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”的上下文参数

4

0 回答 0