Azure Load test preview unable to read data from parameterized CSV file in JSR223 Sampler - jmeter

I used JSR223 Preprocessor to create the request body for a POST JSON request. I used Groovy language for it The code has some parameterization so, I mentioned the path for CSV file in the script as below and attached the Order.csv file to the test plan in load test preview.
CSV file path in the script:
"List lines = new File("Order.csv").readLines()"
So whenever I run the test in Azure load test preview, the is the error message im encountering:
javax.script.ScriptException: java.io.FileNotFoundException: Order.csv (No such file or directory)
How can I fix this. Please Help.
I tried just mentioning the CSV file name in the code and attached the CSV file to the Load test preview along with .jmx file.
This is throwing error saying, File not found

How do you know where guys from Microsoft are placing the CSV file and why do you expect them to copy it to the same place where the .jmx script lives?
I would suggest amending your Groovy script to get the file location dynamically using FileServer class, i.e. change this line:
List lines = new File("Order.csv").readLines()
to something like:
List lines = new File(org.apache.jmeter.services.FileServer.getFileServer().getBaseDir() + File.separator + 'Order.csv').readLines()
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

Related

Can we rename the file name in Jmeter during run time which will be uploaded in the script

I have to upload audio files in the Jmeter script which is stored in my system. E.g. abc.wav is the file store in the system. But in the script the file name format should be "Testinstanceid__itemid__ interactionid.wav". Here "Testinstanceid" is the dynamic value which we can get from correlation of previous response.
But how I can upload the file with this dynamic value during run time and it will upload correctly in the script.
Thanks in advance
You can copy your abc.wav file to the Testinstanceid__itemid__ interactionid.wav file using JSR223 PreProcessor and Groovy script like:
org.apache.commons.io.FileUtils.copyFile(new File('abc.wav'), new File(vars.get('Testinstanceid') + '__itemid__ interactionid.wav'))
once you finish the uploading you can delete the file to free up your drive in JSR223 PostProcessor like:
org.apache.commons.io.FileUtils.deleteQuietly(new File(vars.get('Testinstanceid') + '__itemid__ interactionid.wav'))
where vars stands for JMeterVariables class instance, check out the JavaDoc for all available functions

Jmeter: How to create HTML dashboard in jmeter using saved summary csv file

I am using following command to generate HTML dashboard:
jmeter -g C:/Users/E01659/Desktop/feb28/feb28_10_3600.csv -o C:/Users/E01659/Downloads/apache-jmeter-5.1/bin/sonali/
Following error is coming: File
'C:\Users\E01659\Desktop\feb28\feb28_10_3600.csv' does not contain the
field names header, ensure the jmeter.save.saveservice.* properties
are the same as when the CSV file was created or the file may be read
incorrectly when generating report An error occurred: Mismatch between
expected number of columns:17 and columns in CSV file:11, check your
jmeter.save.saveservice.* configuration or check line is complete
errorlevel=1
From the error message, it is clear that - CSV file created earlier don't have the header as the first line. When you want to create the APDEX Dashboard from CSV file, JMeter expects that files are created with correct Save Service Configuration. You can change Result file config which are present in jmeter.propertes file.
You may need to change the line as below, so that file created has the headers name as required
jmeter.save.saveservice.label = true
The command you're using is correct, the reason of failure is mismatch of the .jtl file contents and what JMeter expects it to be.
If you got this feb28_10_3600.csv file from execution on another JMeter installation - make sure that JMeter's result save configuration on the machine where you're trying to generate the report is identical to the JMeter installation where JMeter was running.
Inspect the associated JMeter properties and amend them to for 100% match, once done you should be able to normally generate the dashboard.
If you still experience the differences update your question with first 2-3 lines of your .jtl results file.
You are receiving this error (most likely) due to a corrupt line at the end of your file. Just execute a 'tail ' to see the last few lines. Most likely, your last line is missing columns due to an abrupt stop in the test. Once you delete the problematic line, you should be able to generate the HTML report.

JMeter SMTP Sampler - is it possible to use parameterization with in "attach files" option?

am using JMeter 4.0 and I have been trying to parameterize the filename in "Attach files" option with no success. I am required to use attachments of varying sizes and with each loop a random pdf file (from the set of files saved locally in d drive) to be attached with the email.
I am using a CSV data set config for parameterization and see no issues in using the parameters in Subject line of within the Message.
However, when used with the attach files option, the JMeter test fails to execute with FileNotFoundException as the variable name is substituted as such instead of the pdf filename. Is there a solution?
Error Message: java.io.FileNotFoundException: D:\Data_Jmeter\${AttachFile}.pdf (The system cannot find the file specified)
I cannot reproduce your problem using the following settings:
Where ${path} is set via User Defined Variables on Test Plan level and resolves into "bin" folder of my JMeter installation
The same situation for ${path} variable originating from the CSV Data Set Config
So I would recommend to double check if your ${AttachFile} variable is defined, you can do this using Debug Sampler and View Results Tree listener combination

Not able to generate html report in JMeter using Commandline

I want to generate html report from the csv file that is created. I am using BlazeMeter to record the test which gives me .jmx file.
When I give:
sh jmeter -n -t /home/Annie/JMeter/vDC1.jmx -l /home/Annie/JMeter/a.csv
I am getting a csv file where there is no header.So when trying to generate a html report it shows:
File '/home/Annie/JMeter/a.csv' does not contain the field names header, ensure the jmeter.save.saveservice.* properties are the same as when the CSV file was created or the file may be read incorrectly.
I tried the solution found in:
Getting Header error in JMeter when trying to get HTML report
Its still showing the same error. However its showing the html report.
Is there anything else to be done?

In jmeter how can I create a folder dynamically?

A monthly PDF report is getting downloaded by the HTTP sampler. I'm passing the file path of this report in the prefix of 'Save responses to a file' listener which is a child of the HTTP sampler.
I'm passing the month name variable like ${month} in the file path, to create a folder dynamically as given below.
E:/Work/Monthly Productivity Report/${month}/MONTHLY_PRODUCTIVITY_REPORT_${month}_${__time(yyyyMMdd-hhmmss)}
But the script is throwing errors like unknown source or path not found. Is there any way where I can create new folder dynamically?
Add JSR223 Sampler, choose Language Java and put the code in script window:
String folder = vars.get("folder");
boolean success = (new File(folder)).mkdirs();
return success;
For each test suite run:
JMeter always created a new testresult.csv and needs a blank new folder for report. So it is good to use .bat file to dynamically create the testresult.csv and report folder using this code.
Everytime you run .bat file, you will get new result.csv e.g. TestResults-Sat_09182021_160935_94.csv and new report folder e.g. Reports-Sat_09182021_160935_94
Add below code in Run.bat and open Run.bat:
set mydate=%date:/=%
set mytime=%time::=%
set mydatetime=%mydate:=_%_%mytime:.=_%
jmeter -n -t "F:\WebsitePerformanceTest.jmx" -l "F:\TestResults-%mydatetime%.csv" -e -o "F:\Reports-%mydatetime%"
Enjoy !

Resources