Capturing Java-Based Applications Using Java Spy
Sometimes, Real-Time Designer is not able to locate elements within an embedded browser in a Java application. In this case, use Java Spy as follows:
-
Locate the browser object in the Java application, as described in Locate the Browser Object in the Java Application. This is the most important step. Once the browser object is located, the rest is straightforward.
-
Test the evaluate function of the browser object, as described in Test the Evaluate Function.
-
Invoke JavaScript functions using the evaluate function to perform screen element activities, such as get value, insert value, and click, as described in Call JavaScript Functions Using the Evaluate Function.
Locate the Browser Object in the Java Application
To locate the browser object in the Java application:
-
Run JavaSpy.exe from the Real-Time Designer installation directory.
-
To capture a JAVA application, click
, and click the Java application layer. Start by capturing the outer most layer. The Class is the class of the layer.
-
Click Inject. The grey ball turns green if the capture is successful.
-
In the Components tab, select Highlight and Show class.
-
Click Load. All the layers are shown.
-
For any browser-embedded Java application you should be able to find a class with the word “browser” in the class name.
-
Select the relevant object.
-
In the Jscript tab, find the methods and fields of the object.
If a component has a field x, you can:
-
Set the field value: component.InternalObj.x = 0;
-
Get the field value: var a = component.InternalObj.x;
To call a method, use the following syntax:
component.<method name>(<return type>, <parameter types separated by commas>, <true == the method is static, false otherwise>, <parameters if any>);For example, getComponentAt returns the component located at coordinates (x,y):
var c = component.InternalObj.getComponentAt(“java.awt.Component”,”int,int”,false, 2, 1);
The last line in the script returns a result if any.
-
-
Call getSelectedItem.
-
Use your JavaScript experience to look for a method such as getBrowser, or any method that has a similar name. The objective is to get the browser object so that you can call JavaScript functions on it.
Sometimes, the object itself is the browser object, in which case you don’t need to look for getBrowser. You can simply execute the JS function directly on the object.
Test the Evaluate Function
If you have found the browser object, you can call the evaluate function to operate screen activities such as get value and insert.
Example 1
component.InternalObj.getInnerBrowserPanel("java.lang.Object","",false).InternalObj.evaluate("java.lang.Object","java.lang.String",false,"alert('test')");
The text in red gets the browser object and the highlighted text calls the alert function in the browser object.
Example 2
If the selected element in the Components tab is the browser object itself.
component.InternalObj.evaluate("java.lang.Object"," java.lang.String",false,"alert('test')");
Call JavaScript Functions Using the Evaluate Function
Once you can evaluate functions in the browser object, you can perform screen operations using JavaScript. For example, instead of “alert(‘test’)”, insert the value into a field by using the following:
getElementById(‘id’).value=’value’

