jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "" <>
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
<>   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
<>  .  

Here is the code which will store file's contents into *myVar* JMeter

> import
> 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:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message