Cyrine
Cyrine

Reputation: 185

testing a curl request with jmeter

I have a curl request and i don't know how to transform it in jmeter :

curl -H application-id:my-app-id \
     -H secret-key:my-secret-key \
     -H Content-Type:"multipart/form-data" \
     -H application-type:REST \
     --form upload=@/logo.jpg \
     -X POST \
     -v \
     http://localhost:8080/api/v1/files/Photos/logo.jpg

What is the best way of doing this?

Upvotes: 13

Views: 23508

Answers (3)

thangdc94
thangdc94

Reputation: 1632

For JMeter 5.1 or higher. There is an easier solution for creating test plan from curl just like in Postman

ToolsImport from curl → Paste your curl into the box → Create Test Plan

In some older version, the path can be:

HelpImport from curl → Paste your curl into the box → Create Test Plan

Upvotes: 9

Dmitri T
Dmitri T

Reputation: 168092

Option 1: Record the request

In JMeter:

  1. File -> Templates -> Recording -> Create
  2. Workbench -> HTTP(S) Test Script Recorder -> Start

In console:

 curl -x localhost:8888 -H application-id:my-app-id ......

Option 2: Building Request Manually

  1. Add HTTP Request sampler and configure it as follows:

    • Server Name: localhost
    • Port Number: 8080
    • Method: POST
    • Path: /api/v1/files/Photos/logo.jpg
    • Check Use multipart/form-data for POST
    • Switch to "Files Upload" tab
    • Click "Add" and provide full path to logo.jpg file, upload as Parameter Name and image.jpg as MIME Type
  2. Add HTTP Header Manager and provide your headers names and values there


References:

  1. curl man page
  2. JMeter Proxy Step by Step
  3. How to Save ‘Loads’ of Time Using JMeter's Template Feature

Upvotes: 8

Suman g
Suman g

Reputation: 477

Simple .

  1. Create a Thread group .

    RightClick on TestPlan --> Threads-->Thread Group

  2. Add a HTTP Header manager add all Header entries

    Right Click on Thread Group Created in Step1 --> Add-->ConfigElement-->HTTP Header Manager and add all[ -H application-id:my-app-id -H secret-key:my-secret-key -H Content-Type:"multipart/form-data" -H application-type:REST] Note: here you dont have to append -H

  3. Add a HTTP sampler

    Right Click on the ThreadGroup Created in Step1 --> Add-->Sampler-->HTTP Sampler provide ServerName or IP = local host and Port= 8080 and in Path =/api/v1/files/Photos/logo.jpg and method = post and There is add section for send files add accordingly

  4. Add a Listener to verify the requests

    Right Click on ThreadGroup created in Step1 --> Add-->Listener--> View result tree

By the end your Jmeter script should like

TestPlan
  ThreadGroup[threads =1 loopcount=1]
    HTTP HeaderManager
    HTTPSAmpler
    View Result Tree

Happy Testing . for more information http://jmeter.apache.org/usermanual/component_reference.html if it helps dont forget to click answered.

Upvotes: 3

Related Questions