SoapUI NG Pro
  • Preface
  • 1. About SoapUI NG Pro
    • 1.1 Introduction to SoapUI NG Pro
    • 1.2 Application Installation Instructions
    • 1.3 License installation instructions
  • 2. Ready API - How to use
    • 2.1 Creation of Project:
    • 2.2 Test Case Creation
    • 2.3 Assertions
      • Assertions - In Nutshell
      • Groovy Request and Response Save
      • Script Assertion
    • 2.4 Data Driven Testing
  • 3. Execution in SoapUI NG Pro
    • 3.1 Running Tests From Test Steps
    • 3.2 Running Tests From Test Suites
    • 3.3 Running Test From Project Level
  • 4. Report Generation in SoapUI NG Pro
    • 4.1 Test case Level
    • 4.2 Test Suite Level
    • 4.3 Project Level
  • 5. Continuous Integration
    • 5.1 Jenkins ReadyAPI - Installation instruction
    • 5.2 CreateTests from Jenkins
    • 5.3 Run Tests from Jenkins
    • 5.4 Resolve License errors in Jenkins
Powered by GitBook
On this page

Was this helpful?

  1. 2. Ready API - How to use
  2. 2.3 Assertions

Groovy Request and Response Save

Groovy Script to save your request and responses in a particular location.

//Get the project path storage location
def projectPath = new com.eviware.soapui.support.GroovyUtils(context).projectPath.replace("\\", "/") //gets the path of the project root
//log.info(projectPath)
//Save the request and response in the below location
context.testCase.testSuite.setPropertyValue("XMLReqResLoc",projectPath+"/TestResults/")


//Check if there is response
assert context.request, "Request is empty or null"

//Save the contents to a file
def saveToFile(file, content) {
    if (!file.parentFile.exists()) {
         file.parentFile.mkdirs()
         log.info "Directory did not exist, created"
    }
    file.write(content) 
    assert file.exists(), "${file.name} not created"
}
def testCaseName = context.testCase.name.take(10) 
def testStepName = context.testCase.getTestStepAt(context.getCurrentStepIndex()).getLabel() 
def timeZone = TimeZone.getTimeZone("PST")
def dateStamp = new Date().format("yyyyMMdd",timeZone)
def timeStamp = new Date().format("yyyyMMdd_HHmmss",timeZone).toString()
def storageLocation = context.testCase.testSuite.getPropertyValue("XMLReqResLoc")
def requestFile = new File("${storageLocation}/${dateStamp}/Requests/${timeStamp}_${testCaseName}_${testStepName}_Request.xml")
def responseFile = new File("${storageLocation}/${dateStamp}/Response/${timeStamp}_${testCaseName}_${testStepName}_Response.xml")
saveToFile(requestFile, context.requestContent)
saveToFile(responseFile, context.response)

//To call in other scripts place below line
//context.testCase.testSuite.testCases["<TestCaseName>"].testSteps["<TestStepName>"].run(null,context)
PreviousAssertions - In NutshellNextScript Assertion

Last updated 5 years ago

Was this helpful?