11.2. Creating a Report Template

11.2.1. Supported Parameter Types
11.2.2. Dealing with Parameters

Go to the Configure section and select the Report Templates page.

The “Report Templates” Page

Figure 11.2. The Report Templates Page


A click on the button New creates a new report template. Here you can enter a name and a short description for the report.

Name

The name of the report.

Description

A description of the report.

Output Format

The output format: PDF or Excel.

Status

The status of the report: Draft or Approved.

Klaros-Test­management comes with several predefined report templates These are read-only, but can be duplicated with the icon. The duplicate can then be modified as desired.

The “Report Templates Details” Page

Figure 11.3. The Report Templates Details Page


[Note] Note

For larger report templates it can be helpful to use an IDE (e.g. Eclipse) for the script and layout template. The created files can then be uploaded in Klaros-Test­management. To avoid errors, add the Klaros model libraries to the build path of your Eclipse project. The tutorial document has a chapter about creating report templates where this is explained in detail.

Instead of editing the report script and template directly in the application, they can also be imported from a file. Specify the file to be used by clicking the Browse button and selecting the file to be imported. A click on OK in the file dialog and then on Upload imports the selected file into the script or template field.

This page provides three actions to be executed:

To make reports more flexible, it is possible to pass parameters to the report script. These can be used, for example, to pass a time span for which data is determined.

To add arguments to the report, click the icon button on the parameters tab.

The “Parameters” Tab

Figure 11.4. The Parameters Tab


The type of the parameters can be specified by selecting the appropriate value from the type list. Supported types are Text, Number, Date, Boolean, List and Multi List. A default value can be specified and a mandatory flag can be set. Clicking the icon removes the parameter from the list.

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

11.2.1. Supported Parameter Types

The following parameter types are supported:

  • Text
  • Number
  • Date
  • List
  • Multi List

11.2.2. Dealing with Parameters

As mentioned before, the passed parameters can be retrieved from the context by the getParameterValue(String name) and getParameter(String name) methods.

The following code snippet shows how to access the parameters and how to use them in the report script:

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

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

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

Parameters can be accessed from the layout template in the following way:

<p:text value="Test results for test runs with execution time &lt; #{executionTime} ms" />
  
[Note] Note

Make sure to escape characters like &, < or > when using them in XML attributes in the layout template. In our example < is the escape character for <.