InterviewSolution
Saved Bookmarks
| 1. |
Write a Groovy Script to save request and response in SoapUI? |
|
Answer» A Groovy SCRIPT for saving a request and RESPONSE in SoapUI is as follows: def projectName = context.currentStep.testCase.testSuite.project.name //GETTING the name of the projectdef projectDate = new Date().format( 'yyyyMMdd' )//getting the current datedef stringDate = projectDate.toString()//converting the projectDate into string typedef projectTestSuite = context.currentStep.testCase.testSuite.name//geting the Test Suite name of the projectdef projectTestCase = context.currentStep.testCase.name//getting the Test Case name of the projectdef filePath = 'C:/SoapUI Projects/TS0.1/TestEvidence/'+projectName+'_'+stringDate+'/'+projectTestSuite+'/'+projectTestCase+'/'//composing the path of the fileFile file = new File(filePath)if (!file.exists()) file.mkdirs()//CREATING the destination folderfos = new FileOutputStream(filePath+ testStepResult.testStep.label + '.txt', TRUE)pw = new PrintWriter(fos)testStepResult.writeTo(pw)pw.close()fos.close()A groovy event handler saves requests and responses for each test step, while a script below captures the requests and responses. 'TestRunListener.AfterStep' is the event handler. |
|