How to use JMeter to create a resource with POST, extract Location, and then subsequently update it with PUT - performance

I would like to profile a REST API using JMeter. I would like to write the test plan such that each user thread performs the following actions:
creates a new resource using HTTP POST
If HTTP 201 Created is received, then extract the new resource URL from the Location header of the HTTP response.
Subsequently update the resource using HTTP PUT
Loop in 3 and measure the response time
It's unclear to me how to use JMeter's conditional logic to break up the tests into these discrete parts. I would appreciate any insight anyone can provide on how to implement this.

You need to use If Controller to express this logic.
You can use Regular Expression Extractor to extract Response code (In field to check, check it and extract response code in a Variable)
Use the previously extracted variable in the If Controller condition

Related

Jmeter HTTP Request sample and SkipToken

I am using HTTP request sampler for API performance testing. My APIs might return a response containing the skiptoken
If response contains the skiptoken, I need to call the API again using the skip token and capture the performance metrics. I required calling the API until there are no skiptoken available in the response.
Please let me know how I can implement this in JMeter
You can add a Post-Processor, for example JSON Extractor, which will extract the skpitoken into a JMeter Variable from the API response.
If the variable is defined you can add If Controller and send another request to the API with the variable from the previous step.
Something like this:
You have to use any of the Post processor according to your API response content. e.g, Json extractor, Regex extractor, Boundary based extractor, whichever suits well.
Then you need to use While Controller instead of If controller. The While controller it will keep executing the API inside it, until the last skiptoken gets retrieved/ not found - refer the screenshot
If you use If controller - It will execute only once and proceed with other APIs
Since, I don't know the exact response body structure - you can use Regex to fetch the value, something like the below
"#odata.nextLink":"([^ ]+)"

JMeter reponse headers values before redirection on status code 302

I am performing load testing on an API using JMeter. For that, I call an oauth link, which returns a code in the headers which I use for further testing. But the link redirects to another link and I am unable to capture the value of the response headers when a response with status code 302 is returned. How can I do that.
If your situation is like this one:
You can still extract the dynamic value from the latter sample result by modifying Regular Expression Extractor scope
As per documentation:
Apply to:
This is for use with samplers that can generate sub-samples, e.g. HTTP Sampler with embedded resources, Mail Reader or samples generated by the Transaction Controller.
Main sample only - only applies to the main sample
Sub-samples only - only applies to the sub-samples
Main sample and sub-samples - applies to both.
JMeter Variable - assertion is to be applied to the contents of the named variable
By default Regular Expression Extractor is looking into Main sample only, in the above example it is HTTP Request, if the data you're looking for is stored in one of the sub-samples it is enough to change Regular Expression Extractor's scope to look into sub-results as well:
You have 2 options:
Do not allow HTTP request to redirect. Simply uncheck "Follow Redirects" checkbox in the HTTP Sampler:
That way you can process this request normally. The drawback is of course that you need to add a second request which will take you to a link to which you are normally redirected automatically.
Most post-processors allow you to extract value from either main sample, or sub-samples, or both. So follow redirect as before, but change Post-Processor to extract value from sub-sample. For example Regular Expression Extractor:

Jmeter extract value from Get Request

In this example request 226 is main Post request which internally executes 1 Post and 2 Get requests during run time. how i can extract dynamic code value from one of Get request of 226 which is input for the request 228.
I know how to extract from response using RegEx and Xpath. I this case need help Passing Data From a Request to Another Request
Hopefully you've already found the solution, but I believe that is what you've been looking for:
To extract data from a response, you can go for Regular Expression Extractor in this case which is faster and consumes less memory and CPU compared to other extractors like XPath which is worse.
This blog has decent info on extracting information using Regular Expression Extractor.
You are already saying that you know how to use them. Then it is very easy to pass the value to another request. You just use the variable using below syntax to access the value - ${variablename}. Whereever you need to substitute the value, just use ${variablename}.
Ex: code=${code}&stats=${stats}
Remember: Scope of this variable is within the thread for a thread group.
I don't think you will be able to bypass OAuth 2.0 login challenge using correlation. See How to Run Performance Tests on OAuth Secured Apps with JMeter for feasible options.
you can use beanshell sampler to process the results and have prev to get the list of results
org.apache.jmeter.samplers.SampleResult [] temp=prev.getSubResults();
print(temp[2].getURL())

Feature Testing using jmeter

Can somebody please explain me how can I use JMeter for Feature testing?
I'm able to create multiple HTTP requests within a Testplan. But I need know the way to capture the previous API response and pass one of the response data to the next API request.
Eg:
1.Create Account.
Request- POST: /account
Response: ID: "Value"
Read account
Request- GET: /account/
JMeter is really more of a load testing tool, and best used as such. Capturing data from responses is possible using the Regular Expression Extractor, which can store extracted values in variables for use in a subsequent request. It is a bit of a pain in the ass to use, though.
On your request, add a Regular Expression Extractor:
Field to check: body
Reference name: EXAMPLE
Regular Expression: \[.*\] #your regex here, stuff in square brackets as example
Match No.: 1
In a subsequent request, you can then use the variables defined by the extractor, e.g. ${EXAMPLE_g0} for the entire match, or ${EXAMPLE_g1} for group 1, etc.

Anyway to auto set jmeter assertions to initial responses?

I am building out a test suite in jmeter and want to set the assertions to the initial responses that I get from the api calls. Is there any way to do this besides copy pasta?
For clarity each individual call has its own assertion, which for the moment is the response it is receiving.
I want the assertions to be populated by the responses.
If I understood currectly - you are coming up with some JMeter-Baseline script - you also assume that the response you get now is correct - that is what you expect to get it in future as well , so you want to put the response data in the assertion.
If yes, JMeter will not remember the initial responses. So you need to create your script accordingly.
You can have a beanshell postprocessor to write the the responsedata in a CSV file. Later you modify the script to look for the assertion string from CSV file to compare. This is the statement to get the Response Data.
prev.getResponseDataAsString()
As per How to Use JMeter Assertions in 3 Easy Steps guide, JMeter Assertions have their scope.
If you put an assertion at the same level as all requests it'll apply to all of them. See image below for explanation:
I would use a CSV file with the URL and the assertion string you want to match.

Resources