JMeter

Download Files Using JMeter

Hola Testers,

Let’s talk about how to download a file from API call using JMeter. First you have to create a JMeter project by adding Thread Group, HTTP Requests and etc. Then, add a “Save Responses to a file” Listener to the download HTTP Request

  • Right click on the HTTP Request > Add > Listener > Save Responses to a file

Screen Shot 2017-03-24 at 3.41.52 PM

And Then, you can add further inputs to the save file

Filename prefix: File will download to this location (~ sign mentioned: file will download to the location where jmeter script saves in your machine)

Screen Shot 2017-03-20 at 6.42.11 PM

After run test you can see the downloaded file in the mentioned location.

Screen Shot 2017-03-20 at 6.44.32 PM

Send SOAP Request Using JMeter

SOAP (Simple Object Access Protocol) is a protocol specification for exchanging structured information the implementation of web services using XML. But how we implement this on jmeter? Yes, there are some solutions. Today I’ll show one simple way to do it.

1. Open JMeter > Add a Thread Group
2. Add a HTTP Request for the Thread Group
Screen Shot 2016-04-17 at 10.04.29 AM.png

3. Fill host, port, method and path according to your WSDL name
For example I’m using http://www.webservicex.net/country.asmx?WSDL file
My variables will be,
Host: webservicex.net
Port:
Method: POST
Path:/country.asmx?WSDL
Screen Shot 2016-04-19 at 10.41.57 AM

4. Select “Body Data” tab of the HTTP Request and add request URL with parameter
Screen Shot 2016-04-19 at 10.42.10 AM

5. Add a HTTP Header Manager to the Thread Group and add needed Header requests
Screen Shot 2016-04-19 at 10.42.24 AM

6. Add a Listener to get the results. I used “View Results Tree”
7. Save and Run the test. You can see response xml on “Response data” tab of the Listener
Screen Shot 2016-04-19 at 10.42.40 AM.png

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 🙂

 

Delete Files inside a Folder using Jmeter

Hola Testers,

After a long time I’m gonna tell you how to delete files inside of folder using Jmeter. Actually sometimes we need this trick while we are removing created test data.

Step 1:
Open JMeter. Obviously, since we are using JMeter. We need to open it first

Step2:
Add “User defined Variables” element
Right Click on the Test Plan > Add > Config Element > User Defined Variables
Screen Shot 2016-03-22 at 11.29.50 AM.png

Step 3:
Add user defined variable
Click on the “User Defined Variables” element
Click “Add” button
Give the folder path with a variable name.
Screen Shot 2016-03-22 at 11.33.23 AM

Step 4:
Add a Thread Group
Right click on the Test Plan > Add > Threads (Users) > Thread Group
Screen Shot 2016-03-22 at 11.35.10 AM.png

Step 5:
Add a request (I’m adding HTTP Request)
Right click on the Thread Group > Add > Sampler > HTTP Request
Screen Shot 2016-03-22 at 11.38.27 AM.png

Step 6:
Add a Beanshell PreProcessor for the Request
Right click on the HTTP Request > Add > Pre Processors > Beanshell PreProcessor
Screen Shot 2016-03-22 at 11.40.14 AM.png

Step 7:
Write a beanshell script to delete files inside of the folder (I’m deleting all the .csv files inside of “jmeterFolder” on my desktop)
Select Beanshell PreProcessor
Enter below script

import org.apache.commons.io.FileUtils;
List files = FileUtils.listFiles(new File("${folderPath}"), new String[]{"csv"}, true);
for (File file : files) {
file.delete();
}

${folderPath}: variable which you declare on “User Defined Variables”
Screen Shot 2016-03-22 at 11.47.19 AM.png

Step 8:
Save the script and Run.
jmac.jpg