Created
February 26, 2013 17:30
-
-
Save pradeepbishnoi/5040371 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//code to write to xls | |
import jxl.* | |
import jxl.write.* | |
import jxl.format.Colour; | |
WritableWorkbook workbook = Workbook.createWorkbook(new File(“C:/Users/rajbir_kaur/Desktop/EM2.xls”)) //replace the file location & file name | |
WritableSheet sheet = workbook.createSheet(“Actual”, 0)//replace the name of sheet with desired name | |
//Setting Background colour for Cells | |
Colour bckcolor = Colour.DARK_GREEN; | |
WritableCellFormat cellFormat = new WritableCellFormat(); | |
cellFormat.setBackground(bckcolor); | |
//Setting Colour & Font for the Text | |
WritableFont font = new WritableFont(WritableFont.ARIAL); | |
font.setColour(Colour.GOLD); | |
cellFormat.setFont(font); | |
//Variable Declaration for xls | |
int counter = 1; | |
//xls sheet header formatting | |
Label label1= new Label(0, 0, “SITE ID”); | |
sheet.addCell(label1); | |
WritableCell cell1 = sheet.getWritableCell(0, 0); | |
cell1.setCellFormat(cellFormat); | |
Label label2= new Label(1, 0, “NAME”); | |
sheet.addCell(label2); | |
WritableCell cell2 = sheet.getWritableCell(1, 0); | |
cell2.setCellFormat(cellFormat); | |
Label label3= new Label(2, 0, “PATHS”); | |
sheet.addCell(label3); | |
WritableCell cell3 = sheet.getWritableCell(2, 0); | |
cell3.setCellFormat(cellFormat); | |
//Variable declaration for XML response handling | |
def project = testRunner.testCase.testSuite.project ; | |
def tcase = project.testSuites["login TestSuite"].testCases["getPremisesByIds TestCase"] ; //replace the names of testsuite & testcase | |
def tstep = tcase.getTestStepByName(‘Premises IDs’); //replace the teststepname with name of REST request in testcase | |
def response_test_suite_1 = tstep.getPropertyValue(“ResponseAsXml”); | |
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ); | |
def holder1 = groovyUtils.getXmlHolder(“${response_test_suite_1}”); | |
holder1.namespaces ['ns1']= “https://ems.gridpoint.com/publicApi/services/user/getPremisesByIds” //replace the namespace as required | |
def nodeCount = holder1.getDomNodes(“//ns1:Response/ns1:result/ns1:e/ns1:paths/ns1:e”).length //replace the xpath as required | |
//get node values from the mentioned xpath and add to worksheet | |
for (def nodeIndex = 1; nodeIndex <= nodeCount; nodeIndex++) { | |
def node = holder1.getDomNodes("//ns1:Response/ns1:result/ns1:e/ns1:paths/ns1:e["+nodeIndex+"]") //replace the xpath refer the sample script below | |
node.each { | |
Label label4 = new Label(0,counter, holder1.getNodeValue("//ns1:Response[1]/ns1:result[1]/ns1:e[1]/ns1:id[1]")); //replace the xpath with the sample given below | |
sheet.addCell(label4); | |
Label label5 = new Label(1,counter, holder1.getNodeValue("//ns1:Response[1]/ns1:result[1]/ns1:e[1]/ns1:name[1]")); //replace the xpath with the sample given below | |
sheet.addCell(label5); | |
Label label6 = new Label(2,counter, it.firstChild.nodeValue.toString()); | |
sheet.addCell(label6); | |
counter ++ | |
} | |
} | |
//writing to and clsoing the worksheet | |
workbook.write() | |
workbook.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment