Micro Focus QTP (UFT) Forums
Sending json file request and validating response in soap UI tool using Groovy script - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Sending json file request and validating response in soap UI tool using Groovy script (/Thread-Sending-json-file-request-and-validating-response-in-soap-UI-tool-using-Groovy-script)



Sending json file request and validating response in soap UI tool using Groovy script - smiley - 07-19-2017

Hi,

I am sending json files as request and getting responses in soap UI tool using groovy script for Rest Project.

but i found error in step 2, as it is not retrieving the content of json file. below is my code.

If u people have code for this in Groovy language plz post it ASAP. 

Steps:-
--------
1. Retrieving data from json file 
2. content from json file should place in body (parameters), send request and get response
3. the response should pass it to json file and validate the response

Step1: (Script)
------------------

def fileList = []
new File("C:\\GroovyTest\\requests").eachFile { f ->
if (f.isFile() && f.name.endsWith('.json')) {
   def filename = f.name[0..-1]
     fileList.add(filename)
     log.info filename
}
}
if (fileList.size() < 1) {
   testRunner.fail("No request files")
}
context.put('fileList', fileList)


Step2: (Script) 
-------------------

${=new File("C:\\GroovyTest\\requests\\"+(context.get('filelist')).last()).text)


Step3SadScript)
------------------

def fileList = context.get('fileList')
if (fileList != null)
{
def fileName = fileList.pop()

def newname = fileName[0..-5]

def response = context.expand( '${Step2#Response}' )
def f = new File("C:\\GroovyTest\\responses\\${fileName}_Response.xml")
f.write(response, "UTF-8")

if(fileList.size() >0)
{
testRunner.gotoStepByName("Step2")
}
}

Thanks
smiley