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

问题描述 投票:0回答:4

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

soapui
4个回答
0
投票

据我所知,运行测试用例或测试套件后无法创建 Excel 报告。一种方法可能是创建一个

DataSink
测试步骤,将数据接收器类型设置为 Excel,然后向其写入多个属性。


0
投票

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

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();

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();
  }
}
}

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()
}
© www.soinside.com 2019 - 2024. All rights reserved.