Templates
Templates are code snippets that are expanded with the parameter values passed to them when generating a test scenario.
Templates are fragments of code used by the Genero Ghost Client (GGC) for generating scenarios. A
template is an implementation of generic code that can be added to a test scenario to test for the
execution of different actions or perform checks based on passed parameters. The GGC has a set of
built-in code templates, located in $GGCDIR/template
, with Genero BDL and Java
templates in the respective directories.
How the GGC uses templates
Templates are used to generate a scenario with the ggcgen tool, for scenarios recorded in a log file. The generated test scenario is either in Genero BDL (.4gl) or Java (.java) format, depending on what was specified in the ggcgen command option. The test scenario contains the template code, expanded with parameter values corresponding to the action or event performed when the log file was recorded.
Sorting a table: an example of template use
# Sort a table
CALL ggc.wait($(delayMs))
CALL ggc.sortTable("$(tableName)", "$(columnName)", ggc.$(sortTypeBdl))
# Sort a table
CALL ggc.wait(1910)
CALL ggc.sortTable("sr_prices", "name", ggc.SORT_ASCENDING)
Types of templates
- event templates
- event type templates generate code that trigger real actions in the program: key events, set focus on a field, set a field value, sort a table, move a column, and so on.
- check templates
- check type templates perform runtime checks on the state of the
applications: 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
checks the value of the focused field.
Why use templates?
Templates allow you to customize the test implementation. If you update a template, and regenerate your scenarios from the original log, the resulting scenario will take your modifications to the template into account.
Consider this simple example. 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 might update the check_value template to ignore this field as it is expected that the check will fail on subsequent tests, or you might implement a check for this field that ensures that it contains the date of the day.
Modifying the template 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. 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 your changes there.
Specify the custom template directory to use with the ggcgen command option
--template-directory
. Multiple template directories can be provided; lookup will be
performed in the order of command line arguments.
ggcgen bdl --template-directory ${MYCUSTOM_TEMPLATE_DIR}
--template-directory ${GGCDIR}/template/bdl/alternate-checks
--check-all mylog.log
The $GGCDIR/template/bdl/alternate-checks directory provides an example of
customized templates. The templates contained in this directory are calls to
ggc.check*
functions that are a less-verbose form of the standard checks, yet
basically performing 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.