在jmeter

时间:2016-05-05 05:23:05

标签: jmeter

我必须在jmeter中从Beanshell处理器调用for循环中的一系列http Request。

for (String fName : FNameArray) 
         {
            System.out.println(fName);

            if (dict.get(fName) != null) 
            {
                String dicValue = dict.get(fName).toString();
                String sr = dicValue.substring(dicValue.indexOf('=') + 1);
                String id = sr.substring(sr.indexOf('=') + 1);
                String pval = sr.substring(0, (sr.indexOf('=') - 3));
                String email = id.replace("%40", "@");

                System.out.println(id);
                System.out.println(email);
                System.out.println(pval);

                // from here i have to call http request and pass the pval, id and email to that http request
            }
        }

从上面的代码中,我必须将pval,id和email传递给第一个http请求,然后传递下一个http请求,依此类推。 但是这个pval,id和email都是从for循环中传递出来的。 我怎么能实现这个目标呢?

1 个答案:

答案 0 :(得分:0)

我会选择以下选项:

  1. 修改您的代码如下:

    Custom User Agent
  2. 在Beanshell测试元素之后添加ForEach Controller并按如下方式配置:

    • 输入变量前缀:for (String fName : FNameArray) { int counter = 1; System.out.println(fName); if (dict.get(fName) != null) { String dicValue = dict.get(fName).toString(); String sr = dicValue.substring(dicValue.indexOf('=') + 1); String id = sr.substring(sr.indexOf('=') + 1); String pval = sr.substring(0, (sr.indexOf('=') - 3)); String email = id.replace("%40", "@"); System.out.println(id); System.out.println(email); System.out.println(pval); vars.put("id_" + counter, id); vars.put("email_" + counter, email); vars.put("pval_" + counter, pval); counter++; // from here i have to call http request and pass the pval, id and email to that http request } }
    • 输出变量名称:id
    • 在号码前添加“_”:已选中
    • 其他字段 - 空白
  3. Counter测试元素添加为ForEach控制器的子元素,并将其配置为:

    • 开始:current_id
    • 增量:1
    • 参考名称:1
  4. 在计数器后添加HTTP Request Sampler并使用以下参考:

    • “id” - counter
    • “email” - ${current_id}
    • “pval” - ${__V(email_${counter})}

    必要时。

  5. 替代选项是使用Apache HTTPClient库(JMeter构建在它们之上,因此它们可用),请参阅上面的链接以获得快速入门和示例。但在这种情况下,我强烈建议使用JSR223 Sampler and Groovy language而不是Beanshell。

相关问题