将多个随机值转换成多个变量-Jmeter [英] multiple random values into Multiple variables - Jmeter

查看:59
本文介绍了将多个随机值转换成多个变量-Jmeter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于此线程多个随机值Jmeter ,我设法根据数组中的数据创建了1个变量.

Based on this thread multiple random values Jmeter , I managed to created 1 variable, based on the data from array.

现在我需要获取两个变量:pickID&pickValue,pickValue保持不变,但pickID应该增加206.

Now I need to fetch two variables: pickID & pickValue, where pickValue remains the same, but pickID should be increased by 206.

所以我将有像这样的随机对:

So I will have random pairs like:

"id":"210","value":"4".或"id":"208",值":"2"

"id": "210", "value": "4" or "id": "208", "value": "2"

如果我尝试这样做:

import java.util.*;  


String[] categories = [0, 1, 2, 3, 4, 5]
for (int i=0; i<categories.length; i++) {
   vars.put("pickID" + (i+1), categories[new Random().nextInt(categories.length)] + (+206)  );
   vars.put("pickValue" + (i+1), categories[new Random().nextInt(categories.length)]);
} 

我在它旁边获得了价值,而不是增加了.例如:

I got value next to it, instead of increased. ex:

    "id": "4206",
    "value": "1"
},
{
    "id": "1206",
    "value": "2"

如何将pickID增加206?

How to increase pickID by 206?

推荐答案

您要添加2个字符串,并且应该添加2个整数并将结果转换为字符串.

You're adding 2 strings and you should be adding 2 integers and convert the result into a string.

类似的东西:

int[] categories = [0, 1, 2, 3, 4, 5]
for (int i = 0; i < categories.length; i++) {
    vars.put("pickID" + (i + 1), String.valueOf(categories[new Random().nextInt(categories.length)] + 206));
    vars.put("pickValue" + (i + 1), String.valueOf(categories[new Random().nextInt(categories.length)]));
}

更多信息:

这篇关于将多个随机值转换成多个变量-Jmeter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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