如何在执行测试套件时通过soapui生成基于Excel工作表的报表

时间:2011-06-16 06:42:11

标签: soapui

如何在执行测试套件或测试用例时从soapui生成基于Excel工作表的报告?(在测试wsdl时)

4 个答案:

答案 0 :(得分:0)

据我所知,在运行测试用例或测试套件后无法创建Excel报告。一种方法是创建DataSink测试步骤,将数据接收器类型设置为Excel,然后向其中写入多个属性。

答案 1 :(得分:0)

要将测试结果导出到excel文件,您需要在测试用例中创建一个groovy步骤。

soapUI正在使用免费的Java Excel API来创建或操作Excel文件中的数据。

您可以在下面找到基本的示例代码。

import jxl.*;
import jxl.write.*;

// create an excel workbook
WritableWorkbook workbook1 = Workbook.createWorkbook(new File("c:\\report.xls"));

// create a sheet in the workbook
WritableSheet sheet1 = workbook1.createSheet("Report Worksheet", 0);

// Get the data to be added to the report
def fieldFromResponse = context.expand( '${Test Request#Response#declare namespace soap=\'http://www.w3.org/2003/05/soap-envelope\'; //soap:Text[1]}' );

// create a label 
Label label = new Label(0, 0, fieldFromResponse);

// Add the label into the sheet
sheet1.addCell(label); 
workbook1.write();
workbook1.close();

答案 2 :(得分:0)

以下代码用于创建Excel文件,使用Java Excel API编写工作表:

import jxl.*;
import jxl.write.*;
import java.io.*;

public class CreateExcel_JxlApi {
    public static void main(String[] args) {

        //create WorkbookSettings object
        WorkbookSettings ws = new WorkbookSettings();

       try{
             //create work book
             //WritableWorkbook workbook = Workbook.createWorkbook(new File("F:/Tips/JExcelTip/TestReport.xls"), ws);
           WritableWorkbook workbook = Workbook.createWorkbook(new File("F:\\TestReport.xls"), ws);
           System.out.println("Did excel file create?");

             //create work sheet
             WritableSheet workSheet = null;
             workSheet = workbook.createSheet("Test Report" ,0);
             SheetSettings sh = workSheet.getSettings();

             //Creating Writable font to be used in the report  
             WritableFont normalFont = new WritableFont(WritableFont.createFont("MS Sans Serif"),
             WritableFont.DEFAULT_POINT_SIZE,
             WritableFont.NO_BOLD,  false);

             //creating plain format to write data in excel sheet
             WritableCellFormat normalFormat = new WritableCellFormat(normalFont);
             normalFormat.setWrap(true);
             normalFormat.setAlignment(jxl.format.Alignment.CENTRE);
             normalFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
             normalFormat.setWrap(true);
             normalFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN,
             jxl.format.Colour.BLACK);
             //write to datasheet 
             workSheet.addCell(new jxl.write.Label(0,0,"User Name",normalFormat));
             workSheet.addCell(new jxl.write.Label(1,0,"Password",normalFormat));   
             //write to the excel sheet
             workbook.write();
           //close the workbook
             workbook.close();
   }catch(Exception e){
        e.printStackTrace();
  }
}
}

答案 3 :(得分:0)

import java.util.*; 
import java.lang.*;
import jxl.*
import jxl.write.*

testCase = testRunner.testCase.testSuite.project.getTestSuiteByName('TS_CurrencyConverter').getTestCaseByName('TC_CurrencyConverter')
def properties = new com.eviware.soapui.support.types.StringToObjectMap ()
def async = false
def runner=testCase.run (properties, async)

for(r in runner.results)
{
    log.info(testCase.name+ ":Executed Successfully with Status " + r.status ) 
    //testCase.name+ ":Executed Successfully with Status " + r.status
    WritableWorkbook workbook1 = Workbook.createWorkbook(new File("c:/AQR/TestResult.xls"))
    WritableSheet sheet1 = workbook1.createSheet("RunReport", 0)
    Label TCNamelabel = new Label(0, 0, "Test Case Name");
    Label TCStatus= new Label(1,0,"Test Case Status");
    //Label TCComment= new Label(0,2,"Comment");
    sheet1.addCell(TCNamelabel); 
    sheet1.addCell(TCStatus); 

    Label TCANamelabel = new Label(0, 1, testCase.name);
    Label TCAStatus= new Label(1, 1, ""+ r.status);
    sheet1.addCell(TCANamelabel); 
    sheet1.addCell(TCAStatus); 
    workbook1.write()
    workbook1.close()
}