문제

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.

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.)

Thanks!

도움이 되었습니까?

해결책

I think using __javascript(parseInt()) should suffice for you to check the condition.

e.g.

${__javaScript(parseInt(${time_elapsed_string}) < parseInt(${duration}))}

다른 팁

Assuming that you have following variables:

  • currentSize
  • maxSize
  • continue

where continue is set via User Defined Variables and has the value of true

You can use following Beanshell code to check if current size is equal or greater than maximum size:

import java.math.BigDecimal;

String currentSize = vars.get("currentSize");
String maxSize = vars.get("maxSize");

BigDecimal currentSizeNumber = new BigDecimal(currentSize);
BigDecimal maxSizeNumber = new BigDecimal(maxSize);

if (currentSizeNumber.compareTo(maxSizeNumber) > -1){
    vars.put("continue", "false");
}

Make sure that following criteria are met:

  1. Your While Controller has ${continue} as a condition
  2. Beanshell Sampler, Pre / Post Processor or Assertion with the code above is added as a child of the While Controller

See How to use BeanShell guide for more details and kind of Beanshell cookbook.

Everything should work this way.

Hope this helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top