how can we pass bearer token created in xml into 2 nd api which is placed in another thread group in jmeter - jmeter

how can we pass bearer token created in xml into 2 nd api which is placed in another thread group in jmeter I have tried with set property but it is not working as the body of token is in xml.

If your token comes in the XML response just extract it using XPath Extractor or better XPath2 Extractor.
Once you have the token stored as JMeter Variable there will be 2 options:
Convert it into a JMeter Property using __setProperty() function
Or use Inter-Thread Communication Plugin (see SynchronizationExample.jmx test plan for reference usage)

Related

How to use one access token generated for multiple users request in jmeter

I am working on jmeter for the First time. I am extracting the accesstoken and passing it on to other requests. but i am facing the issue that once I run it for 50 users the access token request is also running and becase of which other request is failing as new access token is generated and the request is failing to use that. I want to generate one access token for all the 50 request. I have tried keeping the request parted in two different thread groups.
enter image description here
#oshin, I am also new here but I will try what I did that might help yours too. I used JSR223 PreProcessor to get that access token and passed that in my other thread with another JSR223 preprocessor which reads that accesstoken. And passed that token in my header manager. See if this helps you.
Get token
Read access token in the following thread
Assign token to Header manager
Don't use Beanshell, since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting
Don't use scripting when something can be achieved using built-in JMeter Test Elements (or JMeter Plugins)
I would recommend:
Moving your "login" sampler under setUp Thread Group so it would be executed before the main thread group and only by 1 user
Storing the token into a JMeter Property via __setProperty() function
JMeter Properties are global and can be accessed by all threads in all thread groups so you will be able to use one token
Read the token using __P() function where required.

Comparing api request with jdbc values

I am doing api request automation using jmeter. i want to compare api request values with jdbc values after execution.how to do that?
Add JDBC driver for your database to JMeter Classpath
Add JDBC Connection Configuration to your Test Plan
Add JDBC PostProcessor as a child of the HTTP Request and execute the relevant query to get the value from the DB and store result into a JMeter Variable
Add JSON Extractor or XPath Extractor as a child of the request and fetch the value from the API response
Compare the values from steps 3 and 4 using Response Assertion
You can see How to Retrieve Database Data for API Testing with JMeter article for reference configuration.

Jmeter : getting 401 error

Does any one knows how to solve it with regular expression? here i am putting screen shot with valid access token and error response token.
thanks in advance.
Valid response token
invalid response token
and Regular expression exctracter
it is fine if you guys have any other solution for this unauthorized access thing.
Add JSON Extractor as a child of the authserver request and configure it as follows:
Variable Names: anything meaningful, i.e. token
JSON Path expressions: $.access_token
Add HTTP Header Manager as a child of the student request and configure it to send Authorization header with the value of Bearer ${token}
Going forward you can go for an alternative way of recording a JMeter test which is capable of exporting the recorded requests in SmartJMX mode with automatic correlation of dynamic parameters applied so you will be able to save your time for more creative work. See How to Cut Your JMeter Scripting Time by 80% article for more details.

How can i extraxt Session id and Xsrf token through cookies in jmeter

I have recorded script and run jmeter. the Session id and Xsrf tokens are passing request header cookies in browser cookies. but,session id is not passing in jmeter.
So, connection closed error occurring.
How can i extract session id and xsrf token using regular expression extractor?
Add the next line to user.properties file (located in the "bin" folder of your JMeter installation)
CookieManager.save.cookies=true
Restart JMeter to pick the property up
Add HTTP Cookie Manager to your Test Plan
Now you should be able to refer cookie values as:
${COOKIE_session}
and
${COOKIE__xsrf} where required
More information: Using the HTTP Cookie Manager in JMeter
You can use XPath extractor and enter "//input[#name='_csrf']/#value" to get the csrf token value and then enter desired reference name for example "csrf_token" and use the variable ${csrf_token} wherever necessary

JMeter: How to use the RESTful API key for authorization of the next set of API

I am creating a jmeter load test plan for RESTful API request. I need to use the dynamic API key generated in my first sampler SignIn API in the next set of API requests I am going to create.
Can someone help out with how to pass the selected data parameters from response and input to the another api request in other required format for that post request.
Response Header
WebxxxHeader: {"UserName":"xxxxx","UserID":1,"ApiKey":"ea9a3572-de75-4a85-848a-8fed874f2269","ValidFrom":"2015-06-05 05:54:35","ValidTo":"2015-06-12 05:54:35","UserRole":null,"Password":null,"DeviceToken":null,"DeviceType":null,"IsRetina":false,"UniqueId":null}
Header to be posted in the next set of APIs
WebxxxHeader: {"UserName":"xxxxx","ApiKey":"ea9a3572-de75-4a85-848a-8fed874f2269"}
One more issue here is I have to pass the user email in the header instead of UserName.
Please share advanced JMeter blog references.
Thanks in advance for your suggestions.
I would suggest searching the web for something like "JMeter correlation" - that should give you the answers you're looking for.
Particular this API key bit can be handled via Regular Expression Extractor postprocessor.
Add Regular Expression Extractor as a child of the request which returns the API Key
Configure it as follows:
Field to check: Response Headers
Reference Name: anything meaningful, i.e. API_KEY
Regular Expression: "ApiKey":"(.+?)"
Template: $1$
Other fields can be left as is
Add HTTP Header Manager as a child of the second request and configure it as follows:
Name: WebxxxHeader
Value: `{"UserName":"xxxxx","ApiKey":"${API_KEY}"}
If you testing REST API I think that JSON Path Extractor available via JMeter Plugins could be extremely useful. See Using the XPath Extractor in JMeter guide (scroll to "Parsing JSON") for installation and usage instructions and some form of JSON Path language reference.

Resources