Reputation: 308
How do I get variable value in __javaScript function ?
My code:
String[] zoollevelParams = Parameters.split(",");
Random random = new Random();
int zoomValue= Integer.parseInt(zoollevelParams[random.nextInt(10)]);
double lat = 50.669;
double lng = 5.499;
int numTiles = ${__javaScript(Math.pow(2\, "${zoomValue}"))};
This code is unbale to get value of zoomValue in __javaScript function call, how do I get value in this function?
Upvotes: 3
Views: 6636
Reputation: 168157
Don't inline JMeter Variables or Functions into scripts, particular in your case __javaScript function is being executed before zoomValue
is getting initialized.
groovy
from the "Language" dropdownCache compiled script if available
box tickedAmend the last line of your code to look like:
int numTiles = Math.pow(2, zoomValue)
Demo:
Check out Apache Groovy - Why and How You Should Use It article for more details on using Groovy for scripting in JMeter tests.
Upvotes: 0
Reputation: 58862
You can't combine Java and Javascript code and don't need to.
Just keep using Java and take parameter from JMeter variables object vars
:
int numTiles = Math.pow(2, vars.get( "zoomValue"));
vars.getObject
Upvotes: 2