How can I get exatcly one row from database query for every course loop - jmeter

I creating script which let me to get values from database.
Now, when I'm executing query oracle returning me too many values.
My query looks like that : select * FROM OFFERS
I'm getting:
OFFER_NR_#=101042
OFFER_NR_1=0001G000210
OFFER_NR_10=0001G000411
and many many more...
I want to take exactly one value e.g. OFFER_NR and use it in request
------- request SEARCH_OFFER ${OFFER_NR} = 101042
During next course loop I want to take another value as variable
------- request SEARCH_OFFER ${OFFER_NR} = 0001G000210
It's just like using CSV FILE CONFIGURATION, which can give me exactly each next row for every thread group iteration, but I don't know how can I do this the same using jdbc request.

1 You need to use ForEach Controller configured as follows:
Input Variable Prefix: OFFER_NR
Output Variable Name: anything meaningful, i.e. CURRENT_OFFER
Check `Add "_" before number" box
Place your 2nd request under the ForEach Contoller
Refer each subsequent OFFER_NR as ${CURRENT_OFFER} where required
See Debugging JDBC Sampler Results in JMeter guide for more detailed explanation of your and other situations

Related

Jmeter - My response has multiple values of same id. I want to extract and pass these values incrementally to the next request

My response to a save action is somewhat like this-
"diagnosisId":45686,"confidence":0.0, --other text--
"diagnosisId":45966,"confidence":0.0,--other text-- etc. Say there are 27 diagnosis Ids.
Now i want to send request for the 1st Diagnosis Id in loop till the last id (multiple records/rows to save depending upon the diagnosis Ids).
Request is something like this -
"diagnosisId":45686,"confidence":0," etc.
I have extracted the Diagnosis Id using Regular Expression extractor and matched the first value -
"diagnosisId":(.+?),
How do I pass the values incrementally now?
Given you provide "Match No:" as -1 in the Regular Expression Extractor:
You will get the following JMeter Variables as the result (viewable via Debug Sampler):
At this stage you can add ForEach Controller and configure it like:
Input variable prefix: diagnosisId
Output variable name: anything meaningful, i.e. id
That's it, you can reference each consecutive ID as ${id} in the request(s) which will be the children of the ForEach Controller:
Another example: Using Regular Expressions in JMeter

How to use value of variable (holding integer value) from JDBC request in while loop?

I have a JDBC request to fetch row count - 'rownum' of a table. Now I need to do some additional SQL operations in separate JDBC request in which I need to extract data of only 2 rows at a time which I am able to handle using counter. Now I need to decrease the rownum by 2 as I have already used two rows of the table. So I am trying to use while loop in which I would have while rownum>0. But I . have no idea how to use the output variable of first JDBC request which will hold the integer value in while loop. I also need to subtract 2 from this in every iteration.
The output variable name of first JDBC request is "count_num"
Then I used beanshell to parse this as integer using following code:
int i = Integer.parseInt(vars.get("{count_num}").trim());
This beanshell sampler is also failing. I even tried using vars.get("count_num"), but that also failed stating ::
Error invoking bsh method: eval Sourced file: inline evaluation of: ``int i = Integer.parseInt(vars.get("count_dcn").trim());'' : Typed variable declaration
Now in my while loop, I want to use this value of I (no idea how to do it, should I be using ${i}).
I also need to subtract 2 from the value of I probably at the end of while loop (after second forEach controller maybe), again not sure how to do it.
Structure of Test Plan:
${__javaScript(parseInt(${count_dcn_1})>0)}
this code worked

JMeter: Passing Results of SQL Query as a Variable

I've been reading through the forums, the Apache JMeter guide, and BlazeMeter's The Real Secret to Building a Database Test Plan With JMeter and Using JDBC Sampler In JMeter, but I'm still kind of lost.
I need to issue a query to extract an Obj ID value from a table and pass that value into an HTTP READ Request. I've done the following setup:
JDBC Request
Variable Name: Pool-1
Query Type: Select Statement
Query: select distinct ObjId from dbo.CommonRuleSet where Name like '%ABC%';
Param. values:
Param. types:
Variable names: abcObjId
Result variable name: abcCommonRule = vars.getObject("resultObject").get(0).get("ObjId");
Query Timeout (s): 5000
Handle Result Set: Store as Object
When executed results in:
ObjId
1136682203
I'm trying to figure out how to pass in this ObjId value as a variable to append the URL.
HTTP REQUEST
database:port/applicationServer/../../crud/CommonRuleSet/????
I've tried appending using:
the Variable names value: ${abcObjId}
the Result Variable Name: ${abcResult}
Each time, JMeter is not translating the variable resulting in a parser error. (e.g., http://database:port/.../.../.../crud/CommonRuleSet/${abcResult})
I'm just not understanding how to take the results of my successful query and pass it as a variable to an HTTP Request. Any insight/enlightenment is much appreciated!
The solution was:
//database:port/.../.../.../crud/CommonRuleSet/${abcObjId_1}).
I guess I didn't go through enough BlazeMeter pages before posting my question. I found the solution on Debugging JDBC Sampler Results in JMeter.
The section explaining the difference and usage between Variable Names and Result Variable Name made all the difference. I now understand the Result Variable Name is an ArrayList of HashMaps, which I don't need in this scenario.
So I changed the Result Variable Name field from: abcCommonRule = vars.getObject("resultObject").get(0).get("ObjId"); to: result,
Next, since I want to directly access the Variable Name 'abcObjId', I modified the variable that appends my URLfrom: ${abcObjId}to: ${abcObjId_1}. I was so close... so close....
Thanks to dmitri-t and the folks at Blazemeter.

JMeter: Can't copy CSV variable into another variable

I am reading a token from a .csv file into variable CSV_ACCESS_TOKEN. I have 3 request under one ThreadGroup. I want a scenario when logged in user loads a page thrice (or N time). So 1 thread is looping N time. After reading token once, I dont want to read next token in loop but want to loop through URL three (or N) time with same token.
Right now I am reading data from CSV, and using "BeanShell Sampler" inside "Once only Controller". In the sample I am using line like: vars.put("ACCESS_TOKEN",vars.get("CSV_ACCESS_TOKEN"). But that BeanShell sampler is recorded in my Summary Result. I don't want that.
I tried using "User Defined Variable" controller and try to assign the value ${__evalVar(CSV_ACCESS_TOKEN)} but it return empty value for ${ACCESS_TOKEN}. When I use ${CSV_ACCESS_TOKEN}, it shows me the values. If I use some other variable instead of CSV_ACCESS_TOKEN in UDV controller, it assigns the value from other variable and I see values for ${ACCESS_TOKEN}.
Why CSV variable is not assigning the values in regular variable.
Thanks
Vinay
If you have 3 requests, I suggest you put a Beanshell preprocessor on the first request, which copies the CSV_ACCESS_TOKEN to ACCESS_TOKEN.
Each of your samples can the use ACCESS_TOKEN, so CSV is accessed once per cycle of 3.
Each time the preprocessor run (ie before each 1st request), CSV_ACCESS_TOKEN will get updated from the dataset.
If it is the same request, which you do not wish to duplicate, you can look into use of test fragments and modules, so you can run the same sample from a variety of controllers. First from a simple controller with the preprocessor attached, and then from a loop controller to perform 2 more requests.
I think the code you have used already to manipulate the CSV values will continue to work in this scenario.

Read a string from a file with a dynamic name in JMeter

My test plan contains a thread group that looks like that :
Only once controller : Login to application
CSV Data Set Config : Info used to login to application
Only once controller
HTTP Request : POST login information
Loop controller (10 times)
HTTP Request : POST add a "comment" to a "question"
My CSV dataset contains these fields :
username
password
group_id
A user have access to a question depending on it's group_id. I want to add 10 comments per thread to different questions.
My idea was to build a file like questions_by_group_${group_id}.txt containing some ids of questions that the ${group_id} would have access. Then I could do ${__StringToFile(questions_by_group_${group_id}.txt)} in the POST parameter value to add a comment. Using __StringToFile function should loop through lines of my file at every call. That way I can add many comments to many different questions.
The problem is that JMeter seems to open the file one time and share it for every thread (even thought I know that the ${group_id} changes for every thread.
I tried many things like
${__StringFromFile(questions_by_group_${group_id}.txt)}
${__StringFromFile(${__eval(questions_by_group_${group_id}.txt)})}
${__eval(${__StringFromFile(${__eval(questions_by_group_${group_id}.txt)})})}
but nothing works.
StringFromFile works this way by default, read:
__StringFromFile
You could organize your csv like this:
username, password, group_id , commentID1, commentID2....
Then put CSV Data Set Config before Once Only Controller.
Set Sharing Mode to All threads for example.
Finally just use variables instead of using __StringFromFile.
It's not the best solution as you have to build this file and repeat group_id ids.
Another option, if your number of groups is not very big, would be to do this in a setUp Thread Group:
read a CSV file containing:
groupID1, IDA1, IDA2,....
groupID2, IDB1, IDB2,....
...
set one property per group __setProperty or calling this inside a Beanshell Sampler:
JMeterUtils.setProperty(propertyName, propertyValue);
Then in your controller, use a Beanshell Sampler to get ids using:
JMeterUtils.getProperty(propertyName);
I must say I hate all these solutions :-)

Resources