Jmeter,而控制器似乎没有将变量评估为数字 [英] Jmeter while controller doesn't seem to evaluate variables as numbers
问题描述
我正在编写一个jmeter脚本,该脚本会不断加载数据,直到表达到指定大小为止.我有一个while循环,在这个循环中,我有一个HTTP Sampler来加载数据,然后是另一个具有XPath后处理器的HTTP Sampler来检查表的大小(它们调用了两个不同的API). XPath后处理器的参考变量是currentSize,我有一个用户定义的变量maxSize,但是使用$ {currentSize}< $ {maxSize}作为while循环的条件会创建一个无限循环.
I am writing a jmeter script that keeps loading data until a table reaches a specified size. I have a while loop, in which I have one HTTP Sampler to loads the data, then another HTTP Sampler with an XPath Post-processor to check the table size (they call two different APIs). The reference variable of the XPath Post Processor is currentSize and I have a user defined variable maxSize, but using ${currentSize} < ${maxSize} as the condition for the while loop creates an infinite loop.
也许问题在于XPath的输出是一个字符串,我尝试在beanshell中执行各种操作以将其强制为数字,但是我是beanshell noob,所以我并没有成功任何一个.谁能指导我有关如何让jmeter将变量识别为数字? (最好是小数,但如果我必须舍入为整数,则可以接受.)
Thinking maybe the problem is that the output of XPath is a string, I've tried doing various things in beanshell to coerce it to a number, but I'm a beanshell noob, so I haven't been successful with that either. Can anyone guide me about how to get jmeter to recognize a variable as a number? (Preferably a decimal, but if I have to round to an int, I can live with that.)
谢谢!
推荐答案
我认为使用__javascript(parseInt())足以满足您检查条件的要求.
I think using __javascript(parseInt()) should suffice for you to check the condition.
例如
$ {__ javaScript(parseInt($ {time_elapsed_string})< parseInt($ {duration}))}
${__javaScript(parseInt(${time_elapsed_string}) < parseInt(${duration}))}
这篇关于Jmeter,而控制器似乎没有将变量评估为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!