简体   繁体   中英

How to upload file in a JSF application using JMeter

I've been asked this time to also create a test script for file upload in a JSF application using JMeter. The generated script from blazemeter is as follows:

generated script for input form

The encircled value is the file name. I have noticed that the parameter was not created under "Files Upload" tab, so I have also tried to move the parameter to File Upload tab, using the generated content type in our application logs when uploading as Mime Type in JMeter:

Jmeter file upload tab

Generated content type

But it has the same result when I first tried the script where the file name parameter was still under "Parameters" tab (file name is null according to localhost application logs):

Application log indicating that file name is null

The UI of the file upload is this. The user clicks browse button, picks a file then the name of the file is displayed in the input field (Import File). The user would then click the Import button to submit the form:

File upload UI

Am I missing a step or doing something incorrectly?

Thank you in advance! Any help would be greatly appreciated.

Your way of building a file upload request might be wrong, if you want to continue manual experiments I would recommend comparing requests which are being sent by JMeter and the real browser using a sniffer tool like Wireshark . Apart from ${VIEWSTATE} the requests should be exactly the same.

An easier option would be just re-recording the request (you can record only one single request) using HTTP(S) Test Script Recorder .

  1. Prepare JMeter for recording. The easiest way of doing this is using JMeter Templates feature

    • from JMeter main menu choose File -> Templates -> Recording and click "Create"

      在此处输入图片说明

    • expand HTTP(S) Test Script Recorder and click "Start"

      在此处输入图片说明

  2. Prepare your browser for recording, refer your browser documentation in order to set up proxy using localhost as the proxy host and 8888 as the proxy port, the proxy needs to be set for all protocols with no exclusions . The relevant configuration for Mozilla Firefox (the only free and open source popular browser, moreover it has separate proxy configuration which does not derive from the operating system) would be:

    在此处输入图片说明

  3. Copy the file you will be recording to the "bin" folder of your JMeter installation . If you omit this step JMeter will not be able to properly record the request. See Recording File Uploads with JMeter article for more details if needed
  4. Execute the request in browser - the relevant HTTP Request sampler will be generated under the Recording Controller

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM