I have a Thread Group that looks something like this:
JDBC Connection
Request_1
Request_2
Request_1 is an OracleSQL procedure that returns a number.
declare
result NUMERIC;
begin
result:=procedure1();
end;
Request_2 needs the number returned by Request_1.
begin
procedure(?);
end;
result
NUMERIC
How do I pass the result of Request_1 to Request_2?
I guess that you need to add Regular Expression Extractor post-processor to your Request 1.
If result value is a number, i.e. "10" you can do the following to extract it.
Add "Regular Expression Extractor" Post Processor to request 1
Fill "Regular Expression Extractor" fields as follows:
Reference Name: RESULT
Regular Expression: (\d+)
Template: $1$
You can refer RESULT variable in your Request2 as ${RESULT}
begin
procedure(${RESULT});
end;
result
NUMERIC
You can test your regular expression using Jakarta ORO Demonstration applet
Related
I have the request where I'm passing page number.
https:// †*********/projects?page=1
Response will be project details with page number.
{
"Firstpage" : "page=1";
"Lastpage" : "page=10"
}
1000 records will be printed in first page. I need to repeat the request untill it's reached page 10.
I tried capturing with following regular expression
"Firstpage" : "(.*?)"
This will capture page=1, but I need to loop till it reached page 10.
Extract the value for the last page and store it into Lastpage JMeter Variable using Regular Expression Extractor configured like:
Name of created variable: Lastpage
Regular Expression: Lastpage"[\s]+:[\s]+"page=(\d+)
Template: $1$
Add Loop Controller to your Test Plan and put the following __jexl3() expression into "Loop Count" field:
${__jexl3(${Lastpage} - 1,)}
That's it, you should be able to refer the next page as ${__jexl3(${__jm__Loop Controller__idx} + 2,)} where required
I need to use variable from beanshell in my while loop, but I am not able to see the value of variable coming through.
output variable of my JDBC select count(*) query is "count_num"
using following code in beanshell:
int id = Integer.parseInt(vars.get("count_num_1").trim());
Following is the structure of my test plan:
-JDBC request (o/p variable is count_num)
-beanshell sampler (parse string count_num to integer)
-While Controller: vars.get(${i})>0)
-http request1
-http request2
- (beanshell code to decrease "i" by 5 - not sure how??)
What am i doing wrong in usage of "i" and also how to decrease count of "i" by 5 towards the end of while loop.
Put variable string value after adding 5
vars.put("count_num_1", String.valueOf(id +5));
Regular expression is fetching 9 values
Need to add all these ticked values with comma separation in next request.How can we do this in J meter
How can we pass multiple values extracted via regular expression to next request in JMeter
Can you please share some snippet of the HTML response, I'd like to help you with the answer. Also, at times, using an XPath expression in an XPath Extractor can be easier to work with.
If the reference name for is set to VALUE, then you can access each of the 9 matched values as VALUE_1, VALUE_2, ...... VALUE_9
Given you configure your Regular Expression Extractor as follows:
Reference Name: arg_name
Regular Expression: `arg_names" value="(.+?)"
Template: $1$
Match No.: -1
You will get JMeter Variables like:
arg_name_1=foo
arg_name_2=bar
arg_name_3=baz
arg_name_matchNr=3
Now you should be able to concatenate the values using the following __groovy() function:
${__groovy(def builder = new StringBuilder(); 1.upto(Integer.parseInt(vars.get("arg_name_matchNr"))) { builder.append(vars.get("arg_name_" + it)).append("\,") }; builder.toString(),)}
Demo:
More information:
vars is a shorthand to JMeterVariables class instance
Groovy For Loop Examples
Apache Groovy - Why and How You Should Use It
I have a Soap request which response returns a set of values under the same tag
let's say
<PricelistDetails>
<ServicePricelistDetailInfo>
<cost>20</cost>
</ServicePricelistDetailInfo>
<ServicePricelistDetailInfo>
<cost>25</cost>
</ServicePricelistDetailInfo>
<ServicePricelistDetailInfo>
<cost>30</cost>
</ServicePricelistDetailInfo>
<PricelistDetails>
I'v created an Xpath assertion to assert the cost tag to a user defined variable:
/Envelope/Body/GetServicePricelistResponse/GetServicePricelistResult/ServicePricelistInfoList/ServicePricelistInfo/PricelistDetails/ServicePricelistDetailInfoList/ServicePricelistDetailInfo/cost ='${COST1}'
whilst COST1 is defined as below :
name : COST1
Value :[20,25,30]
but when running the test plan it is showing an assertion error
Note:
I 've created an Xpath extractor to test the assertion query and it returned all
of the cost values from the response correctly
I would suggest putting your XPath query into XPath Extractor, adding Debug Sampler afterwards and checking the generated variables via View Results Tree listener, my expectation is that you will get something like:
cost=20
cost_1=20
cost_2=25
cost_3=30
cost_matchNr=3
So you will be able to use "normal" Response Assertion against these ${cost_1}, ${cost_2} and ${cost3} variables.
If for some reason you need to go the "XPath way" - use the following XPath Expression in the assertion:
concat("[", //PricelistDetails/ServicePricelistDetailInfo[1]/cost, ",", //PricelistDetails/ServicePricelistDetailInfo[2]/cost, ",", //PricelistDetails/ServicePricelistDetailInfo[3]/cost, "]")="${COST1}"
Demo:
References:
XSLT, XPath, and XQuery Functions
XPath Language Specification
How to Use JMeter Assertions in Three Easy Steps
Your expression will just compare each of values from returned array (20, 25, 30) with [20,25,30] like:
20 = [20,25,30] # false
25 = [20,25,30] # false
30 = [20,25,30] # false
and return false as all comparissons failed, while you need to compare all of them at once:
[20,25,30] = [20,25,30] # true
I'm not sure that it's the best solution, but as last resort you can try
concat('[', string-join(//PricelistDetails/ServicePricelistDetailInfo/cost, ','), ']') = '${COST1}'
I am new to jMeter. I am recording a script for creating a shift. For every transaction New shift ID is generated. I have tried to extract it by using regx Exp extractor but not getting anything. Pls see below information.
*Reference Name: strgenShiftId
Regular Expression: end="${strWeekEndDate}" gs="(.+?)"
Template: $1$
Match No.
Default Value:
Where ${strWeekEndDate} is a variable which extracts the date from some other previous response.
My Response code is as following-
week start="07/27/2015" end="08/02/2015" gs="61530" unitSkey="811" fy="2015" fw="30" ac="Y">
I want to extract the gs="61531".
The full response is:
<data>
<weeks selWkIndex="5">
<week start="06/29/2015" end="07/05/2015" gs="71526" unitSkey="811" fy="2015" fw="26" ac="N">
</week>
<week start="07/06/2015" end="07/12/2015" gs="71527" unitSkey="811" fy="2015" fw="27" ac="N">
</week>
<week start="07/13/2015" end="07/19/2015" gs="71528" unitSkey="811" fy="2015" fw="28" ac="N">
</weeks>
</data>
You can extract gs value using following regular expression: gs=\"([^"]+)\". Always remember to escape " with \ in regular epressions, unless you want " to be evaluated as part of regular expression.