JMeter - testing unique links taken from CSV file - testing

I want to test unique link taken from csv file in Jmeter. I have a csv file with unique values - "value 1", "value 2" .....
For each thread, I need to append it as part of url(or path).
Ex: BaseURL: example.com
For thread 1, example.com/value1
For thread2, example.com/value2
How can I do this in JMeter? Any help will be highly appreciated. I have created CSV and all. Just need to know how to take that value and set as part of path.

Put your "base url" into "Server name or IP" tab of the HTTP Request Defaults:
Configure CSV Data Set Config to read the values from the file and store them into a JMeter Variable
Use the variable from the step 2 in "Path" field of the HTTP Request sampler:
That should be it, each thread will read the next value from the CSV file on each iteration:
Demo:

In CSV Data Set Config add path as Variables Names, use Sharing mode All Threads
In HTTP Request Path field add ${path}
Each thread will send a different path taken from CSV line

Related

How to parameterize values in the csv file which is already parameterized in Jmeter

I have multiple API request bodies and Im passing them using txt file in CSV Data Set Config. This API request bodies have certain values to parameterize. How Do I acheive this? something like paramertize inside parameterized csv file.
If your CSV file contains JMeter Functions or Variables which you want to evaluate in the runtime you need to wrap the variable(s) defined in the CSV Data Set Config into __eval() function
For example if you have:
test.csv file with the single line containing ${foo} and CSV Data Set Config reading this file into some-variable
User Defined Variables which assigns the variable foo the value of bar
And a couple of Debug Samplers for visualization
You will see that:
${some-variable} will return ${foo}, basically the line from the CSV file
${__eval(${some-variable})} will return bar because the variable will be evaluated and its respective value will be resolved.

is there a way to start to read where we stop in CSV Data Set Config in JMeter?

I have created a test that reads the users from a CSV Data Set Config in JMeter.
For example when i run a test, JMeter reads first 20 users in the CSV file.
Then if i will run the same test again, JMeter again reads the first 20 users in the CSV file.
But i want JMeter to read 20 users but must start the reading from 21st user, and so on.
Is there a way to make this possible?
As per CSV Data Set Config documentation:
By default, the file is only opened once, and each thread will use a different line from the file. However the order in which lines are passed to threads depends on the order in which they execute, which may vary between iterations. Lines are read at the start of each test iteration. The file name and mode are resolved in the first iteration.
So there is no way to specify the "offset" for reading the file, the options are in:
Use __CSVRead() function where you can call ${__CSVRead(/path/to/your/file.csv,next)} as many times as needed to "skip" the lines which are already "used"
Use setUp Thread Group and JSR223 Sampler to remove first 20 lines from the CSV file programmatically
Go for Redis Data Set config instead where you have Recycle Data on Use option, if you set it to False the "used" data will be removed

Jmeter dynamic URL property with variable not substituted

I have a simple Jmeter test where I have a property to set the URL. The PATH in the Jmeter test is set to the following.
${__P(GET_URL,)}
This works well for all URLs that I have been working with, except for the ones where I need to pass a variable in the URL component.
For example, it works for http://server:port/getemployeelist when I run the test with -JGET_URL=/getemployeelist
Then I created a CSV config element to populate the variable EMP_ID.
Then if I run the test with -JGET_URL=/getemployee/${EMP_ID}, the EMP_ID variable is not getting substituted. Jmeter test gives me an error as follows:
java.net.URISyntaxException: Illegal character in path at index xx: https://://getemployee/${EMP_ID}
Appreciate any help/pointers.
It will not work this way, JMeter doesn't know anything about ${EMP_ID} at the time it is being started, you need to append this ${EMP_ID} to HTTP Request sampler "Path" in the runtime
Start JMeter as:
jmeter -JGET_URL=/getemployee/
Use CSV Data Set Config to read the EMP_ID from the CSV File
In the HTTP Request sampler use construction like /${__P(GET_URL,)}/${EMP_ID} to combine JMeter Property specified via -J command line argument and JMeter Variable originating from the CSV file.
If anything goes wrong first of all check jmeter.log file - it normally contains enough troubleshooting information. If there is nothing suspicious - use Debug Sampler and View Results Tree listener combination to inspect requests and response details, variables and properties names and values, etc.
Had asked this question a while back. Thought of posting the solution which I eventually ended up implementing. In the solution, I created a template jmx with a substitution variable for the HttpSampler.path and then replace the path at runtime. Following are the key points from the scripting done.
This turned out to be a simpler solution that worked for all kinds of API call patterns.
Created a template jmx (jmeter_test_template) with the following line.
<stringProp name="HTTPSampler.path">#PATH#</stringProp>
This jmx has CSV config element to populate variable "EMP_ID". To create this file, just create a new test with any URL and then save it as a template and replace the URL with substitution variable #PATH#.
Created a wrapper script like run_any_api.sh with usage,
sh run_any_api.sh URL=http://server:port/myapp/employees/${EMP_ID}
In the wrapper script, this URL is replaced in place of the token.
sed "s/#PATH#/$URL" jmeter_test_template.jmx > jmeter_test_template.current_test.jmx
jmeter -t jmeter_test_template.current_test.jmx
Last but not the least, please remember to cleanup the temporary jmx,
rm jmeter_test_template.current_test.jmx

Upload csv files with comma inside it

As per my requirement, I need to upload a .csv file into the application. I am trying to simulate this using loadrunner. The issue I am encoutering is that my csv file is in the below format
Header - AA,BB,CC
Data-xyz,"yyx,zzy",xxz
On using the below statement to upload the file, I am getting an error ""line 2 contains 4 columns instead of 3"
web_submit_data("upload",
"Action=xxx/upload",
"Method=POST",
"EncType=multipart/form-data",
"RecContentType=text/html",
"Referer=xxx",
"Snapshot=t86.inf",
"Mode=HTML",
ITEMDATA,
"Name=utf8", "Value=✓", ENDITEM,
"Name=token", "Value={token_1}", ENDITEM,
"Name=upload_file", "Value={NewParam_5}", "File=yes", "ContentType=text/csv", ENDITEM,
"Name=Button1", "Value=Upload", ENDITEM,
LAST);
AS per information provided in How to deal with a string with comma in it from a csv, when we have to read the data by using loadrunner? ,
I tried updating the .prm file to a new delimiter pipe, | but still i get the error.
[parameter:NewParam_5]
Delimiter="|"
ParamName="NewParam_5"
TableLocation="C:\temp"
ColumnName="Col 1"
I also notice that even though I set the delimiter to pipe, if I rightclick on the web_submit_data() and go to Parameter properties, i see a column delimiter option there as well and it is not set to pipe and is set to comma which indicates that this setting is taking higher precedence to the setting in .prm file.
Can someone please guide me the right way to set a new delimiter so that vugen recognizes and parses the csv file as I want it to.
I am using loadrunner 12.5
Thanks for your help.
Do you need to upload a file or a line of comma separated variables? Right now you appear to be reading a line of CSV variables, not a file as your parameter file would contain a list of filenames or a single file reference within the directory of the virtual user (extra files, transferred with the use) or created by the virtual user and then uploaded.

How to upload image through JMeter?

I have a website which needs to upload multiple images at a time. So I want to know what is the process of posting image file through JMeter?
You'll need the following:
In HTTP Request Sampler:
Select "POST" method from drop-down.
Check "Use multipart/form-data for POST" box
Provide correct input name, MIME type and path for the file to be uploaded.
See Upload and Download Scenarios with Apache JMeter guide for more details.
If you need to upload multiple images best option is to go for a CSV Data Set Config element in Jmeter.
First, add the full path of the images you want to upload comma separately in a file (.csv) as below.
eg: D:\User\Images\img1.png,D:\User\Images\img2.png
Then, add a CSV Data Set Config element most preferably to the top of the script
Next, configure the below elements in the CSV Data Set Config element
Filename: full path to the csv file
Variable names: “column name” in the csv file if you have added one or any variable name if you don't have a column name (eg: images)
Note: Make sure to change the delimiter and other optional parameters as required.
Finally, in a HTTP Request you can use the parameter ${images} to call the images. The CSV Data Set Config element will read the image names from the CSV file and set them in the variable called "images".
Refer the below guide for more information.
https://www.blazemeter.com/blog/how-test-image-upload-functionality-jmeter