We are building a new experience for our SmartBear Community.
This site is now read-only. You can still browse and search as usual. Learn More
This site is now read-only. You can still browse and search as usual. Learn More
In that case, I would suggest the following:
Have the original file with data as below which uses property expansion as mentioned earlier, you may call it template request.
<abc-request client-application-id="JUnit client" client-domain="JUnit client Domain">
<payload>
<modify-UG>
<charging-id type="msisdn">${#TestCase#MSISDN}</charging-id>
</modify-UG>
</payload>
</abc-request>
Before your json step, have a groovy step which does the transformation of the data and saves into a file in the temporary directory by replacing the MSISDN value.
This way, we always only read the template file(remains same) and create a new temporary file and that is sent as attachment each time. So, no overwriting of that template file.
def tmp = System.getProperty('java.io.tmpdir')
context.testCase.setPropertyValue('FINAL_DIR', tmp)
def originalFilePath = context.expand('${#TestCase#ORIGINAL_FILE_PATH}')
def fileName = context.expand('${#TestCase#FINAL_FILE}')
def content = new File(originalFilePath).text
new File("${tmp}/${fileName}").write(context.expand(content))
Note: If you are using ReadyAPI, then you may avoid additional groovy step, instead use Events feature, TestStep.beforeSubmit and have the above script in it
In the attachment, you define the custom properties as below:
Hi
Answer: Actually property expansion does it. It is right. But my project requirement is
1. Keep base xml request file at any external location.
2. Call it in the requests. Change some properties values.
So that going forward, if there any changes in the requests, we have do maintenance in externalized file only. Not inside the scripts.
Thanks very much for your solution. It really helped me.
Ohh. That's really good idea.
But before this workaround, I have tried this.
1. Following is my externalized request.xml file
<abc-request client-application-id="JUnit client" client-domain="JUnit client Domain">
<payload>
<modify-UG>
<charging-id type="msisdn">${#TestCase#MSISDN}</charging-id>
</modify-UG>
</payload>
</abc-request>
2. Call request from external request file (For this, In requests, I am using media type as 'text/xml' and attaching the .xml file)
Issue:
When I passed custom properties(${#TestCase#MSISDN}) inside request.xml file, it is not picking the value of of custom property.
So Can you please correct me if I am missing anything here. This will be very straightforward solution for me.
regards
Vishal
Hi nmrao
You are right. In the request editor, it will still the property expansion.
But I am sending my request using file. For this, In requests, I am using media type as 'text/xml' and attaching the .xml file
So Files sent as a part of requests are affected by property expansion ? (I mean file content changes as per property expansion ?)
Or alternatively ,
I can use groovy script to send request. I can call my base request.xml file. Change values using property expansion inside groovy script. (U already provided solution above for same)
But can you please suggest me the part - how should I send request using groovy script ?
This will be fully feasible solution.So that my base request.xml file will remain unchanged at all.
Just I have to call base externalized request.xml - Change property values using property expansion and send request using same groovy script.
can you Please help on this.