Advanced Java test object methods

Java test object classes include test object methods that you can use in your tests to enhance the interaction between UFT and the application being tested:

CreateObject method

You can use the CreateObject method to create an instance of any Java object within your applet or application. The CreateObject method returns an object reference to the newly created Java object.

You can activate the methods of an object you create in the same way as you would activate the methods of any returned object from a prior call. Because the CreateObject method returns an object reference, there is no need to use the Object property when activating methods of the created object.

For example, you can use the CreateObject method to create a rectangle object. The return value is an object reference.

Set Rect = Browser("Periodic").Page("Periodic").JavaApplet("Periodic").JavaObject("Panel").CreateObject ("java.awt.Rectangle", 10, 20)

The CreateObject method can be performed on any Java test object. The class loader of the Java test object on which the CreateObject method is performed is used to load the class of the newly created Java object.

We recommend to use the CreateObject method on a Java test object from the same toolkit as the object you want to create. For example, to create a Swing/JFC object, use the CreateObject method on an existing Swing/JFC Java test object.

Back to top

GetStatics Method

You can invoke any static method, or you can set or retrieve the value of any static property of a Java class using the GetStatics method.

For example, to invoke the gc method of class.java.lang.System, which runs the garbage collector on the application, you can insert a statement similar to the following:

Browser("Browser").Page("Page").JavaApplet("mybuttonapplet.htm").JavaObject("MyButton").GetStatics("java.lang.System").gc

To retrieve the value of the out property of the java.lang.System class, you can insert a statement similar to the following:

Set OutStream= Browser("Browser").Page("Page").JavaApplet("mybuttonapplet.htm"). JavaObject("MyButton").GetStatics("java.lang.System").out

To print a message to the Java console, you can insert a statement similar to the following:

Set OutStream= Browser("Browser").Page("Page").JavaApplet("mybuttonapplet.htm"). JavaObject("MyButton").GetStatics("java.lang.System").out
OutStream.println "Hello, World!"

Back to top

FireEvent/FireEventEx Methods

You can simulate an event on a Java object during a run session with the FireEvent and FireEventEx methods. The FireEvent method simulates an event on a Java object using one of several pre-defined event constants. If the list of pre-defined constants does not cover the event you want to fire, you can use the FireEventEx method to fire any Java event.

For example, you can use the FireEvent method to fire a MouseClick event on the JavaObject called MyButton_0.

Browser("Browser").Page("Page").Applet("mybuttonapplet.htm").JavaObject("MyButton_0").FireEvent micMouseClick, 0, "BUTTON1_MASK", 4, 4, 1, "OFF"

Alternatively, you can use the FireEventEx method to fire the same event as follows:

Browser("Browser").Page("Page").Applet("mybuttonapplet.htm").JavaObject("MyButton_0").FireEventEx "java.awt.event.MouseEvent", "MOUSE_CLICKED", 0, "BUTTON1_MASK", 4,4, 1, "False"

Note that you can pass any Java constant that is used as one of the event's constructor parameters using its string, rather than its value. In the example above, the "java.awt.event.MouseEvent" Java constant MOUSE_CLICKED is supplied as a string argument instead of its value (500 in this example).

Back to top