PreProcessor and PostProcessor in JMeter

A processor is used to modify the Samplers in its scope.

There are two types of processors :

  • Pre-processor : Pre-processor executes some action before making a Sampler Request.
  • Post-processor: Post-processor executes some action after making a Sampler Request.
The following Example demonstrates the Pre-Processor and Post-Processor.
  • Open the JMeter and then add Thread Group to the Test Plan.
  • Next, add HTTP sampler request to the Thread Group and enter the www.google.com in the Server IP address.
    http-request-with-goole-address-jmeter
  • Next, add View Result Tree sampler to the thread group.
  • Now save and run the Test Plan, after the execution, the request has been executed.
    execution-of-http-request-jmeter
  • Now, what I wanted to do is, I want to perform some other actions before executing the current request. So for that, I need to add User Parameters to the Thread Group.
    add-user-parameter-pre-processor-jmeter
  • Now entering one parameter and specify the name of that parameter as below(To enter the parameter, click on Add Variable)
    creating-parameter-jmeter
  • The Calendar Parameter will execute before the HTTP Request, so I am using this parameter in the HTTP request.
  • Mention the /${param} in the HTTP request as below.
    enter-param-in-http-request-jmeter
  • Save and run the Test Plan, After the execution, open any HTTP request in the View Result Tree, you can see that the HTTP request uses the variable which we mentioned in the User Parameters.
    view-result-tree-in-http-request-jmeter
  • Next, we need to have a Post Processor.
  • Here I am adding Result status Action Handler post-processor to the thread group.
    reault-status-action-handler-jmeter
  • Whatever the actions which we select in the Result Status Action Handler, Post Processor will be executed after the execution of the HTTP request.
    result-status-action-action-handler-jmeter
  • If any user Parameter goes wrong, then the post-processor will stop execution if we select the stop test now.
  • Select the Number of Users as 5, ramp-up period as 1, and loop count as 5.
  • And then enter the wrong parameter in the User Parameters as /calendar123
    enter-wrong-parameter-jmeter
  • Now save and run the Test Plan.
  • We have given the wrong parameter, so the First request itself will fail so the execution will be stopped.
    execution-og-request-has-been-stopped-jmeter
  • In this way, you can select any actions in the post-processor and execute the pre-processor and post-processor.

Assertions in JMeter

How to Test FTP Upload and Download

To Demonstrate an FTP upload and Download we need an FTP website where we should have access. I have a sample FTP website where everybody can have access.

Once you navigate to that website, you will find the below page: ftp-test-website-jmeter

  • On the above page, we have a username and password, by using these details we can connect to the FTP website.
  • We can connect to the FTP site either by using a WinSCP client or Filezilla.
  • I am connecting using WinSCP.
  • Before that download and Install WinSCP in your system.
    installing-winscp-in-system-jmeter
  • After the successful installation of WinSCP, you will find the login page as below.
    winscp-login-page-jmeter
  • Click on the file Protocol and select FTP.
    select-ftp-from-file-protocol-jmeter
  • Next, enter the Hostname which is present in the dlptest website, and enter the given username and password.
    click-on-login-button-jmeter
  • Click on the Login button.
  • Once you click on the Login button, WinSCP will connect to the FTP.
  • Here you can drag and drop files from Local system to FTP or From FTP to Local System.
  • Let us go to the JMeter and we need to enter some connection details.
    add-ftp-request-to-thread-group-jmeter
  • Next, you need to enter all the connection details on the FTP page as shown below. Enter the Server name as ftp.dlptest.com.
    server-name-in-jmeter
  • Next, go to the WinSCP and create a new file by clicking on the New.
    creating-new-file-jmeter
  • After creating a new .txt file, enter some texts inside the text file as shown below.
    text-txt-file-created-jmeter
  • After creating a file, go to the remote file location and refresh WinSCP, you will find the Text.txt file as below.
    test-txt-file-inside-winscp-jmeter
  • Next, go to the JMeter and enter the file name in the Remote File and then enter the Local file location followed by a newly created file name in the JMeter, and enter the Username and Password of the FTP account.
    ftp-request-details-jmeter
  • These are the details which we have to give in the JMeter, Save the test plan.
  • Next, add View Result Tree listener to the Thread Group.
  • Save and Run the Thread Group, after successful execution the test.txt file has been downloaded to our local system.
    successfull-execution-of-ftp-request-jmeter
  • The Test.txt file has been downloaded in the given location.
    test-file-present-in-local-system-jmeter

Challenges I have faced in this while Downloading the File from WinSCP to Local System is:

  • Sometimes the local drive does not support them to access remote file locations, in that case, change the local system location.

Uploading File to FTP Server with JMeter

  • Delete the Test.txt file which is present inside the remote location.
    deleting-test-txt-file-in-remote-location-jmeter

  • Go to the JMeter and select the put(STOR) in the FTP request and then save and run the thread group.
    select-put-location-inside-the-FTP-request-jmeter
  • After the successful execution, the Test.txt file will be uploaded into the remote location.
    test-txt-file-has-uploded-inside-remote-location-jmeter

Save File Response With FTP in JMeter

  • In the same way, you can save the file in the Response by selecting the Save file Response option in the FTP Request inside the JMeter.
  • Delete the test.txt File in the Local system and then select the Get option in the FTP request in the JMeter.
    delete-the-file-inside-the-local-system-jmeter
    select-get-option-and-save-file-response-jmeteer
  • Now save and run the Thread Group. After execution, the Test.txt file has been downloaded into the Local systems and then the same file has been saved inside the Response.
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions