我想用groovy做一些自動操作。我正在接收另一個請求的響應數據,並使用jxl jars將這兩個請求和兩個輸出存儲在excel中。但如果我這樣做,我的Excel文件被損壞。但是當我做了單一的請求響應,它工作正常。所以我想知道是否有任何jxl內存問題??如果是的話如何克服?使用jxl編寫大型數據時,excel文件損壞gent
這裏是我的腳本:
import jxl.*
import jxl.write.*
import groovy.sql.Sql
//Datasheet read define start
def projectLocation="E:/"
def dataFileLocation=projectLocation+"zip.xls"
def workbook = Workbook.getWorkbook(new File(dataFileLocation))
def readSheet = workbook.getSheet(0)
def rowCount = readSheet.getRows()
def colCount = readSheet.getColumns()
def myTestCase = context.testCase
//db config
def url = 'jdbc:hsqldb:hsql://localhost/'
def user = 'sa'
def password = ''
def driver = 'org.hsqldb.jdbcDriver'
def sql = Sql.newInstance(url, user, password, driver)
propTestStep = myTestCase.getTestStepByName("Properties");
//Datasheet read end
//Content Write define start
WorkbookSettings s = new WorkbookSettings();
s.setUseTemporaryFileDuringWrite(true);
// s.setInitialFileSize(100000000)
WritableWorkbook workbook1 = Workbook.createWorkbook(new File(projectLocation+"output1.xls"),s)
WritableSheet writeSheet = workbook1.createSheet("new", 0)
//
//WritableWorkbook workbook2 = Workbook.createWorkbook(new File(projectLocation+"output2.xls"))
//WritableSheet writeSheet1 = workbook2.createSheet("newOutput", 0)
def project = testRunner.testCase.testSuite.project
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
//Content Write define end
for(int i = 1;i < rowCount; i++)
{
for(int j = 0;j < colCount; j++)
{
val= readSheet.getCell(j,i).getContents()
// log.info "before storing in zip val="+ val
// propTestStep.setPropertyValue("zip",val)
def req=groovyUtils.getXmlHolder("GetInfoByZIP#Request")
req["//web:USZip"] = val
req.updateProperty()
testRunner.runTestStep(project.testSuites['USZipSoap12 TestSuite'].testCases['GetInfoByZIP TestCase'].testSteps['GetInfoByZIP'])
// log.info "before sending to db val="+val
sql.eachRow('select state,city from zip where zip=?',[val]){ row ->
st= row.state
ct= row.city
}
//log.info st+" "+ct
def res=groovyUtils.getXmlHolder("GetInfoByZIP#Response")
def state = res.getNodeValues("//STATE")
def city=res.getNodeValues("//CITY")
def ct1=city[0]
log.info ct +" " + ct1
if(ct1.equalsIgnoreCase(ct)){
// log.info "city equals"
}
else{
// log.info "not eq"
}
def req1=groovyUtils.getXmlHolder("GetInfoByState#Request")
req1["//web:USState"]=state[0]
req1.updateProperty()
testRunner.runTestStep(project.testSuites['USZipSoap12 TestSuite'].testCases['GetInfoByZIP TestCase'].testSteps['GetInfoByState'])
def respo1= testRunner.testCase.testSteps["GetInfoByState"].testRequest.response.contentAsString
Label labelReq = new Label(j,i,context.testCase.getTestStepByName("GetInfoByZIP").getProperty("request").value)
Label labelReq1 = new Label(j+2,i,context.testCase.getTestStepByName("GetInfoByState").getProperty("request").value)
def response = testRunner.testCase.testSteps["GetInfoByZIP"].testRequest.response.contentAsString
Label labelResp = new Label(j+1,i,response);
Label labelResp1 = new Label(j+3,i,respo1);
writeSheet.addCell(labelReq)
writeSheet.addCell(labelResp);
log.info respo1
writeSheet.addCell(labelReq1)
writeSheet.addCell(labelResp1);
}
}
workbook1.write()
workbook1.close()
編輯問題並顯示您擁有的腳本。 – Rao
編輯請看一次 – LowCool