It is recommended to avoid scripting where possible, you should be able to
read the file into a JMeter Variable or directly into the request body via
__FileToString() function
<https://jmeter.apache.org/usermanual/functions.html#__FileToString> like:
Read file contents:
> ${__FileToString(/path/to/your/file.txt,,)}
Read file contents and store it into *myVar* variable:
> ${__FileToString(/path/to/your/file.txt,,myVar)}
If you still want to go for scripting be aware that since JMeter 3.1 users
are encouraged to use JSR223 Test Elements and Groovy language
<https://www.blazemeter.com/blog/groovy-new-black> .
Here is the code which will store file's contents into *myVar* JMeter
Variable
> import org.apache.commons.io.FileUtils
> import java.nio.charset.StandardCharsets
>
> vars.put('myVar', FileUtils.readFileToString(new
> File('/path/to/your/file.txt'),StandardCharsets.UTF_8));
It will work for both Beanshell and JSR223 Elements.
--
Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]