问题
In Karate, can I update a value for one of the fields in a Request payload (JSON format) automatically?
I am working on the following scenario - 1. Submit a POST request to create an object. A Request payload (JSON format) is used. 2. Query DB to verify that this object is created. Each object creation generates a unique ID. 3. Submit another POST request to delete this object created in Step 1. A seperate request payload (JSON format) is used.
PROBLEM - How do I automatically update the request payload to delete this object? The only thing that needs to be updated in this payload is the ID field with ID's value which I will grab from the DB (step 2). Basically, all but the ID field values in Delete payload remains the same. I need this ID to update during the run time...Any ideas?
Is there a better way to accomplish this?
Thank you
回答1:
Yes this is easy in Karate. I suggest you read the documentation. The "hello world" example itself shows how to use a value coming back from the response.
This example shows how to get values from a database using Java interop: dogs.feature
And here is how you update any JSON, JS-style: https://stackoverflow.com/a/62294932/143475
Instead of asking a broad question like this, I suggest you create a real example, and ask a specific question only if you get stuck.
来源:https://stackoverflow.com/questions/62329495/in-karate-can-i-update-a-value-for-one-of-the-fields-in-a-request-payload-json