samedi 2 janvier 2016

Web Performance and load testing Visual Studio 2013

Hello I have this test plan where query string passes a time stamp like 1451726609921. I need to pass dynamic current time stamp to this request. so i created a web test request plugin with this code:

namespace ClassLibrary11 {

public class TimeStamp : WebTestRequestPlugin
{
    // public WebTestContext Context { get; set; }
    String date1;

    //[DisplayName("TimeStamp Value")]
    //[Description("Generate time stamp in milliseconds")]
    //public String TimeStamp1
    //{
    //    get;
    //    set;

    //}


    public override void PreRequest(object sender, PreRequestEventArgs e)
    {
        base.PreRequest(sender, e);



        long timestamp = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds;

        //e.WebTest.Context["date1"] = timestamp.ToString();
        date1 = timestamp.ToString();

        // e.WebTest.Context.Add("LoginUser", abc@hotmail.com);
        e.WebTest.Context.Add("dd", date1);




    }
}

}

Now i bound time stamp in query string to {{dd}} So when i run the test though i can see that dd has value but in response i have an error Context variable dd not in test context.

I have tried deleting the class wiring it again, and changing the code to

namespace ClassLibrary2 {

public class TimeStamp : WebTestRequestPlugin
{
   // public WebTestContext Context { get; set; }
     String date1;

    [DisplayName("TimeStamp Value")]
    [Description("Generate time stamp in milliseconds")]
    public String TimeStamp1
    {
        get;
        set;

    }


    public override void PreRequest(object sender, PreRequestEventArgs e)
    {
        base.PreRequest(sender, e);



        long timestamp = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds;

        //e.WebTest.Context["date1"] = timestamp.ToString();
        date1 = timestamp.ToString();

        // e.WebTest.Context.Add("LoginUser", abc@hotmail.com);
        e.WebTest.Context[TimeStamp1] = date1;




    }
}

}

but still the same problem. in below approach i bind time stamp to the variable i declare for timestamp1 property. Please help me resolve this error.

Aucun commentaire:

Enregistrer un commentaire