JMeter - Adding a json response from a file and set it as response body in a get request - testing

Im doing some json validating. I need to be able to add a local json file to a response in dummy sampler.
This because i need to validate new json files every day.
I figure out that i might use the JSR223 Post Response to get the file from a folder then set the Sampleresult.setResponseData to JSON.
Is there anyone who have a clue how i fo this?

The easiest is using __FileToString() function, you can put it to the "Response Data" field of the Dummy Sampler and it will read the file from the file system and respond with the file's contents:
If you have a folder with multiple JSON files and want to read them sequentially or randomly - consider using Directory Listing Config Plugin

Related

JSZip reports missing bytes when reading back previously uploaded zip file

I am working on a webapp where the user provides an image file-text sequence. I am compressing the sequence into a single ZIP file uisng JSZip.
On the server I simply use PHP move_uploaded_file to the desired location after having checked the file upload error status.
A test ZIP file created in this way can be found here. I have downloaded the file, expanded it in Windows Explorer and verified that its contents (two images and some HTML markup in this instance) are all present and correct.
So far so good. The trouble begins when I try to fetch that same ZIP file and expand it using JSZip.loadAsync which consistently reports Corrupted zip: missing 210 bytes. My PHP code for squirting back the ZIP file is actually pretty simple. Shorn of the various security checks I have in place the essential bits of that code are listed below
if (file_exists($file))
{
ob_clean();
readfile($file);
http_response_code(200);
die();
} else http_response_code(399);
where the 399 code is interpreted in my webapp as a need to create a new resource locally instead of trying to read existing resource data. The trouble happens when I use the result text (on an HTTP response of 200) and feed it to JSZip.loadAsync.
What am I doing wrong here? I assume there is something too naive about the way I am using readfile at the PHP end but I am unable to figure out what that might be.
What we set out to do
Attempt to grab a server-side ZIP file from JavaScript
If it does not exist send back a reply (I simply set a custom HTTP response code of 399 and interpret it) telling the client to go prepare its own new local copy of that resource
If it does exist send back that ZIP file
Good so far. However, reading the existent ZIP file into PHP and sending it back does not make sense + is fraught with problems. My approach now is to send back an http_response_code of 302 which the client interprets as being an instruction to "go get that ZIP for yourself directly".
At this point to get the ZIP "directly" simply follow the instructions in this tutorial on MDN.

Blue Prism webservice call and csv download

I am trying to configure Blue Prism to make an API call, and then response of this API is a csv file.
Currently I have configured the webservice with "GET" command on the base URL.
But I am not sure what needs to be done in order to download / save the csv file that the API sends. I am assuming that it needs to be explicitly told.
Please help!
In your process, make the HTTP request to the API using the Utility - HTTP VBO's HTTP Request action. Store the Result output parameter in a Text-typed Data Item.
If you need to process the data in a tabular format...
Once the CSV data is there, you can use the Get CSV As Collection action in the Utility - Strings VBO to parse the CSV content into a collection:
If you need to simply save the file...
... use the Utility - File Management VBO's Write Text File action and point it to the location you need to save the CSV to:

How to read test data from external JSON file and compare with postman response?

I have array of test data json file in local machine. I am writing a test in postman and trying to compare the response against the test data. Instead of doing it in collection runner, is it possible to pass the test data into Tests and compare with the response?
This is not something that is currently supported in Postman:
https://github.com/postmanlabs/postman-app-support/issues/7210
Alternatively what you could do
Copy/paste content of file (assuming it's not huge) and read into a variable which you could then do a string comparison against.
Store the content of the file in an endpoint where you can request it in the pre-request script, save it to a variable then do string comparison.
Neither solution is pretty in my opinion but probably the best you can do.

Jmeter - Err in response body when send body data from external file

I have a scenario to send data in the request body from external file in jmeter and when I send it, I have got the ERR in the response body. Here is my post method request body:
${__FileToString(/Users/public/${__eval(${validUrls})}.txt,,)}
Response:
POST data:
ERR
Please help why I can not send data from external file.
Anis
There is no issue with your function syntax, just make sure that:
Your validUrls JMeter Variable has the anticipated value (you can check it using Debug Sampler and View Results Tree listener combination)
The user which is running JMeter has read access to the files under Users/public/ folder
The file is being properly read and sent (look at Request -> Request Body) tab of the View Results Tree listener, if you see **ERR** there - it means that your function fails somewhere somehow, the reason of failure can be found in jmeter.log file

Updated JSON file is not reading during runtime

Team,
I have service to register a user with certain data along with unique mail id and phone no in JSON file format as a body (for ex: registerbody.json).
Before Post call I am generating unique mail id , phone no and updating the same json file (registerbody.json) fields which is in the same folder where feature file locates. I see the file is updated with the required data during runtime.
I used read () method and performed POST request
Surprisingly read method is not taking updated JSON file instead it is reading old data in the registerbody.json file.
Do you have any idea on this, why it is picking up old data even though file is updated with the latest information?
Please assist me with this.
Karate uses the Java classpath, which is typically target/test-classes. So if you edit a file in src/test/java Karate won't see it unless it is copied. This copying is automatically done when you build / compile your code.
My suggestion is use target/ as a temp folder and then you can read using the file: prefix:
* def payload = read('file:some.json')
Before Post call I am generating unique mail id , phone no and updating the same json file (registerbody.json)
You are making a big mistake here, Karate specializes in updating JSON based on variables. I suggest you take 5 minutes and read this part of the docs VERY carefully: https://github.com/intuit/karate#reading-files
Especially the part about embedded expressions: https://github.com/intuit/karate#embedded-expressions