User defined functions: external methods HowTo [message #1793282] |
Thu, 02 August 2018 23:02 |
Milos Hroudny Messages: 24 Registered: June 2017 |
Junior Member |
|
|
We have two options to define our own functions:
1) external methods
2) extension functions using plug-ins.
Both options require programming in Java. A simpler, and therefore a preferred way for creating user defined functions, is the use of external methods where the only condition is the appropriate placement of jar files with static methods into Jubula. But simplicity is not for everybody. In the Jubula 8.5 we can use external methods only for Swing applications.
External methods are a new and simple way how to add functions that we need to perform tests, but they are not part of the standard Jubula feature package. An example follows:
We start with creating of a separate Java project, such as myExternalFunctions. We create the com.my.util package in the project and here the class ExternalFunctions. In this class, we define static methods that we will use in Jubula.
An example of the external method:
//File Exists
public static String fileExists(String filePath)
{
int count= 0
File file = new File(filePath);
if (file.isFile())
{
count++;
}
return Integer.toString(count);
}
We can simply verify the function by including it in the main method in our class. As soon as we have finished testing of the function, we comment the main method and then we generate the jar file, for example myExternalFunctions.jar. We copy this file to the externaljars Jubula's directory, e.g.:
d:\Program Files\jubula_8.5.0.127\ite\externaljars\
If the directory does not exist, we need to create it first. Jubula uses this directory as an interface. If we include a jar file containing public static methods into the directory, Jubula accepts these methods as its own external methods. All public static methods that we defined in the ExternalFunctions class are now available for use in Jubula. Jubula provides in the unbound_modules_concrete_[8.5] toolkit on the Actions>Invoke Method path several test modules that can be used to recall external methods. We will chose <ub_rfl_invokeExternalAndStore> and <ub_rfl_invokeExternal> modules and wrap them into our user defined modules. Depending on whether the external method returns or does not return a value, we select the module.
We can create the module <FileExists> that contains references of two standard modules:
<ub_app_storeValue> and < ub_rfl_invokeExternalAndStore > .
Configuration of the <ub_app_storeValue> would be
VARIABLE_NAME: EM1_path
VALUE: =FILE_PATH
Configuration of the <ub_rfl_invokeExternalAndStore> would be
VARIABLE_NAME: ExternalMethodValue
FULLY_QUALIFIED_CLASS_NAME: com.my.util.ExternalFunctions
METHOD_NAME: fileExists
METHOD_SIGNATURE: java.lang.String
METHOD_ARGUMENTS: $EM1_path
METHOD_ARGUMENT_SEPARATOR: ','
TIMEOUT_IN_MS: 3000
To apply <FileExists> we configure the parameter of the reference to the module,e.g.:
FILE_PATH: 'd:\myfile1.txt'
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04857 seconds