1

I need to use variable from beanshell in my while loop, but I am not able to see the value of variable coming through.

output variable of my JDBC select count(*) query is "count_num"

using following code in beanshell:

int id = Integer.parseInt(vars.get("count_num_1").trim());

Following is the structure of my test plan:

-JDBC request (o/p variable is count_num)
-beanshell sampler (parse string count_num to integer)
-While Controller: vars.get(${i})>0)   
  -http request1
  -http request2
  - (beanshell code to decrease "i" by 5 - not sure how??)

What am i doing wrong in usage of "i" and also how to decrease count of "i" by 5 towards the end of while loop.

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
vsingh
  • 125
  • 1
  • 2
  • 16

1 Answers1

1

Put variable string value after adding 5

 vars.put("count_num_1", String.valueOf(id +5));
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • I tried using following code: try { int id = vars.get("count_dcn_1"); id = id - 5; vars.put ("count_dcn_1",String.valueOf(id)); } catch (Throwable ex) { log.error("Error in Beanshell", ex); throw ex; } Error: Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: `` try { int id = vars.get("count_dcn_1"); id = id - 5; vars.put ("count_dcn_1",St . . . '' : TargetError – vsingh Jul 19 '19 at 17:34
  • I am sorry about the formatting, somehow I am having trouble formatting comment section using mac, specially for code. – vsingh Jul 19 '19 at 17:39
  • Thank you, it worked! Could you also help me understanding why my while loop won't work. my while loop has code::: ${count_num_1}>0 the above code which we used for decrementing the value of count_num_1 is working, but then code within while loop still keep getting executed. – vsingh Jul 19 '19 at 18:23
  • Actually, following code worked: ${__javaScript(parseInt(${count_dcn_1})>0)} – vsingh Jul 19 '19 at 18:37