On 22 August 2018 at 16:14, Felix Schumacher <[email protected]> wrote: > > > Am 22.08.2018 um 17:06 schrieb Felix Schumacher: >> >> >> >> Am 21.08.2018 um 21:32 schrieb David Fertig: >>> >>> I have a variable called numFiles, which I can print and verify contains >>> an integer. >>> Integer numFiles = vars.getObject("numFiles"); >>> >>> I want to make a random number between 0 and that value. But all of the >>> following fail >>> ${__Random(0,__ ${numFiles},docIndex)}; >>> >>> Integer docIndex = ${__Random(0,${numFiles})}; >>> >>> ${__Random(0,__ numFiles,docIndex)}; >>> >>> Integer docIndex = ${__Random(0,numFiles)}; >>> >>> All with an errors like: >>> Uncaught Exception java.lang.NumberFormatException: For input string: >>> "${NUMFILES}". See log file for details. >>> >>> Uncaught Exception java.lang.NumberFormatException: For input string: >>> "numFiles". See log file for details. >>> >>> How do I pass a variable into the random() function? >> >> It seems that this is a bug. At the moment the Strings given to __Random >> will not be evaluated (and therefore the Integer will not be transformed >> into a String). > > On second thought "bug" might be a bit harsh, as no function in JMeter will > currently transform those values by itself (yet?).
It's not a bug (or even a feature). It's not supported. Variables were designed to be used for replacement of fixed text in test plans. e.g.. instead of http://a.b.c:80/ one could have the following textual definitions (e.g. on the Test Plan): HOST=a.b.c PORT=80 and use the following instead: http://${HOST}:${PORT}/ It so happens that the variables are stored in a structure that allows the values to be arbitrary objects. This proved useful for passing data between scripts (putObject/getObject), but was never intended for use in the test plan textual substitution functionality. Variables that are used in test plan elements must have values that are Strings. A simple way to fix the errors is to ensure that the script stores the value as a String (e.g. using a new variable name). > To answer your question, you could use __evalVar function to convert your > Integer into a String: > > ${__Random(0,${__evalVar(numFiles)})} > > Regards, > Feli > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
