Custom Groovy Macros
It is possible to define new Groovy macros that can be called in your step plan or in your HP ALM test description.
Installation
In order to use Groovy macros, three steps have to be done:
- First, you have to create a folder on the controller. This folder will contain the Groovy file defining your macros.
- The startup script should be modified by adding the new folder in the class path:
“%JAVA_PATH%java.exe” %JAVA_OPTS% -cp “..\lib*;..\templates” step.controller.ControllerServer -config=../conf/step.properties - A new line has to be added in the step.properties file. This option will allow you to specify the name of the Groovy class containing your marcos:
tec.expressions.scriptbaseclass=Templates
When these changes are done, you can then create your macros file in the new folder.
Note that:
- The controller has to be restarted each time you modify these options or the macro file
- The base name of macro file should have the same name used in tec.expressions.scriptbaseclass and have the .groovy extension (…\step-controller-X.Y.Z\templates\Templates.groovy in our example)
Validation
- In order to validate our groovy macro, we will download the following file and save it under …\step-controller-X.Y.Z\templates\Templates.groovy: Template.groovy
- You should now restart your controller for the new macro to be taken into account
- You can now re-run the example test case. The function now() should be know and return the current date:
- As a final check, you can also ensure that the new test status is properly reflected in ALM:
Troubleshooting
The following exceptions can be faced when using Groovy Macros:
- Script1.groovy: 1: unable to resolve class WrongTemplate:
- The name in tec.expressions.scriptbaseclass didn’t match the name of your Groovy class
- The name of the folder didn’t match the name in the Java path
- groovy.lang.MissingMethodException: No signature of method: Script1.unknownMethod():
- The method name is misspelled
- Or our didn’t restart your controller after defining the new macros