Contributions
How to get 'reports from Soapui' using Groovy
I am new to groovy and i am trying to create framework for my company.i have added code where i am passing the request using excel from soapui and the response received will get add in excel itself.I want the report as pass or Fail. I have the code for reporting but i am not able to connect both the code . I am trying to generate the report where the data running from excel and soapui matches and add in report fail or pass import com.eviware.soapui.support.XmlHolder import java.io.File; import java.io.IOException; import jxl.*; import jxl.read.biff.BiffException; import jxl.write.*; log.info("Service Testing Started") def reqOperationName = "Div_Insert"; def inputDataFileName = "C:/Users/xxxxxx/xxxx.xls" def inputDataSheetName = "Division insertion"; Workbook workbook = Workbook.getWorkbook(new File(inputDataFileName)); WritableWorkbook copy = Workbook.createWorkbook(new File(inputDataFileName),workbook); WritableSheet sheet1 = copy.getSheet(inputDataSheetName); def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) def reqholder = groovyUtils.getXmlHolder(reqOperationName+"#Request") try{ rowcount = sheet1.getRows(); colcount = sheet1.getColumns(); for(Row in 1..rowcount-1){ for(Col in 2..colcount-1){ String reqTagName = sheet1.getCell(Col,0).getContents() def TagCount = reqholder["count(//*:"+reqTagName+")"] if(TagCount!=0){ String reqTagValue = sheet1.getCell(Col,Row).getContents() reqholder.setNodeValue("//*:"+reqTagName, reqTagValue) reqholder.updateProperty() } } testRunner.runTestStepByName(reqOperationName) def resholder = groovyUtils.getXmlHolder(reqOperationName+"#Response") resTagValue1 = resholder.getNodeValue("//*:sys_id") resTagValue2 = resholder.getNodeValue("//*:table") resTagValue3 = resholder.getNodeValue("//*:display_name") resTagValue4 = resholder.getNodeValue("//*:display_value") resTagValue5 = resholder.getNodeValue("//*:status") resTagValue6 = resholder.getNodeValue("//*:status_message") resTagValue7 = resholder.getNodeValue("//*:error_message") resTagValue8 = resholder.getNodeValue("//*:map") Label resValue1 = new Label(6,Row,resTagValue1); sheet1.addCell(resValue1); Label resValue2 = new Label(7,Row,resTagValue2); sheet1.addCell(resValue2); Label resValue3 = new Label(8,Row,resTagValue3); sheet1.addCell(resValue3); Label resValue4 = new Label(9,Row,resTagValue4); sheet1.addCell(resValue4); Label resValue5 = new Label(10,Row,resTagValue5); sheet1.addCell(resValue5); Label resValue6 = new Label(11,Row,resTagValue6); sheet1.addCell(resValue6); Label resValue7 = new Label(12,Row,resTagValue7); sheet1.addCell(resValue7); Label resValue8 = new Label(13,Row,resTagValue8); sheet1.addCell(resValue8); } }catch (Exception e) {log.info(e) } finally{ copy.write(); copy.close(); workbook.close(); } log.info("Service Testing Finished") Reporting code: try {r def projectPath = new com.eviware.soapui.support.GroovyUtils(context).projectPath String folderPath = projectPath + "/SoapUIResults"; def resultFolder = new File(folderPath); if(!resultFolder.exists()) { resultFolder.mkdirs(); } Date d = new Date(); def executionDate = d.format("dd-MMM-yyyy HH_mm"); String subfolderPath1 = folderPath+ "/Request-Response_"+executionDate; new File(subfolderPath1).mkdirs(); String subfolderPath2 = folderPath+ "/CSV Reports"; new File(subfolderPath2).mkdirs(); def reportFile = new File(subfolderPath2, "Report_"+executionDate+".csv"); if(!reportFile.exists()) { reportFile.createNewFile(); reportFile.write('"Test Suite","Test Case","Test Step","Step Type","Step Status",'+'"Result message","Execution Date"'); } for(stepResult in testRunner.getResults()) { def testSuite = testRunner.testCase.testSuite.name; def testCase = testRunner.testCase.name; def testStep = stepResult.getTestStep(); def testStepName = testStep.name def type = testStep.config.type def status = stepResult.getStatus() reportFile.append('\n'); reportFile.append('"' + testSuite + '",'); reportFile.append('"' + testCase + '",'); reportFile.append('"' + testStepName + '",'); reportFile.append('"' + type + '",'); reportFile.append('"' + status + '",'); reportFile.append('"'); for(resMessage in stepResult.getMessages()) { reportFile.append('Message:' + resMessage + '\n'); } reportFile.append('",'); reportFile.append('"' + executionDate + '",'); if((type=="request").or(type=="restrequest")) { def extRequest = testStep.properties["Request"].value; def requestFile=subfolderPath1+"/request_"+testSuite+"_"+testCase+"_"+testStepName+".txt"; def rqfile = new File(requestFile); rqfile.write(extRequest, "UTF-8"); def extResponse = stepResult.getResponseContent(); def responseFile=subfolderPath1+"/response_"+testSuite+"_"+testCase+"_"+testStepName+".txt"; def rsfile = new File(responseFile); rsfile.write(extResponse, "UTF-8"); } } } catch(exc) { log.error("Exception happened: " + exc.toString()); } The file is getting corrupted when the code is run.796Views0likes1Comment