jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "glinius@live.com" <glin...@live.com>
Subject Re: How to read full data from a txt file by using Beanshell script
Date Thu, 28 Sep 2017 05:34:55 GMT
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: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Mime
View raw message