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

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

Related

Passing relative path file name in csv config element in jmeter

I want to pass relative path file name in csv config element in jmeter.i have used ./filename.csv but the jmeter script doesn't work .I have also used ../filename.csv but jmeter script doesn't work.
Need resolution to pass relative path file name in csv config element in jmeter.i have used ./filename.csv but the jmeter script doesn't work .I have also used ../filename.csv but jmeter script doesn't work.
Relative to what?
As per CSV Data Set Config documentation:
Relative file names are resolved with respect to the path of the active test plan.
csvdata.txt and ./csvdata.txt - then these are treated as different files
If you have filename.csv in the same directory as your .jmx test plan - just use filename.csv, the ../filename.csv construction will look for the filename.csv file in the parent folder for the active test plan.
If you want to know the full path to the current base directory - look for FileServer entry in the jmeter.log file
INFO o.a.j.s.FileServer: Set new base='/this/would/be/the/base/for/relative/CSV/file/lookup'
you will see where JMeter tries to load the CSV file in the same jmeter.log file

How to read data from csv file in jmeter whose location is not fixed and might change in the future

I have a CSV File whose location is going to change later. Using Jmeter how can I still read the file even if the location change?
You can set the location of the CSV file as a JMeter property and pass it through the command line or through user.properties file
Set the file name with a property in the CSV Data Set Config element
${__P(full-path-to-file,/Users/hansi/Documents/test-data/test-data-users.csv)}
Note: A default value /Users/hansi/Documents/test-data/test-data-users.csv is set in the above screenshot.
2.Define the value
2.1 In user.properties file
full-path-to-file=/Users/hansi/Documents/test-data/test-data-users.csv
or
2.2 Set the property when JMeter test is executed from commandline
./jmeter.sh -n -t test-plan.jmx -Jfull-path-to="/Users/hansi/Documents/test-data/test-data-users.csv"
If the CSV file is going to change location then you could store the test plan which is using the file alongside it. This would maintain the context of the test plan if the CSV itself is going to be moving by storing them together. In JMeter relative file names are resolved with respect to the path of the active test plan (based on the official documentation), allowing you to specify only the name of the file in the CSV Data Set Config Filename property.

JMeter parametrization $URL

I have problem with set parametrize $url variable in Jmeter.
I must set parametrize because I will run my project test in three other URL addresses, because application is deployed for 3 others such as production, development and I also would like testing in local.
I have the following CSV file:
protocol
$url
${dev} http://10.200.XXX.XX/{$url}
${trial} trial.mycompany.io{$url}
${product} product.mycompany.io{$url}
How can I set this in JMeter, set parametrization my URL variable?
Your question is not very clear, moreover my expectation is that you shouldn't have JMeter variables reference in form of ${variable} in the CSV file, only "plain" data should go there.
With regards to running test on different servers I would go for creating 3 separate CSV files, i.e.
dev.csv with the following contents:
protocol,host
http,10.200.XXX.XX/
trial.csv with the following contents
protocol,host
https,trial.mycompany.io
product.csv with the following contents
protocol,host
https,product.mycompany.io
Once done you can add a CSV Data Set Config and set it up like:
And finally add HTTP Request Defaults to your Test Plan to read the values from the relevant CSV file:
So when you run JMeter without any parameters it will pick up dev.csv file and will go to 10.200.XXX.XX host
If you run JMeter like:
jmeter -Jenvironment=trial
it will pick up trial.csv and will go to trial.mycompany.io host
If you run JMeter like:
jmeter -Jenvironment=product
it will pick up product.csv and will go to product.mycompany.io. host
More information:
__P() function
Overriding Properties Via The Command Line

How to write Jmeter Regex into a file after extraction

In my Jmeter test, I am able to use REGEX Extraction, After extraction I want to write the value of the REGEX variable into a file
I found a workaround as using beanshell as mentioned here https://stackoverflow.com/a/15159521/4556894
Is there any clean way of doing it, May be some inbuilt features, which I am not aware of
It is possible to write variable values into JMeter .jtl results file. There is a JMeter Property called sample_variables
Optional list of JMeter variable names whose values are to be saved in the result data files.
Use commas to separate the names.For example:
sample_variables=SESSION_ID,REFERENCE
So if you run JMeter in command-line non-GUI mode as follows:
jmeter -Jsample_variables=myVariable -n -t /path/to/your/testplan.jmx -l /path/to/testresults.jtl
You'll get the output like
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,bytes,grpThreads,allThreads,Latency,"myVariable"
1425978657207,368,HTTP Request,200,OK,Thread Group 1-1,text,true,1591,1,1,367,YOUR_VARIABLE_VALUE
In above example column names are given for reference, they are not included into csv results file by default. This behavior is controllable via jmeter.save.saveservice.print_field_names property, set it to "true" to get column names printed along with results data.
You can also set sample_variables property value in user.properties file which lives under /bin folder of your JMeter installation or uncomment it in jmeter.properties file (same location)
For more information on JMeter properties and ways of setting and/or overriding them refer to Apache JMeter Properties Customization Guide

Writing to a file named with variables in distributed JMeter testing

Okay I've been having an issue with writing results to folders in JMeter.
I have set 2 variables, one for the name of the test and one for the submit date. I want the reports to be written to the folder named with these two variables.
Here's the variables:
TestRun = "Name of test"
DateRun = $__{time(dd-MMM-yyyy HH.mm.ss)}
The path of the folder to be written to looks like this:
C:\Tests\TestEnvironment\Results\\${TestRun}${DateRun}\file.csv
When I run it on the master machine, it's fine. It saves to the correct file and folder path, and ends up looking something like this:
C:\Tests\TestEnvironment\Results\Test Run 1 - 08-May-2014 08.55.47\file.csv
However, when I run it on remote machines, it saves it literally as below:
C:\Tests\TestEnvironment\Results\${TestRun}${DateRun}\file.csv
So I end up with a folder named "${TestRun}${DateRun}"
Am I missing something blindingly obvious, or is this an actual JMeter issue?
Thanks!
As per JMeter help:
-G, --globalproperty <argument>=<value>
Define Global properties (sent to servers)
e.g. -Gport=123
or -Gglobal.properties
You need to use -G key so your variables could be distributed across remote clients.
so something like:
jmeter -r -n GTestRun=SomeName -GDateRun=SomeTime -t /path/to/your/plan
should help.
Alternatively you can create a .properties file and pass it to remote JMeter Engines via the same "-G" option.
I expect that if you want to use JMeter __time() function you'll need to wrap it with __eval, elsewise it will be treated as a string. Alternatively you can use operating system commands to retrieve current date and time.
See Apache JMeter Properties Customization Guide for more information on dealing with JMeter Properties.

Resources