|
2#
楼主 |
发表于 2013-12-3 16:46:29
|
只看该作者
之三:把Response中的数据写入Excel
import groovy.transform.Field
import java.io.File;
import java.util.*;
import jxl.*;
import jxl.write.*;
def propsread = new java.util.Properties();
propsread = testRunner.testCase.getTestStepByName("roperties 1");
def writingSheetName = propsread.getPropertyValue("SheetName")
//log.info "writingSheetName: ${writingSheetName}"
def flag = (testRunner.testCase.getPropertyValue("RUN")).toInteger();
//log.info "initialWritingRow: ${flag}"
Workbook workbook = Workbook.getWorkbook(new File("D:\\FAL\\SOAPUI_Automation\\GetVehicleParkedLocation.xls"))
WritableWorkbook copy = Workbook.createWorkbook(new File("D:\\FAL\\SOAPUI_Automation\\GetVehicleParkedLocation.xls"), workbook) // creates a copy to append data
WritableSheet sheet = copy.getSheet(writingSheetName)
//log.info(sheet.isHidden())
//log.info sheet.getRows()
//log.info sheet.getColumns()
flag = sheet.getRows().toInteger()
//log.info "actualWritingRow: ${flag}"
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def responseAsXml = context.expand( '${GetVehicleParkedLocation#Response}' ) // gets the xml response
def holderResponse = groovyUtils.getXmlHolder(responseAsXml)
if( holderResponse !=null )
{
// declare namespace according to xml request
holderResponse.declareNamespace('veh', 'http://ns.hughestelematics.com/Gateway/service/VehicleParkedLocationService')
holderResponse.declareNamespace('v1', 'http://xmlns.hughestelematics.com/Gateway/VehicleParkedLocation/V1')
holderResponse.declareNamespace('v11', 'http://xmlns.hughestelematics.com/Gateway/Common/Header/V1')
def E2_Timestamp
E2_Timestamp = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1:Header[1]/v11:Timestamp[1]")
//log.info E2_Timestamp
def F2_Altitude
F2_Altitude = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1:Altitude[1]")
def G2_Course
G2_Course = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1:Course[1]")
def H2_Latitude
H2_Latitude = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1atitude[1]")
def I2_Longitude
I2_Longitude = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1ongitude[1]")
def J2_PrecisionInMeters
J2_PrecisionInMeters = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1ocationPrecision[1]/v1recisionInMeters[1]")
def K2_PrecisionTrueness
K2_PrecisionTrueness = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1ocationPrecision[1]/v1recisionTrueness[1]")
def L2_statusReceivedTimeStamp
L2_statusReceivedTimeStamp = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1:statusReceivedTimeStamp[1]")
Label label_Timestamp = new Label(4, flag, E2_Timestamp); // fills excel cells with the results
sheet.addCell(label_Timestamp);
Label label_Altitude = new Label(5, flag, F2_Altitude); //column=0=A,row=0=1, cell A1
sheet.addCell(label_Altitude);
Label label_Course = new Label(6, flag, G2_Course);
sheet.addCell(label_Course);
Label label_Latitude = new Label(7, flag, H2_Latitude);
sheet.addCell(label_Latitude);
Label label_Longitude = new Label(8, flag, I2_Longitude);
sheet.addCell(label_Longitude);
Label label_PrecisionInMeters = new Label(9, flag, J2_PrecisionInMeters);
sheet.addCell(label_PrecisionInMeters);
Label label_PrecisionTrueness = new Label(10, flag, K2_PrecisionTrueness);
sheet.addCell(label_PrecisionTrueness);
Label label_statusReceivedTimeStamp = new Label(11, flag, L2_statusReceivedTimeStamp);
sheet.addCell(label_statusReceivedTimeStamp);
}
def logArea = com.eviware.soapui.SoapUI.logMonitor.getLogArea("SoapUI log"); // reads the soapui log
def M2_soapuiLog
if( logArea !=null )
{
def model = logArea.model
if( model.size > 0 )
M2_soapuiLog = (model.getElementAt(model.size-1)).toString()
//log.info M2_soapuiLog
Label label_soapuiLog = new Label(12, flag, M2_soapuiLog);
sheet.addCell(label_soapuiLog);
}
copy.write()
copy.close()
workbook.close() |
|