Templates

The Genero Ghost Client has a set of built-in code templates.

Templates are fragments of code used by the GGC for generating scenarios. A template is an implementation of generic code that can work on different types of actions executed and checks that are performed based on parameters.

For instance, if the action you want to test was to sort a table column in your application form, the code snippet in the event_table_sort.4gl file can implement this action.
# Sort a table 
 CALL ggc.wait($(delayMs))
 CALL ggc.sortTable("$(tableName)", "$(columnName)", ggc.$(sortTypeBdl))
In the generated BDL test scenario the GGC engine passes the values for table, column, and sort selection to it:
# Sort a table
 CALL ggc.wait(1910)
 CALL ggc.sortTable("sr_prices", "name", ggc.SORT_ASCENDING)

There is a default set of templates provided in the installation directory. They are located in GGCDIR/template. There are templates for BDL and Java in the respective directories. These consist of the following:

  • event type templates that generate code that trigger real actions in the program, like key events, set focus on a field, set a field value, sort a table, move a column, etc.
  • check type templates that perform runtime checks on the state of the applications, like the current window name, field value, form name and title, and so on. All of these checks can be enabled by the ggcgen command option --check-all, or they can be enabled individually, for example, --check-value.

Why use templates?

Templates allow you to customize the test implementation. If you update your templates, and regenerate your scenarios from the original log, the resulting scenario will take your modifications into account. This was not possible in GGC version 1.

As a simple example, if you have a form field called "today" containing today's date, the scenario in this case generates a check with the recorded value but that value can change when you execute the test at a later date.

Therefore, you may want to update the check_value snippet to ignore this field as it is expected that the check will fail on subsequent tests. Or you can implement a check for this field that ensures that it contains the date of the day.

This allows you to customize the generated code to take cases like this into account without editing the test scenario code directly or having to record new test logs.

Customizing templates

You can develop your own custom templates and provide these to the ggcgen command option --template-directory to specify the custom template directory to use.

If customizing templates, the recommendation is to copy the templates you need from the FGLDIR/testing_utilities/ggc/template directory to your own working directory and make any changes needed there.

Multiple template directories can be provided to the ggcgen command option --template-directory. Lookup will be performed in the order of command line arguments, for example:

ggcgen bdl --template-directory ${MYCUSTOM_TEMPLATE_DIR} 
           --template-directory ${GGCDIR}/template/bdl/alternate-checks 
           --check-all mylog.log

You will find the alternate-checks directory with templates using calls to ggc.check* functions, as an example of customized templates. These checks are a less-verbose form of the standard checks, but basically perform the same function. It is recommended to use these checks for your custom templates.

Templates are first searched for in the custom template directory, and then if not found in the default template directory.

Ways the GGC uses templates

Templates are used to generate a scenario for tests recorded in a guilog or GDC log file with the ggcgen tool.

The scenario test file is either in BDL (.4gl file format) or Java (.java format), depending on what you specified in the ggcgen command option. It contains the template code expanded with parameter values corresponding to the action or event you performed when recording the log.