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

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

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?

Related

Jmeter | if reponse has list it's getting null how to fix it?

I am trying to do POST data and it's getting 200. but if in response JSON data has list [] like
{
"resno":"5600123",
"inquiry": [
{
"number": "1",
"organization": "",
"name": "Amarbold",
"collateralInfo2": "0",
"description": "dadtatadada"
},
{
"number": "1",
"organization": "",
"name": "Amarbold",
"collateralInfo2": "0",
"description": "dadtatadada"
}
]
}
this then i recieved this.
{"resno":"5600123","inquiry":null}
It's working fine in Postman.
how can i fix?
Given you send the same requests you should have the same responses, double check your request payload and headers using View Results Tree listener or maybe even better an external sniffer tool like Fiddler or Burp
Once you identify and eliminate the differences - you should get the same behaviour.
Be aware that it's also possible to record the Postman's request using JMeter's HTTP(S) Test Script Recorder, if you configure Postman to use JMeter as the proxy - JMeter will intercept the request and produce the relevant HTTP Request sampler and HTTP Header Manager. See How to Convert Your Postman API Tests to JMeter for Scaling article for more information.

Azure Data Factory REST API paging with Elasticsearch

During developing pipeline which will use Elasticsearch as a source I faced with issue related paging. I am using SQL Elasticsearch API. Basically, I've started to do request in postman and it works well. The body of request looks following:
{
"query":"SELECT Id,name,ownership,modifiedDate FROM \"core\" ORDER BY Id",
"fetch_size": 20,
"cursor" : ""
}
After first run in response body it contains cursor string which is pointer to next page. If in postman I send the request and provide cursor value from previous request it return data for second page and so on. I am trying to archive the same result in Azure Data Factory. For this I using copy activity, which store response to Azure blob. Setup for source is following.
copy activity source configuration
This is expression for body
{
"query": "SELECT Id,name,ownership,modifiedDate FROM \"#{variables('TableName')}\" WHERE ORDER BY Id","fetch_size": #{variables('Rows')}, "cursor": ""
}
I have no idea how to correctly setup pagination rule. The pipeline works properly but only for the first request. I've tried to setup Headers.cursor and expression $.cursor but this setup leads to an infinite loop and pipeline fails with the Elasticsearch restriction.
I've also tried to read document at https://learn.microsoft.com/en-us/azure/data-factory/connector-rest#pagination-support but it seems pretty limited in terms of usage examples and difficult for understanding.
Could somebody help me understand how to build the pipeline with paging abilities utilization?
Responce with the cursor looks like:
{
"columns": [
{
"name": "companyId",
"type": "integer"
},
{
"name": "name",
"type": "text"
},
{
"name": "ownership",
"type": "keyword"
},
{
"name": "modifiedDate",
"type": "datetime"
}
],
"rows": [
[
2,
"mic Inc.",
"manufacture",
"2021-03-31T12:57:51.000Z"
]
],
"cursor": "g/WuAwFaAXNoRG5GMVpYSjVWR2hsYmtabGRHTm9BZ0FBQUFBRUp6VGxGbUpIZWxWaVMzcGhVWEJITUhkbmJsRlhlUzFtWjNjQUFBQUFCQ2MwNWhaaVIzcFZZa3Q2WVZGd1J6QjNaMjVSVjNrdFptZDP/////DwQBZgljb21wYW55SWQBCWNvbXBhbnlJZAEHaW50ZWdlcgAAAAFmBG5hbWUBBG5hbWUBBHRleHQAAAABZglvd25lcnNoaXABCW93bmVyc2hpcAEHa2V5d29yZAEAAAFmDG1vZGlmaWVkRGF0ZQEMbW9kaWZpZWREYXRlAQhkYXRldGltZQEAAAEP"
}
I finally find the solution, hopefully, it will be useful for the community.
Basically, what needs to be done it is split the solution into four steps.
Step 1 Make the first request as in the question description and stage file to blob.
Step 2 Read blob file and get the cursor value, set it to variable
Step 3 Keep requesting data with a changed body
{"cursor" : "#{variables('cursor')}" }
Pipeline looks like this:
pipeline
Configuration of pagination looks following
pagination . It is a workaround as the server ignores this header, but we need to have something which allows sending a request in loop.

Jmeter extracting response multiple id from array

I am traying the extract the term-id- id value -200000000326 from the below response. controlled-term can have multiple term-id, I have tried with Json extractor $..controlled-term.[[term-id]].[id] and [Thursday 12:22 PM] G, Shwetha C
$..term-id[id]
but this is returning null. can you please help
enter code here:
{
"controlled-terms": {
"controlled-term": [
{
"term-id": {
"id": "200000000326"
},
"term-names": {
"term-name": [
{
"lang": "en",
"name": "All"
}
]
}
}
]
}}
For particular that JSON you provided the relevant JSONPath query would be something like:
$.controlled-term.*.term-id.id
If you need to extract particular ID which is related to some other attribute value - you will have to provide the full JSON response and specify the data relationships.
I would also recommend considering switching to JSON JMESPath Extractor mainly because it has official specification (JSONPath implementations are lacking it so query which works for one implementation may fail for another). Moreover JMESPath language is more powerful and provides a lot of functions and operators which can make your life easier. More information: The JMeter JSON JMESPath Extractor and Assertion: A Guide

JSON path for contains

I have the below json
{
"swagger": "2.0",
"info": {
"version": "v2",
"title": "Portfolio"
},
"host": "portfolio.com",
"schemes": [
"https"
],
"paths": {
"/v2/clients/{clientId}/assets": {
"get": {
"tags": [
"assets"
There are multiple paths I want to extract but they all start /v2/clients so what Im looking for is everything that starts with /v2/clients but none of the sub-data that sits the below, just the full paths between the ""
I am using jmeter JSON extractor and if I use $.paths it starts at this point but brings through all the mass amount of sub-data. I've tried looking around stackoverflow but can't find exactly what I am looking for. Any help appreciated
I believe the easiest would be going for JSR223 PostProcessor and Groovy language
Add JSR223 PostProcessor as a child of the request which returns above JSON
Put the following code into "Script" area:
def index = 1
new groovy.json.JsonSlurper().parse(prev.getResponseData()).paths.each { path ->
if (path.getKey().startsWith('/v2')) {
vars.put('path_' + index, path.getKey())
index++
}
}
That's it, you will have JMeter Variables like:
path_1=/v2/clients/{clientId}/assets
path_2=/v2/foo/bar
path_3=/v2/baz/qux
etc.
More information:
JsonSlurper
Apache Groovy: Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

Wiremock Standalone with Dynamic response

I have a standalone instance of Wiremock server. The mappings are stored as json files under the mappings folder. I have a POST request that needs to return a dynamic ID(integer) in the response. Is there a way to configure this in the json file?
To make the above examples work, I had to run the standalone jar with the --global-response-templating. Then I saw, for example, {{now}} working which is what I wanted. Not sure if the documentation specifies this -- I tried the always-useful --help.
In WireMock there are a number of response template helper functions for generating random strings. In the below example I'm using the one for generating a UUID, but several other options exist.
Mapping file: dynamic_id.json
{
"request": {
"method": "POST",
"url": "/dynamic_id"
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"status": 200,
"body": "{{randomValue type='UUID'}}",
"transformers": ["response-template"]
}
}
Using an empty POST http://wiremock/dynamic_id will return an id similar to: c2e6bf32-c9a3-45c0-b988-94fad04cc7a2.
Start WireMock:
java -jar wiremock-standalone-2.18.0.jar --port 8181 --verbose --local-response-templating
This seems like a perfect use-case for OpenTable's Wiremock Body Transformer.
It can be easily integrated with the Standalone Server like this:
java -cp "wiremock-body-transformer-1.1.6.jar:wiremock-2.3.1-standalone.jar" com.github.tomakehurst.wiremock.standalone.WireMockServerRunner --verbose --extensions com.opentable.extension.BodyTransformer
And allows you to easily specify a dynamic variable that you would want to match in the response.
Here is an example to get a random integer without having to specify anything in the request, however if you need to match a specific variable in the request to the response, then that is also very doable with this extension and numerous examples can be found in the readme.
{
"request": {
"method": "POST",
"urlPath": "/transform",
},
"response": {
"status": 200,
"body": "{\"randomInteger\": \"$(!RandomInteger)\"}",
"headers": {
"Content-Type": "application/json"
},
"transformers": ["body-transformer"]
}
}
As #Jeff mentions, If you are running it as a stand-alone process, you need to add this flag --global-response-templating. This will apply templating to each and every reponse. However, few of your responses may be jsut plain json with no templating required.
In that case use --local-response-templating. and add this field inside reponse json:
response:{
"transformers": ["response-template"]
}

Resources