I am sending First request to server:
POST http://192.168.7.101/r2.web/Planning/Scheduling/TimelinefromR3 -->(A)
I have written Regular Expression extractor((?<=\"Values":")(.*?)(?=\")) to extract Resourcenames like "Ray Gwilliams" and "James Mark" from the response of (A),
Now, I have another request(as mentioned below) to which, I need to pass all the Resource names("Ray Gwilliams" and "James Mark") extracted above.
Please let me know how to achieve this.
http://192.168.7.101/R2.Web/Planning/Scheduling/SchedulesAndGroups
POST data:
[{"ColumnName":"CONTACTNAME","ColumnIId":0,"UdfIId":null,"ConditionIId":0,"OperatorIId":1,"SequenceNo":0,"Values":"Ray Gwilliams
","Lookup":null,"LookupIId":0,"LookupSource":0,"LookupType":0,"MultipleOperatorIIds":null,"MultipleValues":null,"ColumnDataType":null},{"ColumnName":"CONTACTNAME","ColumnIId":0,"UdfIId":null,"ConditionIId":0,"OperatorIId":1,"SequenceNo":0,"Values":"James Mark
","Lookup":null,"LookupIId":0,"LookupSource":0,"LookupType":0,"MultipleOperatorIIds":null,"MultipleValues":null,"ColumnDataType":null}
I have not used the regular expression but if you use the JSON Extractor element and put the extracted value into a variable, you would just add the variable into the 2nd POST request. For example:
POST data:
[{"ColumnName":"CONTACTNAME",
"ColumnIId":0,"UdfIId":null,"ConditionIId":0,
"OperatorIId":1,"SequenceNo":0,
"Values":"${variable1} ","Lookup":null,"LookupIId":0,
"LookupSource":0,"LookupType":0,
"MultipleOperatorIIds":null,"MultipleValues":null,
"ColumnDataType":null}, {"ColumnName":"CONTACTNAME",
"ColumnIId":0,"UdfIId":null,
"ConditionIId":0,"OperatorIId":1,
"SequenceNo":0,
"Values":"${variable2} ","Lookup":null,"LookupIId":0,
"LookupSource":0,"LookupType":0,
"MultipleOperatorIIds":null,
"MultipleValues":null,"ColumnDataType":null}
Tip: To get the value you want extracted, use jmeter's JSON Path Tester in the View Results in Tree listenter element or this helper tool: http://jsonpath.com/
Related
I am using REST-API for testing
I am stuck where I am checking the response with some specific string.
please refer below info
I got the response from a request is
{
"clusters":[
{
"id":10,
"name":"HP2",
"status":2,
"statusDisplay":"HParihar#4info.com",
"lastModifiedBy":"HParihar#4info.com",
"lastModifiedTime":"06/08/2017 23:42",
"sitesAppsCount":0
},
{
"id":799,
"name":"Regression_cluster_111_09",
"status":2,
"statusDisplay":"admin#4info.net",
"lastModifiedBy":"admin#4info.net",
"lastModifiedTime":"07/11/2017 08:19",
"sitesAppsCount":0
}
]}
and I wanted to match just
"name":"Regression_cluster_111_09",
"status":2,
"statusDisplay":"admin#4info.net",
"sitesAppsCount":0
right side values I'll be keeping as hard coded.
any guesses?
Since you are only checking those 4 parameters are in response or not.
Do no use regex for this.
Use jsonObject's find key/value feature.
Check whether the values to the keys are there.
If key/value is null, the parameter is not in response.
I got my answer
I used the following regex
"name":"Regression_cluster_111_09","status":2,"statusDisplay":"admin#4info.net","lastModifiedBy":"[a-z]+#[0-9a-z]+\.[a-z]+","lastModifiedTime":"[0-9]{2}\/[0-9]{2}\/[0-9]{4}\ [0-9]{2}:[0-9]{2}","sitesAppsCount":0
or I can simply use
"name":"Regression_cluster_111_09","status":2,"statusDisplay":"admin#4info.net",.+"sitesAppsCount":0
thank you all
(Edit: The answer is to use check 'Encode?'option in the HTTP Request. Please see Vinoth's Edit 2 and comment below, thanks!)
This is interesting!
I'm trying to parse a HTTP response which has (let's give concrete example,
bigH:"2a3a6CEH+iJakQpQtPm8efv"
Using Regular Expression Extractor when I try
bigH:"(.+?)"
it extracts the string but replaces all the "+" in the string with space. That is, instead of
"2a3a6CEH+iJakQpQtPm8efv"
it gives me:
"2a3a6CEH iJakQpQtPm8efv"
Note the space between H and i.
How can I stop it from replacing the "+" with a space? I'd really appreciate if someone can give an explanation also.
Btw, I tried (.+?) and (.\++?) and even ([.|\+]+?) - didn't work :(
Thanks,
--Ishtiaque
Updating with screenshots below:
Adding screenshots:
POST Response data:
After parsing with regular expression extractor in JMeter:
Side by side in Notepad++:
'Raw' tab shows the '+'s:
'HTTP' tab does not:
As you get the response in JSON format, I would go with JSON Path Extractor.
It seems to be a much easier approach than using Regular expression.
Below JSON Path should take care of getting the encoded string from your JSON & You should be able to access using ${bigH}.
Check this for more details (scroll down for JSON Path extractor details).
EDIT:
I was wrong that You get the response in JSON format. Are you trying to access - bigH:"XXX" - from script tag? For this, We have to use Regular expression extractor only or Beanshell.
<script type='text/javascript' charset='utf-8'>
registerSubmit(document.forms[0].elements['SubmitTopButton']);
registerSubmit(document.forms[0].elements['SubmitBottomButton']);
(function($) {
$(".wb_tsauthall").wb_tsauthall({
auth : "Authorize All",
unauth : "Unauthorize All",
locMsgKeys : []
});
$(".wb_newedit").wb_newedit({
labels:['Job','Code','Work Premium','Flat Rate','Premium','Shift','Sched Times','LTA','Sched Times w Breaks','Delete Details','Employee Holiday','Work Detail','Schedule Detail'],values:[105,103,200,206,204,450,401,500,461,199,900,100,460],bigH:"PVxUbYIODBT31j8IZnPGxF/9O1iuKAkFzTO9WhXu8An8hAUa22tLiWrEHz8v9SIu/NXZH1a5IxO0xYeNwRIYM+3n1kNsrESnhiAYhwhCiqUY9mI4hvEPgAOx7B+MEB8iSIUyNGNZbeGx9nSogFYpNrzmCXirW7Nm9Tn7owPKHmc8dOf5SZ+eDzAOHIB8+5YzQ3bIdFoe60hOMkyd7FiUXtwPcNMUFEjOSMs9JhgIHTE4agpCdbFb6SLuSuLoO9rqxj+9GovUbzTmrxj4faBKZVATNN7iIFyDZHYAZuZRcPJBdUJ1xNHMCWyPZ4p2/Yk0Q0ujdKJbJw9NFysikZgBFNEhNXEA4w8HL1ycYCmZDgSUW1GsumDAKh0Brq3K8Kh2akep8YEjDMWipKgSPaNx3CVY4lf87e0oK70nK/zKGkmpWFvyMnxbkJtWmeuxmPgRZgg2lYbZXFauD1AidnQQhPULJTTV+P+Xkk9PYm3ZkIEcDnYJUmPg/D3iuwg84m2IZatFTdjiNuDAcGNKptTd54yMgohN87c3sRMiZlSY/r88u+Le3BKWJqyl7Xai7Odqz366DFgOzdPi92LnSaggKX++hy+Z04kjyfSZOUYWmiWlc38SUdeTq2v15egig2mMkSLMaUnHagk="
});
$("#codeSummaryBar").wb_expandableframe({
iframe : contextPath + '/dailytimesheet/summaryInline.jsp'
});
$("#codeSummaryBar").click(function(){$("#codeSummaryBar_expand_collapse_icon").toggleClass("collapse expand");});
$("#codeSummaryBar").click();
$("#selectionBar").wb_expandableframe({
iframe : contextPath + '/dailytimesheet/dailySelectInline.jsp',
onExpand : function() {
$(".selectionBarControl").css("visibility", "hidden");
$("#expand_collapse_icon").removeClass("expand").addClass("collapse");
},
onCollapse : function() {
$(".selectionBarControl").css("visibility", "");
$("#expand_collapse_icon").removeClass("collapse").addClass("expand");
}
});
DTS.onload();
})(jQuery);
</script>
EDIT 2:
I doubt that you might have checked the Encode in the HTTP Request.
Uncheck
Try with the regular expression ([a-zA-Z0-9+]+)
I would like to write a regular expression that catch Encoded Words parts from email MIME message string (eml). for example, this is part of email:
<div dir=3D"ltr"><br clear=3D"all"><div><div dir=3D"ltr"><div style=3D"dire=
ction:rtl">-------------</div><div style=3D"direction:rtl">=D7=91=D7=91=D7=
=A8=D7=9B=D7=94,</div><div style=3D"direction:rtl">=D7=90=D7=91=D7=99=D7=A2=
=D7=93 =D7=9B=D7=94=D7=9F</div></div></div>
</div>
--20cf3003bc2e044e980500f755dc--
--20cf3003bc2e044e9d0500f755de
Content-Type: text/plain; charset=US-ASCII; name="EhudBanay.txt"
Content-Disposition: attachment; filename="EhudBanay.txt"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_hz0z4us30
aHR0cHM6Ly93d3cuZmFjZWJvb2suY29tL2wucGhwP3U9aHR0cHMlM0ElMkYlMkZ3d3cucmFwaWRz
aGFyZS5jb20lMkZmaWxlcyUyRjM4NzAxNTA2MDclMkZFaHVkX0JhbmFpXy1fVGlwX1RpcGFfXzE5
OThfLnJhciZoPTdBUUZRb0RMQQ0KDQpodHRwczovL3d3dy5mYWNlYm9vay5jb20vbC5waHA/dT1o
dHRwcyUzQSUyRiUyRnd3dy5yYXBpZHNoYXJlLmNvb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5haV9WZUhhUGxpdGltX18xOTg3X19GLnBhcnQy
LnJhciZoPUJBUUVoSWN3Yw0KDQpodHRwczovL3d3dy5mYWNlYm9vay5jb20vbC5waHA/dT1odHRw
cyUzQSUyRiUyRnd3dy5yYXBpZHNoYXJlLmNvbSUyRmZpbGVzJTJGMjYwNDg2Njc1MiUyRkVodWRf
QmFuYWlfLV9FaHVkX0JhbmFpX1ZlSGFQbGl0aW1fXzE5ODdfX0YucGFydDEucmFyJmg9REFRSHpG
LXZBDQoNCmh0dHBzOi8vd3d3LmZhY2Vib29rLmNvbS9sLnBocD91PWh0dHBzJTNBJTJGJTJGd3d3
LnJhcGlkc2hhcmUuY29tJTJGZmlsZXMlMkYyNjQxMzIwNzg2JTJGRWh1ZF9CYW5haV8tX0Ryb3Bz
X09mX1RoZV9OaWdodF9fMjAxMV8ucmFyJmg9Y0FRRlRZQ1pTDQoNCmh0dHBzOi8vd3d3LmZhY2Vi
b29rLmNvbS9sLnBocD91PWh0dHBzJTNBJTJGJTJGd3d3LnJhcGlkc2hhcmUuY29tJTJGZmlsZXMl
MkYzMTQ3NzUzNzAwJTJGRWh1ZCUyNTIwQmFuYWklMjUyMC0lMjUyMEtlZXAlMjUyMERyaXZpbmcu
cGFydDEucmFyJmg9S0FRRWtPUkZTDQoNCmh0dHBzOi8vd3d3LmZhY2Vib29rLmNvbS9sLnBocD91
PWh0dHBzJTNBJTJGJTJGd3d3LnJhcGlkc2hhcmUuY29tJTJGZmlsZXMlMkYxNzc1NDI5NDY3JTJG
RWh1ZF9CYW5haV8tX0FuZV9MaV9fMjAwNF8ucmFyJmg9dkFRRWlEWXFu
I didn't manage to do it with regular expression so i tried to use the following line which always start with "--" and ends with "--". notice that before the wanted part there is always an empty line.
I tried: "(\s).*(--)$" but it returns only the following line.
Can someone please help?
It sounds like you're trying to parse multipart/mixed email. There are libraries in most languages to do this already. If you want to write your own I'd suggest following the structure of a multipart message.
Find the boundary defined in the content-type header
Split the message into parts delimited by the boundary (prefixed by --).
For each part seek to the first instance of two consecutive line breaks that denote the end of the headers.
While regular expressions might be helpful for some part of this. I'm not sure its the right tool to parse a structured message.
You can use this regex:
\n\s*\n\K(?:[^-]{2})*.?(?=\n--)
Online demo
I am having sample json
[
: {
: : "id":"255",
: : "name”:”abc”,
: },
: {
: : "id":"257",
: : "name”:”xyz”,
: }
]
I am using json path extractor in jmeter to get the values of id and name.
However is it possible to get the count of ids or names in a straight forward way.
I know if I use regex extractor and using for loop to get the count.
Use regular expression extractor and set no. of match to a negative no. then reference name_matchNr variable should give you the count of occurances of string.
like,
Then expression_matchNr variable should give you the count of id occurances.
For additional reference see JMeter help,Regular Expression extractor
It is possible via some scripting.
For example, if you have the following JSON payload:
{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
And the following JSONPath Expression:
$.employees..firstName
which returns first names as follows:
["John","Anna","Peter"]
You can get matches number by counting commas in the resulting variable.
Given that you're using "name" as the Variable Name in JSON Path Extractor
Add the a Beanshell PostProcessor below JSONPath extractor
Put the following code into the PostProcessor's "Script" area:
int matches = vars.get("name").split(",").length;
vars.put("matches",String.valueOf(matches));
Optionally add a Debug Sampler and a View Results Tree Listener and run your test
You should have "matches" variable containing "3"
For more information on Beanshell scripting in Apache JMeter see How to use BeanShell: JMeter's favorite built-in component guide.
There is a way to do it using Json Extractor as well. For your given Json you can add a Json Extractor in your HTTP Sampler and a Debug Sampler(to see result) next to you HTTP sampler as shown below
and set variable and path expression as follow
See response data of debug sampler and you will get result at last
idCount_matchNr=2
I'm using the regex in Jmeter 2.8 to extract some values from JSON responses.
The response is like that:
{
"key": "prod",
"id": "p2301d",
"objects": [{
"id": "102955",
"key": "member",
...
}],
"features":"product_features"
}
I'm trying to get everything except the text between [{....}] with one regex.
I've tried this one "key":([^\[\{.*\}\],].+?) but I'm always getting the other values between [{...}] (in this example: member)
Do you have any clue?
Thanks.
Suppose you can try to use custom JSON utils for jmeter (JSON Path Assertion, JSON Path Extractor, JSON Formatter) - JSON Path Extractor in this case.
Add ATLANTBH jmeter-components to jmeter: https://github.com/ATLANTBH/jmeter-components#installation-instructions.
Add JSON Path Extractor (from Post Processors components list) as child to the sampler which returns json response you want to process:
(I've used Dummy Sampler to emulate your response, you will have your original sampler)
Add as many extractors as values your want to extract (3 in this case: "key", "id", "features").
Configure each extractor: define variable name to store extracted value and JSONPath query to extract corresponding value:
for "key": $.key
for "id": $.id
for "features": $.features
Further in script your can refer extracted values using jmeter variables (variable name pointed in JSON Path Extractor settings in "Name" field): e.g. ${jsonKey}, ${jsonID}, ${$.features}.
Perhaps it may be not the most optimal way but it works.
My solution for my problem was to turn the JSON into an object so that i can extract just the value that i want, and not the values in the {...}.
Here you can see my code:
var JSON={"itemType":"prod","id":"p2301d","version":"10","tags":[{"itemType":"member","id":"p2301e"},{"itemType":"other","id":"prod10450"}],"multiPrice":null,"prices":null};
//Transformation into an object:
obj = eval(JSON );
//write in the Jmeter variable "itemtype", the content of obj.itemType:prod
vars.put("itemtype", obj.itemType);
For more information: http://www.havecomputerwillcode.com/blog/?p=500.
A general solution: DEMO
Regex: (\[{\n\s*(?:\s*"\w+"\s*:\s*[^,]+,)+\n\s*}\])
Explanation, you don't consume the spaces that you must correctly, before each line there are spaces and you must consume them before matching, that's why isn't your regex really working. You don't need to scape the { char.