Forum Discussion
Hi all !
Another question related:
We are using JSON files to load all the body parameters for a Test Suit with a lot of Test Steps. Most of this parameters are diferent for each Test Step, but they have some common parameters. And every time that some change is done, we should modify every single JSON.
So, We want to automate the JSON's preloading
We are considering to upload files with "file Wait", and before executing the test we want to predefine this common fields.
Which is the best way to do it? Some idea before starting?
Example, All bellow Test Cases have common parameters, but every once in a while we need to change them :
departure: "BCN",
arrival : "LGW",
departureDateTime : "2017-01-04",
Thanks very much
Anna
Hi, Anna!
If I understood you correctly, you want to load a JSON that should go to request body from a file, but then change some of its fields during test execution. So, in your example departure, arrival and departureDateTime already exist in JSON file, but you want to change them, while leaving the rest of the parameters as they are in the file, right?
For this scenario you can use File Wait and then Property Transfer with several transfers: the first one should move the file content to the whole request body, and others should move each of your predefined values for common fields to the specific request fields via JSONPath. As transfers are executed in the order of their positions in the list, this should work fine.
Say, your TestCase have 2 custom properties: departure and arrival (you can change its values in groovy script test step at any stage of your test). Then you need one FileWait step in the beginning of your test. Then goes PropertyTransfer, and then - your POST Request.
PropertyTransfer will have 3 transfers (make sure path expressions are correct for your JSON):
1) wholeRequest (Source: FileWait, Property: fileContent; Target: POST Request, Property: Request);
2) departureTransfer (Source: TestCase, Property: departure; Target: POST Request, Property: Request, Path Language: JSONPath, Path: $.departure);
2) arrivalTransfer (Source: TestCase, Property: arrival; Target: POST Request, Property: Request, Path Language: JSONPath, Path: $.arrival).
To execute a request several times with different predefined values, it's more convenient to create a DataSource Loop with some type of DataSource (e.g. Grid, where your can just type your values in the table). DataSource should have properties that correspond your predefined parameters (departure and arrival in my case). Target step for DataSource Loop should be PropertyTransfer. And in Property Transfer for departureTransfer and arrivalTransfer you'll just need to change Source step to DataSource.
- amarcilla8 years agoOccasional Contributor
Hi Anton,
Thanks very much for your answer, we are following your suggestions.
Now, we found a problem executing the second Transfer, the value is changed correctly, but now all the JSON null values, somehow, during the transfer are all switched over to { }. Can we keep it with null like the original request?, otherwise we are getting Err in Our Response.
Thanks very much
anna
- AntonE8 years agoSmartBear Alumni (Retired)
Hi, Anna,
Ready! API parses JSON to make a property transfer to the position specified in JSON path and then regenerates string representation with a changed field - I think that's when it replaces null with {}. It seems like a bug in our JSON library, or the library might need some extra configuration. I'll create an issue for that and see what we can do.
- amarcilla8 years agoOccasional Contributor
Hi Anton,
Any update related to the issue?.
Any other way to replace parameters?.
With this issue we can not work very much with automationThanks very much
Anna - AntonE8 years agoSmartBear Alumni (Retired)
Hi Anna
The issue isn't fixed yet. I can suggest a simple workaround though - using Groovy script to replace {} with "null" values. You should add a Groovy test step right after Property Transfer with the following script (assuming POST Request is your request with corrupted null fields):
import com.eviware.soapui.model.testsuite.TestStep String request = context.expand( '${POST Request#Request}' ) String correctedRequest = request.replace("{}", "null") TestStep testStep = testRunner.getTestCase().getTestStepByName("POST Request") testStep.setPropertyValue("Request", correctedRequest)
Hope it helps.