Chapter 11. Reports

Table of Contents

11.1. Create A New Report Template
11.1.1. Dealing with Parameters
11.2. Applying a Report Template
11.3. Example Report
11.3.1. Creating the Groovy Script
11.3.2. Creating a SeamPDF Report Template
11.3.3. Creating a Chart
11.3.3.1. Pie Chart Groovy Script
11.3.3.2. Pie Chart Template Script
11.3.4. Including Images
11.3.5. Creating a SeamExcel Report Template

With the Enterprise Edition of Klaros-Testmanagement it is possible to define custom Reports. Though Klaros-Testmanagement already provides several Reports, it might be helpful to design new Reports that suite your and your customer's needs. Figure 11.1, “The Report Generation Process” gives an overview of the Report generation process. As the Report definition process is based on a Groovy script and SeamPDF or SeamExcel , basic knowledge in Java programming and XML are helpful for a Report Designer.

Figure 11.1. The Report Generation Process

The Report Generation Process

The reporting process involves two roles, the Report Designer and the Report User. While the Report Designer provides the outlook of the Report and prepares the Report data, the Report User applies the Reports to the data collected in Klaros-Testmanagement. The Report Designer has to provide two scripts to build a Report. The Query script prepares the data and is implemented in Groovy, while the report template describes the layout of the Report. The Groovy script taking care of data retrieval and preparation is provided by a Java class that implements the Section D.2, “KlarosScript Interface” . This interface defines one method called execute and takes a de.verit.klaros.scripting.KlarosContext object as input parameter.

To retrieve the data from Klaros-Testmanagement the designer can access the de.verit.klaros.core.model via HQL. The main task of the class is to provide and prepare the data for the Report. The data for the report template must then be stored in the de.verit.klaros.scripting.KlarosContext object passed to the execute method. To make Reports more flexible for Report Users, it is possible to pass parameters to the Groovy script. The parameters are stored in the context and can be accessed from the Groovy script.

[Tip]Predefined objects in the context

The de.verit.klaros.scripting.KlarosContext object already contains predefined objects. For a list please refer to Section D.1, “Context Variables” .

The report template must be implemented using SeamPDF . Section Section 11.3, “ Example Report ” provides an example of how to define a custom Report.

11.1.  Create A New Report Template

Before Reports can be applied to the test data, they have to be defined. To get to the Report Templates page click on the Configure icon and select Report Templates from the menu on the left side of the screen.

Figure 11.2. The Report Templates Page

The Report Templates Page

To create a new Report click on the New button on the Report Templates page. Then provide the basic data for the Report by entering a name in the Name field and a short description in the Description field.

Figure 11.3. The New Report Templates Page

The New Report Templates Page

To enter the Groovy script, which retrieves the data, use the Groovy Script text area. To unfold the Template text area click on the Edit the Template link next to the Template label. The Report's Template code can then be entered into the unfolding text area. To unfold the Groovy script text area again click on the Edit the script link.

[Note]Note

It might be helpful to use a Java IDE e.g. eclipse, to develop the Groovy script and an XML editor to provide the report template. The created files can then be uploaded into Klaros-Testmanagement. To avoid errors in the Groovy script, add the Klaros model libraries to the build path of your eclipse project.

Instead of manually entering the code for each text area, the code can be imported from a file. Specify the file to use by clicking on the Browse Button and select the file from the file system. Click OK in the file dialog and afterwards click Upload to import the selected file into the text area.

This page provides three actions to be executed. To test the code click on the Preview button to generate a Report. The Save button stores the Report into Klaros repository in the file system. The changes can be discarded by pressing the Back button.

[Note]Note

The generated Report is opened automatically in a new browser window. If this does not work for you, please check if you have a pop-up blocker active.

To provide a certain degree of freedom to the Report User, and to make the Reports more flexible, it is possible to pass parameters to the Groovy script. This mechanism can, for example, be used to pass a timespan to the Groovy script, so that only data for this timespan is retrieved from Klaros-Testmanagement.

To pass arguments to the Report select the The script has parameters checkbox.

Figure 11.4. Adding Parameters to the Script

Adding Parameters to the Script

A new section as shown in Figure 11.4, “Adding Parameters to the Script” is displayed, which enables the addition of parameters. Clicking the button allows a parameter to be added to the parameter list.

Figure 11.5. Specifying Parameters

Specifying Parameters

Clicking the icon removes the parameter from the list. The type of the parameters can be specified by the combo box. Supported types are Text, Number, and Date.

The passed parameters can be accessed by the Groovy script by either calling the getParameterValue(String name) or the getParameter(String name) method. The methods will return null if no parameter with the specified name can be found.

11.1.1. Dealing with Parameters

As mentioned before the passed parameters can be retrieved from the context by the methods getParameterValue(String name) and getParameter(String name) . The following code snippet shows how to access the parameters and how to use them in the Groovy script.

  query.append("select tcr from KlarosTestCaseResult tcr where tcr.executionTime <");
  long executionTime = context.getParameterValue("executionTime");
  query.append(executionTime);
  List<?> tcr = context.executeQuery(query.toString());
    

This query will retrieve all KlarosTestCaseResult instances that have an execution time smaller than the value passed with the parameter executionTime .

As an alternative the parameters can be directly accessed in the query as shown in the following code snippet.

  query.append("select tcr from KlarosTestCaseResult tcr where tcr.executionTime <:executionTime");
    List<?> tcr = context.executeParameterizedQuery(query.toString());
    

To access the parameters from the report template the parameters must be added to the context beforejand, like the query results.

  long executionTime = context.getParameterValue("executionTime");
  context.add("executionTime", executionTime);
    

The parameter can then be accessed from the report template just the same way.

  <p:text value="Testresults for testruns with execution time &lt; #{executionTime} ms" />
    

[Note]Note

In the report template, the < must be escaped.