如何在Web测试脚本中将参数增加1? [英] How to increment parameter by 1 in Web Test scripts?

查看:38
本文介绍了如何在Web测试脚本中将参数增加1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS 2012进行负载测试。我有一个要求 - 有一个值必须增加1倍,持续10次。我需要参数化这个值。我不知道任何会增加值的函数/方法。因此,现在I
每次都要创建10个不同的参数,这很麻烦。如果VS 2012中有现有功能可以帮助我增加价值,请告诉我。如果没有这样的功能,请建议我如何将
中的方法添加到网络测试中。

I am using VS 2012 for load testing. I have a requirement - There is one value which has to be incremented by 1 for 10 times. I need to parameterize this value. I am not aware of any function / method that will increment values. Due to this, right now I have to create 10 different parameters every time and this is cumbersome. Please let me know if there is an existing function in VS 2012 which will help me increment value. If such a function is not available, please suggest as to how i can add methods in to web tests.

谢谢,

Krupa

推荐答案

我希望在上下文参数中增加值,然后使用插件如:

I would have the value to be incremented in a context parameter and then use a plugin such as:

    public class IncrementNumericContextParameter : WebTestRequestPlugin
    {
        public string ContextParameter { get; set; }

        public override void PreRequest(object sender, PreRequestEventArgs e)
        {
            int initialValue;
            object obj;
            if ( e.WebTest.Context.TryGetValue(ContextParameter, out obj) )
            {
                string cp = obj.ToString();
                initialValue = int.Parse(cp);
            }
            else
            {
                initialValue = 0;
            }

            initialValue++;

            string newValue = initialValue.ToString();
            e.WebTest.Context[ContextParameter] = newValue;

            e.WebTest.AddCommentToResult(string.Format("Increment {0}, now {1}", ContextParameter, newValue));
        }
    }

问候

Adrian


这篇关于如何在Web测试脚本中将参数增加1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆