In J.meter I need to test multiple web-services in single scenario like, after successful execution of service one it will gives session-Id and this session id will take by other services and check it and complete the scenario as per business logic?
It is classic question regarding "correlation" in JMeter. Correlation stands for the process of extracting dynamic data from previous response and passing it to the next request.
Add a JSON Extractor as a child of the first request and define a JSON Path query to extract the session-Id value and and store it into a Jmeter Variable.
Use the aforementioned JMeter Variable as the session-Id for the subsequent requests.
See API Testing With JMeter and the JSON Extractor article for comprehensive instructions.
Related
I recorded my jmeter script on server x and make it dynamic after that run that same script on server y - it fetch all data by post processor and did not give any error but data is not added on fronted . how can I solve it any reason behind it? (website is same just change the server for testing)
expected-Data should add on fronted like create lead on server y (successfully create on server x)
actual -data not added on server y
Most probably you need to correlate your script as it is not doing what it is supposed to be doing.
You can run your test with 1 virtual user and 1 iteration configured in the Thread Group and inspect request and response details using View Results Tree listener
My expectation is that you either not getting logged in (you have added HTTP Cookie Manager to your Test Plan, haven't you?) or fail to provide valid dynamic parameters. Modern web applications widely use dynamic parameters for example for client side state tracking or for CSRF protection
You can easily detect dynamic parameters by recording the same scenario one more time and compare the generated scripts. All the values which differ need to be correlated, to wit extracted from the previous response using a suitable Post-Processor and stored into a JMeter Variable. Once done you will need to replace recorded hard-coded value with the aforementioned JMeter Variable.
Check out How to Handle Correlation in JMeter article for comprehensive information with examples.
I have implemented an /GET HTTP endpoint to provide search feature. The user sends search terms in query parameters and receives JSON response containing all search results.
Now I have to add a new feature i.e. save search. It means the user sends same search parameters and can also send a boolean parameter say save=true. I have to save the search term in database in this case for future uses. However this parameter is not mandatory.
I am confused over the following points:
Modify same GET HTTP endpoint allowing additional save parameter in query parameters.
Modify same GET HTTP endpoint but passing save parameter in request body instead of query parameters as its backend state changing parameter.
Use separate endpoint for save the parameters using POST method.
What is the standard/acceptable way of doing this?
As far as I understood your question you try to store a search request and by storing it also retrieve the response in one go?
Usually GET is used to retrieve a resources' state though as this method is defined as safe it shouldn't be used if certain state is created for the invoked resource as persisting the search query would be. RFC 7231 further states that:
A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.
I therefore would refrain from option #1 or #2 as this might break interoperability by certain clients.
POST on the otherhand is defined in RFC 7231 as
The POST method requests that the target resource process the representation enclosed in the request according to the resource's own specific semantics.
It therefore should be used in every situation the other HTTP operations don't fit. The HTTP spec further defines that creating a new resource a 201 Created HTTP status code should be returned including a HTTP response header named Location containing the URI of the created resource. This URI can later be used to retrieve it's state (i.e. the performed search result).
From a client's perspective you are basically storing some query definition on the server and don't care where or how the server is actually persisting it. All you care is to retrieve a handle you can later on invoke. This doesn't prevent the server from returning the current search result within the response payload. And this is what I'd do exactly.
Proposed steps:
Send search request via POST
Store query definition
Generate the URI for the stored query
Perform the search according to the query
Return a response with a 201 Created status code and Location header pointing to the URI of the stored query and add the query result within the response payload
A client can later on use the returned URI to retrieve the current state of the resource, which the server can interpret as: execute the query stored for that URI and return the search result.
How the URI has to look like is not defined by the REST architecture. You might generate UUIDs or generate a hash value based on the query generate. The latter approach has the benefit that multiple identical queries wouldn't result in additional queries created but in the reusage of such. In such cases a redirect to the existing query resource should be performed to tell the client that his query already existed which also teaches the client the actual URI of the query resource as a side effect.
I want to build a RESTFUL API.
I have a resource with task plans.
The client should request the server to run task such as benchmarking on one of the task plan metrics.
which request should be used. POST or GET?
and what should be the uri?
/api/plans/<id>/run or /api/plans/run/<id> ?
I will go for a POST and since is an action on a specific plan, the url should be plans/id?action=run.
run is not a sub collection of a plan so query param must be used in this case
GET requests are used for reading/getting data. POST requests are for creating data.
If the user just needs to see the results of a benchmark run, I would use a GET request that returns the results of the benchmark method for the plan.
For retrieving a single record, the URL convention is /things/:id, so I would recommend api/plans/:id/run. I also recommend renaming run to something more descriptive, like benchmark or metrics.
I have written Xquery assertion in SOAP UI request its working fine. But i want to compare output of this with database. Can I add code to get the values from database in Expected panel of XQuery assertion of SOAP UI. If not is there any way where I can compare the xml response of a request with column values of a database
You can do it the following way:
Call a service with a Soap request
Make a property transfer from the service response to a test case variable, see the SoapUI docs for more information. You can use XPath or XQuery. See the picture bellow.
Make a JDBC request to your database and compare the results with the data stored in your test case variable.
This way is intuitive and effective for simple comparissons, for complex tests I would choose Groovy scripting.
One of the external .NET desktop application is supposed to update our internal MySQL database (Couple of inserts and updates). We’ve agreed to expose a REST web service in order to facilitate this.
I’m thinking of accepting the inputs as a String in JSON format and process inside my REST service. Since there’s lot of values are supposed to be passed into this web service, I’m expecting the inputs in a JSON format without having them in query string or as in params. Is this the best/acceptable way of handling these kind of cases or any other any way of designing this?
If you want insert or update a resource through rest then following is the best practices to design it.
Insert
Request: POST /resources
Body {data in json format}
Response : 201 Created
Update
Request : PUT /resources/{id}
Body {data in json format}
Response : 200 OK
Here you can replace "resources" with the term that you want to manage through rest service. And {id} in second case is the identifier which can identify the resource you want to update in your repository.