Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending json file request and validating response in soap UI tool using Groovy script
#1
Not Solved
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  UFT RESTFUL API. Please pass json issue kul20 0 2,312 08-06-2018, 07:16 PM
Last Post: kul20
  Extract and save a file from zip folder using VB Script karthicksri07 1 6,448 06-29-2016, 02:19 PM
Last Post: Ankesh
  [VBScript] Json: get VALUE by NAME robertosalemi 0 4,963 02-25-2016, 08:18 PM
Last Post: robertosalemi
  [UFT][JSON] Validate Json file robertosalemi 0 3,831 02-10-2016, 04:36 PM
Last Post: robertosalemi
  qtp script for updating values in xml file automation2012 3 11,568 11-30-2015, 11:07 AM
Last Post: Lavanya N

Forum Jump:


Users browsing this thread: 1 Guest(s)