invokeMethods Method

Class

JavaMainWin.

Availability

This functionality is supported only if you are using the Classic Agent.

Action

Retrieves information about a visible Java GUI object by calling a sequence of nested methods inside Java with arguments specified in 4Test.

Syntax

anyValue = object.invokeMethods(lsMethods, llanyArgs)
Variable Description
anyValue Value describing the object. ANYTYPE.
lsMethods A list of method names in the order that they are to be called. LIST OF STRING.
llanyArgs A list of argument lists, to be matched with the method names in lsMethods. LIST OF LIST OF ANYTYPE.

Notes

This method is available for Windows environments. The first method in the lsMethods method list is invoked on object with the argument list specified by the first element of llanyArgs. This method call and all subsequent calls except the last one must have a return object. Each return object becomes the target for calling the next method in lsMethods with the next argument list in llanyArgs until the last method call. If the method names, argument lists, and return classes do not match, a runtime error is generated and reported to 4Test.

Requirements

The invokeMethods method is declared for all built-in 4Test Java classes. However, you must add the method to the class declaration of any custom class for which invokeMethods is invoked.
Note: Record class will include the invokeMethods declaration if you check the Show all methods check box.

Example 1

The following simple example uses invokeMethods to call getScrollPosition, which returns a Point object. Then invokeMethods calls the toString method, which returns a string representing the point object returned from the first call to getScrollPosition.

sValue = MyDialog.ScrollableObject.invokeMethods({"getScrollPosition", "toString"}, {{}, {}})

Example 2

To draw a line in a multiline text field, you need to access a graphics object inside the text field by calling the following methods in Java:
main()
{
  TextField multiLine = ...; // get reference to multiline text field
  Graphics graphObj = multiLine.getGraphics();
  graphObj.drawLine(10, 10, 20, 20);
}
However, you cannot call the above sequence of methods from 4Test because Graphics is not 4Test-compatible. Instead, you can insert the invokeMethods prototype in the TextField class declaration, then add invokeMethods by hand to your test script to draw a line in the Graphics object nested inside the multiline text field, as shown in this 4Test function:
DrawLineInTextField()
MyDialog.Invoke() // Invoke Java dialog that contains the text field
MyDialog.TheTextField.invokeMethods({"getGraphics", "drawLine"}, {{}, {10, 10, 20, 20}})
In this code, the following methods are called in Java:
  • getGraphics is invoked on the multiline text field TheTextField with an empty argument list, returning a Graphics object.
  • drawLine is invoked on the Graphics object, to draw a line starting from (x,y) coordinates (10,10) and continuing to (x,y) coordinates (20,20).