user3212324 user3212324 - 29 days ago 13
Groovy Question

Groovy Script - Automatic Request and saving response from SOAP UI

I am new to Groovy scripting.

Requirement To read the request values from a text file and pass it to the soap request xml and save the output.

Issue facing: I am not able to read the data from step 1 to step 2. However I am setting the values in context variable as well. Kindly help me to fix the issue so that I can able to automate the entire process.

Note: We have only access to SOAPUI not SOAPUI Pro

Step 1:

File file1 = new File("C:\\Users\\Groovy Test\\requests\\orders.txt")
List textLine = file1.readLines()
log.info textLine
context.put('textLine', textLine)
log.info textLine


Step 2:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<OrderId>${context.get('textLine' )}</OrderId>
</soapenv:Body>
</soapenv:Envelope>


Step 3:

def fileList = context.get('textLine')
def fileName = fileList.pop()
def newname = fileName[0..-5]
def response = context.expand( '${Step2#Response}' )
def f = new File("C:\\Users\\Groovy Test\\responses\\${fileName}_Response.xml")
f.write(response, "UTF-8")
if(fileList.size() >0)
{
testRunner.gotoStepByName("Step2")
}

Answer

I think that the problem is the notation in the Xml of the step 2:

Use:

<OrderId>${=context.get('textLine')}</OrderId>

Instead of:

<OrderId>${context.get('textLine')}</OrderId>

Note the = character.

Comments