Send Form data and Query string in one POST request in Jmeter - jmeter

I need to send POST request through jmeter. I have checked the requests workflow through browser dev. tools. In my Post request I need to send form data and one string Query. Question is next - if i will add my string Query to URL will it work fine?
Example : somesite.com/something?refURL=someRef

If it is a POST request, usually any form data will be sent in the request body. Not like a query string in the GET request. But the format is same.
refURL=someRef add this in the parameters section.
Check here for more info.
https://www.w3.org/TR/html401/interact/forms.html#h-17.13

Why not? Query string and request body are different beasts and they are processed differently on server side.
Instead of asking this kind of questions, why don't you just record your test using JMeter's proxy server?
References:
URI Syntax - Query Component
HTTP Method Definitions - POST

Yes it will.
You can even use variables like:
/some/path?refURL=${someCalculatedRefUrl}

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":"([^ ]+)"

How Locust can extract value from response then using for next sequence request

I'm looking for an alternative tool to Gatling and found Locust. I found it's powerful but I wonder how can I extract a Json value and then using that value in the Json payload of the next request (please note the Json payload is in different file). Like in Gatling we can use saveAs() and the value will be store in the session variable, then we can put that value in Json payload.
Thanks,
Hoang
Locust is pretty much just Python, using the requests http client, so look in to the requests documentation for more info.
Lets assume /login returns a session_id in the json response that we want to use in future requests. You would then do something like this in your task:
response = self.client.post("/login")
session_id = response.json()["session_id"]
self.client.post("/foo", json={"session_id": session_id})

Dynamic Refid is appended to the URL but i can't find refid in the response

When i perform the action on UI a dynamic refid is appended to the URL using query string parameter. I can't find that refid in the response but its part of the request. In the code i only found the variable.
Here is the URL on UI.
https://XXXXXX.XXXXXXXXXXXX.com/Recruiter/#!/candidate/new/157072048
I captured the Get request for the same action using the developer tool on Chrome and it looks like this.
Request URL: https://XXXXXX.XXXXXXXXXXXX.com/Pages/candidate/new.aspx?refid=157072048&mode=quick
This Get request has 2 query string parameter.
refid: 157072048
mode: quick
Now i need to captured that refid and pass it the step 2 to be able to create that record. I need help to figure this out.
I found comment in the html that may be help full.
// referenceid - only used with the "Web" app, gets mapped to "&refid=123" in the query string, and ends up as Page.ReferenceID in WebForms.
If this is not a part of a response data then it might be the case it's generated on the client by JavaScript code. You need to figure out how the value is being generated and replicate the same code using JSR223 Test Elements and Groovy language.
Another possibility is that the value comes from an Ajax request which JMeter doesn't execute because it cannot execute client-side JavaScript. In this case you need to simulate the same request and extract the value from there.
And last but not the least, the number you're looking for may reside in one of the sub-samples which may appear as the result of Redirection and you're trying to find it in main sampler response:

How to get URL having ".../?where={'key1' : 'value1' , 'key2' : 'value2':.........}" in Jmeter http request

I need to load test one Python api in below URL format:
//IP:PORT/Sub_Part/?where={"KEY1":"VALUE1","KEY2":"VALUE2","KEY3":"VALUE3"}
I tried to pass the key value pair through csv as well as directly in http request but getting error message.
java.net.URISyntaxException: Illegal character in query at index 47:
http://IP:PORT/Sub_Part/?where={"KEY1":"VALUE1","KEY2":"VALUE2","KEY3":"VALUE3"}
Here key and value are dummy data I have placed here for easy understanding.
Please help me with correct syntax for this URL.
Thanks in advance for all your help.
In REST APIs, JSON objects are typically sent (POST) or returned in the body of the request. They are not typically encoded as part of the URL.
For a GET request, you can either pass the information as segments in the url or as querystring parameters.
For more details refer here, How to send a GET request with a "/" in the query
As per HTML URL Encoding Reference:
URLs can only be sent over the Internet using the ASCII character-set.
so you need to define the request in JMeter's HTTP Request sampler as follows:
Pay attention to URL Encode? checkbox, it has to be ticked otherwise the parameter will be sent "as is"
Another option is using __urlencode() function like:
http://IP:PORT/Sub_Part/?where=${__urlencode({"KEY1":"VALUE1"\,"KEY2":"VALUE2"\,"KEY3":"VALUE3"})}
which will generate an encoded sequence which you could use in the URL path:
%7B%22KEY1%22%3A%22VALUE1%22%2C%22KEY2%22%3A%22VALUE2%22%2C%22KEY3%22%3A%22VALUE3%22%7D
as you can see, all non-ASCII characters where removed.
Check out Apache JMeter Functions - An Introduction to learn more about JMeter Functions concept.

Capture a header value from the response in Jmeter and re-use

I'm calling a REST request for authentication. And I need to get the session ID sending on response; in order to reuse that in my next request.
session id comes in Response header. When I use view result tree, this is not showing header parameters(response body has no data).
When googling I found a method using Regular expression Extractor method, but seems it works only when data in response body.
Nope, Regular expression extractor can search in headers also. You need to specify where to search.
See example,
This will search in headers and you can specify in main samples, sub samples also.

Resources