Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Jubula » User defined functions: extension functions 1 HowTo
User defined functions: extension functions 1 HowTo [message #1793736] Tue, 14 August 2018 22:08
Milos Hroudny is currently offline Milos HroudnyFriend
Messages: 24
Registered: June 2017
Junior Member
Jubula plug-in development environment.
We use "Eclipse RCP" to develop our own extension functions. We can install Eclipse into d:\Program Files\EclipseNeon3_RCP directory and workspace can be in the directory d:\JAVA\Jubula_8.5.0. For our development we will need target platform. The content of the target platform directory has to be the same as Jubula that we use for application testing but we will use a different directory. From this reason we can install Jubula in the d:\TargetPlatform\ directory, no Start Menu folder, no shortcuts for all users. The "Target Platform" content is used as a source of dependency packages used for the compiling the code.
Target platform is added to our Eclipse through:
Window→Preferences→Plug-in Development→Target Platform
Initialize the target definition with: Nothing <Next>
Next→Locations→ Add Content→Directory
Add content > Location: d:\TargetPlatform\jubula_8.5.0.127\ite <Finish>
Rename the "New Target" to "Jubula 8.5.0 Target" in the "Name" field <Finish>
Select check box next to new target platform name in the Target Platform section and <Apply>
Set Classpath variable:
Window→Preferences→Java→Build Path→Classpath Variables
ECLIPSE_HOME d:\TargetPlatform\jubula_8.5.0.127\ite <Apply and Close>
Now we can create plug-in.
Create a standalone "Plug-in Project" for each extension function
Project Name: com.mh.jubula.functions.mhReadFile
<Next>
Data to generate plug-in:
ID: com.mh.jubula.functions.mhReadFile
Version: 1.0.0.qualifier
Name: MhReadFile
Vendor: Milos Hroudny
Execution Environment: JavaSE-1.7
Options check boxes unchecked
Radio button 'Rich Client Application': no
<Finish>
Plug-in project structure is created.
Select the "Dependencies" tab and add dependencies for our plug-in:
org.eclipse.jubula.tools (4.0.0)
org.eclipse.osgi (3.11.3)
org.apache.commons.lang (2.6.0)
org.apache.commons.codec (1.6.0)
org.eclipse.jubula.client.core (5.0.0)
org.eclipse.jubula.client.core.functions (5.0.0)
Select "Extensions" tab, click Add. In the dialog New Extension select the org.eclipse.jubula.client.core.functions and set check box Show only...
<Finish>
The selected extension is displayed in the "Extensions" list. Right-click on this package and choose New→function from the context menu.
In the Extension Element Details section fill-in:
name: readFile
class: com.mh.jubula.functions.mhReadFile.ReadFileFunctionEvaluator
evaluator: local
If the function uses parameters, as in this case, open the context menu for the new created function readFile(function) and add the "varArg" argument. Set focus on the X(VarArg). Under the "Extension Element Details", select the argument type "string" argument type. This function uses just one argument and we will configure defaultArgumentCount: 1.
In the "Project Explorer" view, create the com.mh.jubula.functions.mhReadFile package in the src directory. In this package create the "ReadFileFunctionEvaluator" class.
<Finish>
Write the class content:
package com.mh.jubula.functions.mhReadFile;

import java.io.BufferedReader;
import java.io.FileReader;
import org.eclipse.jubula.client.core.functions.IFunctionEvaluator;

public class ReadFileFunctionEvaluator implements IFunctionEvaluator{
@Override
public String evaluate(String[] arguments){
String fileName = arguments[0];
return loadFileToString(fileName);
}

private static String loadFileToString(String fileName){
String line=null;
String text = "";
try{
FileReader inputFile = new FileReader(fileName);
BufferedReader bufferReader = new BufferedReader(inputFile);
while ((line = bufferReader.readLine()) != null) {
text += line+"\n";
}
bufferReader.close();
}catch(Exception e){
System.out.println("Error while reading file line by line:" + e.getMessage());
}
line = null;
return text;
}
public static void main(String args[]) {
System.out.println(loadFileToString("d:\\temp\\Final.txt"));
return;
}
}
This plug-in can be used to load a file into the Jubula variable that is later used in the test. We test the plug-in before using it. Into the selected directory, in our case d:\temp directory, we will prepare the Final.txt file with the text that we want to load using this plug-in. We perform the plug-in test using the static main() method that is included in the ReadFileFunctionEvaluator class. We first validate the plug-in functionality in the debug mode. After the successful check, we will run the code as Java application by using the Run→Run As Java Application command. In the "Console" view we should see the content of the loaded file.
After successfully testing the loadFileToString() method, we exclude the main() method from the ReadFileFunctionEvaluator class.
Due to the Jubula internal mechanism, each extension function, implemented as a plug-in, is performed at least twice. First time during initialization and then in the test. But this is other story.
Previous Topic:Tree Table input text in specific cells?
Next Topic:General special characters
Goto Forum:
  


Current Time: Fri Apr 26 12:45:20 GMT 2024

Powered by FUDForum. Page generated in 0.02789 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top