Marwa Abdelgawad Marwa Abdelgawad - 1 month ago 15
Groovy Question

groovy.lang.MissingPropertyException: No such property: file for class: Script7 error at line 5

I am writing groovy script to save raw soap request & response and i get this error:


groovy.lang.MissingPropertyException: No such property: file for class: Script7 error at line 5


Here is the Script:

def myOutFile = context.expand( '${#TestSuite#fileName}' )+"_PostPaid-Success_Payment_BillInqReq.xml"
def response = context.expand( '${BillInq#Request}' )
def f = new File(myOutFile)
f.write(response, "UTF-8")
file.write(context.rawRequest,'utf-8')


Test Suite properties

Test case

Rao Rao
Answer

Please follow the steps below:

  • Go to Test Suite PostPaid
  • Add a custom property say DATA_STORE_PATH and its value to a directory name where you like to save the requests and responses
  • Go to test case PostPaid_Success_Payment
  • Disable the Step 2 & Step 3 i.e., SaveInquiryReq and SaveInquiryResponse steps. or you may remove altoger as well if no other work is done apart from save the request & response respectively.
  • Click on step1 BillInq, click on assertions, Choose Script Assertion, see here for more details how to add script assertion
  • Have below script and click ok
  • Now you run the step1, you should be able to see the request and responses saved in the above mentioned directory
/**
 * This script logs both request and response
 */

assert context.response, "Response is empty or null"
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 dirToStore = context.expand('${#TestSuite#DATA_STORE_PATH}')
 def currentStepName = context.currentStep.name
 def requestFileName = "${dirToStore}/${currentStepName}_request.xml"
 def responseFileName = "${dirToStore}/${currentStepName}_response.xml"
 //Save request & response to directory
 saveToFile(new File(requestFileName), context.rawRequest)
 saveToFile(new File(responseFileName), context.response)
Comments