Getting oauth token using Jmeter xpath extractor - xpath

What should be the Xpath query if I want to extract the value for access token, ie 93ee29b4-74dc-4uu7-8e10-6eac6845511b from below http response. I tried using the Xpath extractor with different xpath queries, but no luck.
{
"access_token":"93ee2tum-1234-56789-8e10-6eac684551tum",
"token_type":"Bearer",
"expires_in":3600,
"scope":"test"
}

Is there any reason you are using the xpath extractor instead of the regular expression extractor? Xpath is only useful in case there are for example multiple identical tags with different values.
Regular extractor:
access_token":"([^"]+)"
If you do need to use xpath you should know that it doesnt work with Json by default.
Read also: http://blazemeter.com/blog/using-xpath-extractor-jmeter-0

Related

unable to capture dynamic value from the response in jmeter

unable to capture guid from the below respose using regular expression
{"failure":[],"success":{"NativeMobile.CheckoutItem":["46724846133980208"]}}
using below regular expression, tried with different options
NativeMobile.CheckoutItem":["(.*?)"]
Please help to get the guid from above response
The response seems to be JSON
JSON is not a regular language
I think it would be much easier to use JSON Extractor instead, the relevant JsonPath query would be something like:
success.['NativeMobile.CheckoutItem'][0]
More information: How to Use the JSON Extractor For Testing

JMeter -XPath2 Extractor not working as XPath

I tried to use JMeter recommendation to move to XPath2 over XPath Extractor
Since JMeter 5.0, you should use XPath2 Extractor as it provides better and easier namespace management, better performances and support for XPath 2.0
But for simple query I get no results, for output
<Object classId="QueryResultRow"><Property i:type="fn40:SingletonId" propertyId="Id"><Value>{abc-def}</Value></Property><Property i:type="fn40:SingletonString" propertyId="DCN"><Value>D112345</Value></Property></Object>
I use query /Object/Property/Value or //Object//Property//Value and it works only in XPath and not XPath2
Results:
Value={abc-def}
Value_1={abc-def}
Value_2=D112345
Value_matchNr=2
Same results with /*[local-name()='Object']/*[local-name()='Property']/*[local-name()='Value'] as #EdBangga suggested
Is there an issue with XPath2 Extractor or major change of syntax?
Your issue is due to namespaces in your XML (i)
Once you show the full XML with namespaces I can give more information but to summarize:
you'll need to configure alias i to match the full namespace (you can use XPath2 Tester and Show Namespaces aliases)
then it should work

How to use multiple variables from regular expression extractor in HTTP sampler

I have the following json response from HTTP sampler
{
url: "https://example.com/ir/rest/wsVerRest/getFile?filePath=/data/IR/data/IR_Org/user.mail#abc.com/testSample1_testSample2/testSample1_20151201214307897/outputs/CnvActor-00/testCoverage1.seg",
},
{
url: "https://example.com/ir/rest/wsVerRest/getFile?filePath=/data/IR/data/IR_Org/user.mail#abc.com/testSample1_testSample2/testSample1_20151201214307897/outputs/CnvActor-00/testCoverage2.seg",}...{testCoverageN.seg}
From these I have to construct another htto sampler by using the server(ie xyz.itw),url(/ir/rest/wsVerRest/getFile),keyparam(filePath),value(/data/IR/data/IR_Org/user.mail#abc.com/testSample1_testSample2/testSample1_20151201214307897/outputs/CnvActor-00/testCoverage2.seg)
How to get these values using regular expression extractor and use in another sampler.
At present I can use regex to get those values.but don't know how to use in another http sampler.Please help.Thanks
At present I can use regex to get those values.but don't know how to
use in another http sampler.Please help.Thanks
If you are able to get these values via Reg Expression extractor then it will not be a problem for you. When you use Regular expression extractor then the value are stored in "Reference Name" that you mentioned in your Extractor.
Lets say, your reference names were like below:
ServerValue
UrlValue
KeyParamValue
and so on..
you can simply use them like this in your intended HTTP sampler..
${ServerValue}${UrlValue}${KeyParamValue}

Jmeter- How to extract token id from Response Data

This is the response data from which i need to extract token value
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0IjoibXljb21wYW55IiwiZCI6ImhrZy5maXJlYmV0LmRldi5zdXBwb3J0LmNvbSIsInBybSI6WyJsb2c6KiIsInNlc3Npb246Y29ubmVjdCIsInNlc3Npb246dXBsb2FkRmlsZToxMjUyMyIsInNlc3Npb246ZGV2aWNlSW5mbyxsb2dhY3Rpdml0eWV2ZW50LGRldmljZWNhcGFiaWxpdHk6MTM1MTEiXSwianRpIjoiMGVmNmU5OGYtZjQ0My00NmEzLTkxMmMtMDNiNmMyZDFjNzU1IiwiYXBwIjoiVGVzdGFwcCIsInZlciI6IjEiLCJwbHQiOiJBbmRyb2lkIiwiaWF0IjoxNDMyNjE4MDY3LCJhdWQiOiJhcHAiLCJleHAiOjE0MzI2MjUyNjcsImlzcyI6IlN1cHBvcnQuY29tIn0.qkgSrZFoc2MR8xQN0boRd85PcmD1R0xkQjVzKXNv2Uk",
"session_device_id": "13511",
"session_id": "12523",
"relay_config": "tdssd:443",
"symmetric_key": "dssdFx0=",
"workflow_version_id": 10s008,
"unique_connection_id": "fsdsd"
}
Currently I am using regular expression extractor
token: "(.*?)"
Just add closing quotation mark to your regular expression as
token": "(.*?)"
and use $1$ as Template
Another option is using JSON Path Extractor which comes with JMeter Plugins which is more handy to extract stuff from JSON responses. In that case use the following JSON Path query:
$..token
See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") for more information on the JSON Path language and few useful examples.
Extracting token value from the response
So here I you used as User id so please change this in token so and use post processor regular expression it will definitely work
Use
"token":"(.+?)"
in the JSON Path Extractor.
In regular expression extractor use regular expression as token": "([^"]+)" and template $1$.
I hope this will help you.

Regular expression in Jmeter for a json reponse

How do i write the regular expression for the json response.
My json response is "publisher":"/api/web/publishers/194".
From this response i want to get only the numeric value i.e 194. Some one pls help in getting it?
If "194" is the only integer in your response than your regex can be limited to just '(\d+)`
If you response contains more digits, you'll need to be more specific, like
"publisher":"/api/web/publishers/(\d+)"
So something like:
Reference Name: publisher
Regular Expression: "publisher":"/api/web/publishers/(\d+)"
Template: $1$
Will extract "194" and store it in "publisher" JMeter Variable. You'll be able to refer to it as ${publisher} later in Thread Group.
Going forward if you'll need to extract something from more complex JSON structures I'd recommend consider using JSON Path Extractor available via JMeter Plugins - the extractor lives in "Extras with Libs Set" package.
See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") for more information and XPath to JSON mapping.

Resources