sgsoapuser
12 years agoOccasional Contributor
groovy script to write response to excel file
Hi,
I am new to groovy scripting. I am using free version of SOAPUI. I want to write test responses to excel file using groovy scripts. I found a script on google which I modified as per my test response.
Test step name: login-Request1.
Here is my test response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:loginResponse xmlns:ns1="http://abc.com/">
<ns1:result>
<ns1:Session>T6EBJrSHS9bOMpFvb57Pi6qR5VsJxsCifu6DG9G2aguKVRHDTDciuVvFUS8</ns1:Session>
<ns1:ServerUrl>https://abc.com/38.0</ns1:ServerUrl>
</ns1:result>
</ns1:loginResponse>
</soapenv:Body>
</soapenv:Envelope>
The groovy script :
import jxl.*
import jxl.write.*
// create an excel workbook
WritableWorkbook workbook1 = Workbook.createWorkbook(new File("c:\\report.xls"))
// create a sheet in the workbook
WritableSheet sheet1 = workbook1.createSheet("Report Worksheet", 0)
// Get the data to be added to the report
def fieldFromResponse = context.expand( '${login-Request1#Response#declare namespace ns1=\'http://abc.com\'; //ns1:loginResponse[1]/ns1:result[1]/ns1:Session[1]}' )
// create a label
Label label = new Label(0, 0, fieldFromResponse);
// Add the label into the sheet
sheet1.addCell(label);
workbook1.write()
workbook1.close()
The excel sheet gets created in local drive but however I see its empty.
I believe I am using wrong syntax while retrieving the Session value.
Appreciate if someone could help me on this ASAP.
Thank you.
I am new to groovy scripting. I am using free version of SOAPUI. I want to write test responses to excel file using groovy scripts. I found a script on google which I modified as per my test response.
Test step name: login-Request1.
Here is my test response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:loginResponse xmlns:ns1="http://abc.com/">
<ns1:result>
<ns1:Session>T6EBJrSHS9bOMpFvb57Pi6qR5VsJxsCifu6DG9G2aguKVRHDTDciuVvFUS8</ns1:Session>
<ns1:ServerUrl>https://abc.com/38.0</ns1:ServerUrl>
</ns1:result>
</ns1:loginResponse>
</soapenv:Body>
</soapenv:Envelope>
The groovy script :
import jxl.*
import jxl.write.*
// create an excel workbook
WritableWorkbook workbook1 = Workbook.createWorkbook(new File("c:\\report.xls"))
// create a sheet in the workbook
WritableSheet sheet1 = workbook1.createSheet("Report Worksheet", 0)
// Get the data to be added to the report
def fieldFromResponse = context.expand( '${login-Request1#Response#declare namespace ns1=\'http://abc.com\'; //ns1:loginResponse[1]/ns1:result[1]/ns1:Session[1]}' )
// create a label
Label label = new Label(0, 0, fieldFromResponse);
// Add the label into the sheet
sheet1.addCell(label);
workbook1.write()
workbook1.close()
The excel sheet gets created in local drive but however I see its empty.
I believe I am using wrong syntax while retrieving the Session value.
Appreciate if someone could help me on this ASAP.
Thank you.