0

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

laura
  • 15
  • 8
  • What does *"trying to insert a webtest context parameter"* mean? Your question is not at all clear. Remember that each execution of a webtest has its own context paremeters (CPs), when they complete they are finished and all their CPs are lost. The load test finished event runs after all of the webtests have finished so there are no webtest CPs remaining. Assuming you want a CP from a webtest execution, which of the many webtest runs should supply the value? What do you want to do with the similar CP value from all the other webtests? Please [edit] the question to fill in the missing details. – AdrianHHH Sep 27 '17 at 09:47
  • Hi @AdrianHHH, am trying to insert a context parameter(version) in a database. The context parameter is in the webtest. It contain the version of the site on which the load test is run. In all test the context parameter value will be same as the site version will not change. is there a way i can access the context parameter of test ran? – laura Sep 27 '17 at 10:55
  • Why is the updated `m_loadTest_LoadTestFinished` accessing CP `$LoadTestUserContext` when the web test plugin wrote to CP `version`? – AdrianHHH Sep 28 '17 at 08:37
  • I have done some testing and found that my answer posted earlier was wrong. One way of doing what you want is to write to the database in a web test plugin, but make the write conditional on something like `if(e.WebTest.Context["$WebTestIteration"].ToString() == "1")`. That way the first test case executed will write the value. – AdrianHHH Sep 30 '17 at 08:18
  • For more details of the `$LoadTestUserContext` and how it is used see https://stackoverflow.com/questions/11125385/is-it-possible-to-persist-webtestcontext-across-asp-net-load-test-session – AdrianHHH Oct 05 '17 at 14:11

0 Answers0