CSV

Write values in CSV using JMeter

Hola Testers,

On my last post we were talking about read values from csv external data source. I thought this time we should talk about write values on csv. Imagine our jmeter script is creating some number of files in our web application, and you need to know the names of those files to use it later. In this kind of scenario, we can use csv writer to keep our files name for future use.

Add a Beanshell PostProcessor for the HTTP request which creating files
Right click on HTTP request > Add > Post Processors > Beanshell Postprocessors
Screen Shot 2016-04-10 at 8.25.09 AM.png
(You may need a regular expression extractor to HTTP Request for extract the file name.)

Write a write script to write the file name on csv
You can write a simple beanshell script to write file’s name on csv. A sample script like below,

generatedDocID = vars.get("DocID");
filepath =vars.get("FilePath");
f = new FileOutputStream(filepath, true);
p = new PrintStream(f);
this.interpreter.setOut(p);
print(generatedDocID);
f.close();

Where “DocID” is the variable we used in regular expression extractor and “FilePath” is the variable name for the csv filepath/name. That variable you can initialise in user defined variables. 🙂

Read values from CSV using JMeter

Hola Testers!

What would you do if you have to test dynamic values for a specific test field. For example you have to test login for N number of users. How do you use Jmeter for that? Today I’m going to tell how to deal with that kind of situation.

For above kind of a scenario, you can use an external data source to keep your test data. Jmeter support with CSV files greatly. SO we’ll use a CSV file to demonstrate this. Let’s take a scenario. I’m taking login scenario for alfresco. So, in order to log, you need username and password. That are our test data. Let’s create test data in CSV.

CSV Test Data
In our scenario we need to store username and password in CSV. I already created 4users with admin in alfresco. Now we’ll create a CSV file.
You can create a CSV in two ways
With heading
Without heading

You can use either with heading or without heading. Then save this file as a .csv

Add CSV Configuration file to Jmeter projet
Right click on the Test Plan > Add > Config Element > CSV Data Set Config
Screen Shot 2016-04-04 at 2.01.53 PM.png

Configuration CSV Config Element
Open “CSV Data Set Config”
Filename: CSV doc path with csv filename
If you write csv with heading, this is enough
Screen Shot 2016-04-04 at 2.09.05 PM.png

If you write csv without heading, then you need to add “Variable Names” for the values with separate by comma(,)
Screen Shot 2016-04-04 at 2.10.54 PM.png

Add parameters to the HTTP request
As we set our variables as “username” and “password”, we need to replace the HTTP request’s send parameters like ${username} and ${password}
Screen Shot 2016-04-04 at 2.17.27 PM.png

Now save the project and run again 🙂