07-19-2017, 04:58 PM
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)
Step3Script)
------------------
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
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)
Step3Script)
------------------
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