Use result from jdbc request for the next request - jdbc

I am using JDBC to query on azure sql in JMeter. I was able to successfully get the response. see below
otp
100940
In the Result variable name the value is OTP
My next step in Http request POST method, see below
{
"id": ${requestId},
"otp": "${OTP}",
"requestId": "123456"
}
as you can see otp is parameterized.
But in actual request see below;
POST data:
{
"id": 506,
"otp": "[{otp=100940}]",
"requestId": "123456"
}
how can I concatenate so that I only get the actual otp value without the [{otp=}]

You can add Regular Expression Extractor to extract number from OTP variable
Choose Apply To: JMeter Variable and write OTP and use regular expression as:
otp=(\d+)
And use Template $1$ and Match No. 1
JMeter Variable Name to use - extraction is to be applied to the contents of the named variable

If your response is this otp 100940, use below Regular Expression to extract it:
Now, you can use anywhere OTP value using ${OTP} variable
{
"id": ${requestId},
"otp": "${OTP}",
"requestId": "123456"
}

Related

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

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?

How to send query parameters for gmail api for list_user_messages?

I am trying to send query parameters to fetch list of messages via gmail api https://developers.google.com/gmail/api/reference/rest/v1/users.messages/list
Here is my code
message_list = gmail.list_user_messages user_id
It returns the message list
response -
"messages": [
{
"id": "16641115eca503dc",
"threadId": "16641115eca503dc"
},
Now I want to pass the query parameters
params = {userId: 'me',
maxResults: 1,
pageToken: pageToken}
message_list = gmail.list_user_messages(params)
But it is not working as expected. Please share the correct way to add query parameters.
Go to documentation. Use 'Try this API' option and there you can learn about query params like 'is:unread' ,'from:some#abc.com' etc.
If you want to know about more about valid query strings like 'is:unread' then you can use gmail search options and generate valid query strings.
Edit: Search operator documentation

Which controller to use in Jmeter?

I want to create a controller that should run a till the condition fails. How it can be implemented in Jmeter.
The controller should contain a HTTP Request with a post body which is dynamic the request should continue till the condition fails,but i dont know where the should i apply that condition.
{
"access": {
"identifier": "9876f",
"Reproduce": "Right",
"possible": {
"id": "u7ur038",
"value": "Move"
}
}
}
If the response "Reproduce" contain "Right"then it should run again HTTP Request for new body and If the response "Reproduce" contain "Wrong"then it should stop executing.
You can use a While Controller which will contain your request.
Condition of While Controller will be:
${__jexl3("${response}" != "Wrong")}
Add as child of your HTTP Request a JSON Extractor:
Names of created variables: response
JSON Path Expressions: $..Reproduce
Match No.: 1
To reset variable for next thread loop iteration, add before While Controller a Flow Control Action and put inside it a preprocessor called User Parameters .
Click « Add Variable » and set :
Name: response
User_1: Right

How to correlate drop down list

I have a response like below-
"distributionChannelList":[
{
"id":1,
"description":"Agency1"
},
{
"id":5,
"description":"Agency2"
},
{
"id":4,
"description":"Agency3"
},
{
"id":3,
"description":"Agency4"
}
],
"marketingTypeList":[
{
"id":1,
"description":"Type1".......
There are so many 'id' and 'description' values in my response. Agency1, Agency2.. are drop downs in my application.
So I want Jmeter to pick a different agency every time and pass in subsequent requests.
How to achieve this?
Use json extractor or reg Ex to fetch all the description with Match No. as 0 for random. Pass the Json created variable to the next request like ${varDescription}. On every run, random value will be fetched and provided to the next request.
Below snapshot is an example for regex but prefer json in your case. For fetching with json use $..description as json path expression. Repeat the same for others if required.
Hope this helps.
Update:-
Please check the below config. It will extractor 2 values in sync. But, ${cnt} should be same value. I have used counter just for demo. You can use random function to generate value between 1 to 4 and pass that variable ${rnd};${rnd}.

ServiceNow REST API: return single column

Is there a way to perform a REST call to ServiceNow REST API that returns a single column of a table? I would like to query the server table for only the names of the servers and not have the entire record containing some 50 plus fields returned.
The latest REST Table API (as of Eureka, I think) supports the parameter sysparm_fields, which allows you to specify a comma-delimited list of fields to include in the response:
This URL template:
https://YOURINSTANCENAME.service-now.com/api/now/v1/table/incident?sysparm_fields=number,short_description,caller_id.name
Would give you a result with something like:
{
"result": [
{
"caller_id.name": "",
"short_description": "Unable to get to network file shares",
"number": "INC0000002"
}
]
}

Resources