有没有办法在响应的断言中使用数组索引内的变量?

时间:2019-02-01 13:47:41

标签: arrays jmeter

我有一个json响应。我正在使用json断言,其中其中一个键中有一个大数组。我将Json路径作为$ .value.page [9999] .hash传递。现在我想要一个变量值而不是9999。如何使用变量而不是9999。我试图使用在beanshell后处理器中生成的变量。但是我失败了。有什么解决办法吗?

2 个答案:

答案 0 :(得分:1)

您可以为此使用__V() function

  

V(变量)函数返回评估变量名表达式的结果。可以用来评估嵌套变量引用(当前不支持)。

     

例如,如果一个变量具有A1,A2和N = 1:

     

${A1}-正常

     

${A${N}}-不起作用(嵌套变量引用)

     

${__V(A${N})}-运行正常。 A${N}变成A1,而__V函数返回值A1

所以您可以提出类似的信息:

${__V($.value.page.[${page}].hash)}

演示:

enter image description here

更多信息:Here’s What to Do to Combine Multiple JMeter Variables

答案 1 :(得分:0)

尝试使用eval()evalVar()函数来提取所需的内容:

// THIS IS THE VARIABLE I WANT TO CHANGE ON RESIZE
var triggerOffset = document.documentElement.clientHeight / 2 + 44;

window.onresize = function() { 
// each time the window will resize this code will trigger

// we re cacalculate the triggerOffset value
    triggerOffset =  document.documentElement.clientHeight / 2 + 44;

// we also need to se reset the top value onto the .contain dom element
// basically since we recalculated the triggerOffset you must also update where this value was needed
    TweenLite.set(".contain", {
        top: triggerOffset - cardHeight

    });

    TweenLite.set(".timeline-trigger", {
        top: triggerOffset
    });
}

    TweenLite.set(".contain", {
        top: triggerOffset - cardHeight

    });

    TweenLite.set(".timeline-trigger", {
        top: triggerOffset
    });

    TweenLite.set(".start-trigger", {
        top: sceneStart
    });

    TweenLite.set(".end-trigger", {
        top: sceneStart + duration
    });