Problem in writing output file in jmeter maven project

43 Views Asked by At

I'm using beanshell postprocessor to write a file in my jmeter script,when I run this script as a maven project the file is being written into the
target folder. I want it to be written inside the src/test/jmeter of my project. How can I achieve this. I'm new in my testing journey so if you find my question silly spare and help me

I tried using the userpropertiesin my pom.xml, also I tried using the maven resource plugin to copy the file from Target to src/test/jmeter.

Edit:

I have created a folder structure like

  • src/test/jmeter/test_folder/test file.csv

  • src/test/jmeter/test_folder/testplan.jmx

When I try to add the testfile.csv as a input by using csvdatasetconfig element,by giving the relative address as ./testfile.csv,the test plan works inside the jmeter ui,but when i it run from my maven project the testfile.csv is not found.

1

There are 1 best solutions below

1
Dmitri T On BEST ANSWER

JMeter Maven Plugin sets JMeter basedir / working directory to a very specific location, you can determine it from jmeter.log file

2023-10-11 16:58:47,475 INFO o.a.j.JMeter: user.dir  =/path/to/your/project/target/some-guid/jmeter/bin

so you need to get 4 levels up in order to get to your project directory and then navigate to target directory.

Instead of:

new File("somefile.txt")

you need to use a relative path, something like:

new File("../../../../src/test/jmeter/somefile.txt")

In general your approach seems not too good to me:

  1. First of all, using Beanshell is kind of performance anti-pattern, since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting. See Beanshell vs. JSR223 vs. Java For JMeter: Complete Showdown for more details.
  2. If there will be multiple users writing into the same file you will face data corruption/loss due to race conditions, it makes sense to consider using Flexible File Writer instead.