Jmeter 5.3 + Taurus 1.16. Correctly insert property from YAML file to HTTP request

268 views Asked by At

My current test suite requires me to send some HTTP POST requests to API, some of which require specific objects to be posted via HTTP Request. I encountered some problems when trying to fetch those object from my YAML file when running Jmeter in Taurus.

I will attach part of my YAML file here for context (had to delete of change some properties for confidentiality):

  jmeter:
    properties:
      number.of.users: 1000
      rampup.period: 300
      loop.count: 1
      client.id: "23id"
      array.of.clients: ["id1","id2","id3"]
      ids: [1,2,3]
      rq:
        - "number": "7312sa1"
          "signed": "2020-06-08T00:00:00.000+0000"
          "crmClientId": "1-32D1P"

The problem is: when I try to pass string properties to my HTTP Request like that:

{
    "id": 1986,
    "jsonrpc": "2.0",
    "method": "method",
    "params":
      {
        ${__P(rq,)}
      }
}

all properties are wrapped in single quotation marks which causes request to receive error 400 in return because request after acquiring property is looking like this:

{
    "id": 1986,
    "jsonrpc": "2.0",
    "method": "method",
    "params":
      {
        'rq':
          'number': '7312sa1'
          'signed': '2020-06-08T00:00:00.000+0000'
          'crmClientId': '1-32D1P'
      }
}

Is there a way to pass string properties to request with double quotation marks or structure my YAML file in a way, which will construct request according to this example:

{
    "id": 1986,
    "jsonrpc": "2.0",
    "method": "method",
    "params":
      {
        rq:
          "number": "7312sa1"
          "signed": "2020-06-08T00:00:00.000+0000"
          "crmClientId": "1-32D1P"
      }
}

I tried using groovy replaceAll() method but it doesn't work with complex objects. My only solution as of right now is running some sort of groovy script in setUp thread and then acquire them is HTTP request via groovy jmeter function

1

There are 1 answers

1
Dmitri T On BEST ANSWER

You're sending a string representation of Python's dictionary, you need to send it as a simple string.

Check out YAML Multiline Strings and choose the most convenient option for you.

Example usage:

modules:
  jmeter:
    properties:
      rq: >
        \n"number": "7312sa1"\n
        "signed": "2020-06-08T00:00:00.000+0000"\n
        "crmClientId": "1-32D1P"\n

Taurus is presumably built to make testers and/or devops lives easier, it doesn't seem that it's your case, perhaps you should consider switching to JMeter without any wrappers instead?