Solved
Forum Discussion
Azeddin_Margani
8 years agoContributor
Thanks Lucian for the reply.
The sample data is generated by executing request. Instead of reading it from an external file is it possible to replace:
// Parse response def xml = new XmlSlurper().parse("D:\\test.txt")
by:
//Read response Xml
def reqOperationName="GetMyRequest";
def groovyUtils=new com.eviware.soapui.support.GroovyUtils(context)
def resholder = groovyUtils.getXmlHolder(reqOperationName+"#ResponseAsXml")
Thanks.
Lucian
8 years agoCommunity Hero
Hi, I didn't quite get if the last post was a question or a statement :smileylol: Anyways.. so if I have a project like:
.. where the xml is taken from a response then the code can stay the same except for the first part:
import java.io.File; import java.io.IOException; import java.util.Date; import jxl.*; import jxl.write.*; import jxl.write.Boolean; import jxl.write.Number; import jxl.write.biff.RowsExceededException; //Read xml response def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) // Parse response def xml = new XmlSlurper().parseText( groovyUtils.getXmlHolder( "GetResponse#ResponseAsXml" ).getPrettyXml() ) try { // Create the excel file File exlFile = new File("D:/target_file.xls"); final WritableWorkbook writableWorkbook = Workbook.createWorkbook( exlFile ); // Create a sheet in the excel file final WritableSheet writableSheet = writableWorkbook.createSheet("Sheet1", 0); // Prepare to loop through the file Label label = new Label(0, 0, ""); def i = 0 def currentElement = '' // Start looping for each item while (( currentElement = xml.e[i]) != '') { // Create cell with the column index i label = new Label(0, i, currentElement.toString()); // Add the created Cells to the sheet writableSheet.addCell(label); i++ // Increment index } //Write and close the workbook writableWorkbook.write(); writableWorkbook.close(); } catch (IOException e) { e.printStackTrace(); } catch (RowsExceededException e) { e.printStackTrace(); } catch (WriteException e) { e.printStackTrace(); }
Don't forget about that library I attached to you. Cheers!