Developing your own User-scripted Java harness action
To created a scripted Java action, you must define the action, and modify the existing harness files to implement it.
The figure below provides an overview of the harness samples
/java
directory tree, in the TestArchitect
program folder, and the files it contains.
This figure only describes the most important files and directories required to develop Java harness programs.
The tree resides under TA_INSTALL_DIR
/harness samples
/ (Windows), or /usr/local/testarchitect/harness_samples
(Linux).
java | directory | Root directory of the sample Java harness. |
java/executables | directory | Executable files of Java harness programs. |
java/executables/java_harnress.bat | file | A simple startup script. Its objective is to run the executable Java program file, java_harness.jar. |
java/executables/java_harness.jar | file | An executable Java file invoked by the java_harness.bat file. |
java/source | directory | Contains all necessary files used to implement Java harness code. |
java/source/lib | directory | Libraries used to tell the harness code where to find the Java implementation of the automation library. |
java/source/src | directory | Contains source code that shows how to program for the Java harness. |
java/source/build.xml | file | An XML file that is used by Another Neat Tool (ANT) technology to build an excutable JAR file, which is java_harness.jar. |
The folder java/source/src/com/testarchitect/java/user, contains the following three files:
TAMain.java
is the startup Java script. Running this file executes the main()
function, which sets the actions and starts the TestArchitect interpreter.
Lib_Interpret.java
contains all the necessary functions for TestArchitect interpreter.
Your action definitions in Java may be grouped into separate Java classes, each of which is a .java
file; it is in TAMain.java
that the appropriate class for a given action is invoked. When a given action definition is requested by the interpreter, TAMain’s divert()
function passes execution to the module in which that definition exists.
Only a single class, Mod_Example.java
, exists in your harness samples/java/source/src/com/testarchitect/java/user
directory (assuming you have a fresh installation of TestArchitect). In its unmodified form, it contains the Java code to define a single action, hello world, which writes the text string hello world
to the results.
The convention is to organize user-scripted functions into multiple script class files, with the name of each such file prefixed with the string"Mod_" . If you add new actions, you may want to do so in new script files, depending on whether or not the actions logically fit within an existing module.
In this lesson you will write an action and add it toclass Mod_Example.java
. In the subsequent lesson, you will write another action, but will create an entirely new script module to hold it.
As a rule, adding a new action to an existingmodule in the Java harness involves these steps:
- Add a line to the list of
SetActions()
function calls, declaring the action for the TestArchitect interpreter. - Add an
else-if
clause to thedivert()
function, directing control to a function written to handle the new action. (In the next exercise, you will divert the hello action to aJava function called action_hello.) - Create a function definition that provides the actual action-specific logic. (You will write theJava code for action_hello(), which will do the actual work for the hello action.)