Forum Discussion
5 Replies
- KarelHusaChampion Level 2
You can store all requests and responses of the test steps included in a test case with the following script.
You need to:
1. set the TearDown script of the test case to the code bellow.
2. define the 'outputDirectory' property on the project level to the required path, e.g. /C:/testing/out
File outDir = new File(testRunner.testCase.testSuite.project.getPropertyValue( "outputDirectory") + "/" + testRunner.testCase.testSuite.getName() + "/" + testRunner.testCase.getName()) outDir.mkdirs() File reponseFile File requestFile testRunner.results.each { // WsdlTestRequestStepResult requestFile = new File(outDir, it.getTestStep().getName() + "-Request.xml") responseFile = new File(outDir, it.getTestStep().getName() + "-Reponse" + "-" + it.getStatus() + ".xml") requestFile << it.getRequestContent() responseFile << it.getResponseContent() }
- Bala_1980Occasional Contributor
Hi, how to store the entire xml responses in the specified location by using Groovy Scripting.
- nmraoChampion Level 3
Create a test case level custom property, say FILE_PATH and provide the value say 'c:/temp/myfile.xml'
Please use script assertion for the request test step.
//Check the response is not empty assert context.response, "Response is empty or null" //Save response new File(context.testCase.getPropertyValue('FILE_PATH')).write(context.response)
- nmraoChampion Level 3Did you try below for single response? Then add the same for different tests for multiple occurrences.
- Bala_1980Occasional Contributor
Hi, its working now with the following lines of code:
def myOutFile = "File Path"
def response = context.expand( '${Methodname#Response}' )
def myOutFile1 = new File(myOutFile)
myOutFile1.write(response, "UTF-8")
Related Content
- 4 years ago
- 4 years ago
- 2 years ago
Recent Discussions
- 3 days ago