JavaTree Object

Description

A Java tree.

Operations

The sections below list the built-in methods and properties that you can use as operations for the JavaTree object.

Note: You can also view a list and descriptions of the JavaTree description properties, for use in object repository descriptions, programmatic descriptions, checkpoint and output value steps, and as argument values for the GetTOProperty and GetROProperty methods.

Methods

Method ActivateActivates a node in a tree.
Method AddRangeAdds the specified range of nodes to the current selection in a tree.
Common Method CaptureBitmapSaves a screen capture of the object as a .png or .bmp image using the specified file name.
Common Method CheckChecks whether the actual value of an item matches the expected value.
Common Method CheckPropertyChecks whether the actual value of the specified object property matches the specified expected value within the specified timeout.
Common Method ChildObjectsReturns the collection of child objects contained within the object.
Method ClickClicks the specified location with the specified mouse button.
Method CollapseCollapses an expandable Java tree.
Method CreateObjectCreates an instance of any Java object within your application.
Method DblClickDouble-clicks the specified location with the specified mouse button.
Method DeselectClears the selection of a node in a tree.
Method DeselectRangeClears the selection of the specified range of nodes in a tree.
Method ExpandExpands an expandable Java tree.
Method ExtendSelectSelects an additional node in the tree.
Method FireEventSimulates an event on a test object using one of several pre-defined event constants.
Method FireEventExSimulates an event on a Java test object, given the ClassName, Event ID, and Event Parameters.
Method GetColumnHeaderReturns the header of the specified column in the tree.
Method GetColumnValueReturns the text from the specified column in the specified node in the tree.
Method GetItemReturns the value of the node specified by the index.
Common Method GetROPropertyReturns the current value of the description properties from the object in the application.
Method GetStaticsReturns the Java object capable of accessing static members (methods and fields) of the specified Java class.
Common Method GetTOPropertiesReturns the collection of properties and values used to identify the object.
Common Method GetTOPropertyReturns the value of the specified description properties from the test object description.
Method MouseDragPerforms a mouse drag and drop operation from the specified X1, Y1 coordinates to the specified Xn, Yn coordinates.
Method OpenContextMenuOpens the context menu of a node in a Java tree.
Common Method OutputRetrieves the current value of an item and stores it in a specified location.
Method PressKeyPresses the specified key and modifier in the object.
Common Method RefreshObjectInstructs UFT to re-identify the object in the application the next time a step refers to this object.
Method SelectSelects a node in a tree.
Method SelectRangeSelects the specified range of nodes in a tree.
Method SetItemStateSets the state of the check box icon of the specified node in the tree.
Common Method SetTOPropertySets the value of the specified description properties in the test object description.
Common Method ToStringReturns a string that represents the test object.
Method TypeTypes the specified text in the object.
Common Method WaitPropertyWaits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step.

Properties

Common Property ExistChecks whether the object currently exists in the open application.
Common Property ObjectAccesses the native methods and properties of the object.

 

Back to top

Activate Method

Description

Activates a node in a tree.

Syntax

object.Activate (Item)

Arguments

ParameterDescription
Item Required. A Variant.
The path of the node to activate (double-click) in the tree. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.

Return Type

None.

Example

Activate a Tree Node (VBScript)
'The following example uses the Activate method to activate the Hotdog node of the JTree tree.

JavaApplet("SwingSetApplet").JavaTree("JTree").Activate "Hotdog"
Create a New Project in Eclipse (VBScript)
'This example shows how to use the Activate method of a JavaTree to create a new
'Java Project in Eclipse.

'Invokes the wizard from the main menu
JavaWindow("Java - Eclipse SDK").JavaMenu("File").JavaMenu("New").JavaMenu("Project...").Select
'Expands the tree to see whether the JavaProject item exists.
JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaTree("Wizards:").Expand "Java"
'Verifies that the item with desired name exists in the tree
JavaProject = JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaTree("Wizards:").GetItem(6)
'If the variable JavaProject contains the expected string, the project can be created.
If JavaProject = "Java;Java Project" Then
  'Uses the Activate method to dblclick the item and start Java Project creation
  JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaTree("Wizards:").Activate "Java;Java Project"
Else
   'Else - Report the error and stop the test.
   Reporter.ReportEvent micFail, "Java Project item was not found in required place of the Projects tree", "Cannot create Java project."
   ExitTest
End If
'Verifies that the appropriate dialog appears, if so - start the creation,
'otherwise, reports the error.
If JavaWindow("Java - Eclipse SDK").JavaWindow("New Java Project").Exist Then
  JavaWindow("Java - Eclipse SDK").JavaWindow("New Java Project").JavaButton("Create Project").Click
Else
  Reporter.ReportEvent micFail, "New Java Project dialog", "The dialog didn't appear", "The functionality is broken"
End If

 

Back to top

AddRange Method

Description

Adds the specified range of nodes to the current selection in a tree.

Syntax

object.AddRange (Item1, Item2)

Arguments

ParameterDescription
Item1 Required. A Variant.
The tree path of the first node in the range to add to the selection. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.
Item2 Required. A Variant.
The tree path of the last node in the range to add to the selection. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.

Return Type

None.

Example

Add More Items to Those Already Selected (VBScript)
'The following example uses the AddRange method to add the selected range of music items to those
'already selected.

Browser("Java Examples").Page("Java Examples").Frame("MAIN").JavaApplet("SwingSetApplet").JavaTree("JTree").AddRange "Music;Rock;The Beatles;Abbey Road;You Never Give Me Your Money", "Music;Rock;The Beatles;Abbey Road;Carry That Weight"
Define New Classes the in JavaProject Tree in Eclipse (VBScript)
'This example shows how to use the methods: ExtendSelect and AddRange to define a set of classes
'in JavaProject tree in Eclipse to be moved out from the project's "build path"

'Selects a default package to see which classes should be excluded.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").Select "NewProject;(default package)"
'Selects the first item to be removed.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").Select "NewProject;(default package);AdditionalClass1.java"
'Adds another one that is located right after it in the list
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").ExtendSelect "NewProject;(default package);AdditionalClass2.java"
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").AddRange "NewProject;(default package);Class1.java", "NewProject;(default package);Class3.java"
'Uses the AddRange method here because there are 3 items Class1-Class3.
'If it used the ExtendSelect method then 3 records are added, whereas using AddRange yields  1 record.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").OpenContextMenu "NewProject;(default package);AdditionalClass1.java"
JavaWindow("Java - AdditionalClass1.java").WinMenu("ContextMenu").Select "Build Path;Exclude"
'Checks that the items are excluded from the build path and appear in the root tree hierarchy
TreeContentCheck ("JavaProject")

 

Back to top

Click Method

Description

Clicks the specified location with the specified mouse button.

Syntax

object.Click (X, Y, [MouseButton])

Arguments

ParameterDescription
X Required. A Variant.
The x-coordinate of the click.
Y Required. A Variant.
The y-coordinate of the click.
MouseButton Optional. A String value.
Indicates whether the click should be performed with the left or right mouse button.
Possible values: 
   "LEFT" (default)
   "RIGHT"


Default value = "LEFT"

Return Type

None.

IMPORTANT

You must enter valid x- and y-coordinates.

Example

Click a Tree Nod (VBScript)
'The following example uses the Click method to click the Periodic JavaTree node at coordinates
'503 and 55 using the left mouse button.

Browser("Periodic").Page("Periodic").JavaApplet("Periodic").JavaTree("Periodic").Click 503, 55, "LEFT"

 

Back to top

Collapse Method

Description

Collapses an expandable Java tree.

Syntax

object.Collapse (Item)

Arguments

ParameterDescription
Item Required. A Variant.
The node to collapse in the tree. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.

Return Type

None.

Example

Collapse a Subfolder (VBScript)
'The following example uses the Collapse method to collapse the Jazz subfolder in the Music folder
'of the SwingSetApplet applet.

Browser("SwingSet demo").Page("SwingSet demo").JavaApplet("SwingSetApplet").JavaTree("JTree").Collapse "Music;Jazz"
Select a Range of Nodes and Copy and Paste Them (VBScript)
'This example copies classes from an Eclipse Java project to another package using the methods 'SelectRange and OpenContextMenu.
'Expands the project's tree to get to desirable package
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").Expand "NewProject"
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").Expand "NewProject;(default package)"
'Selects the range of classes to copy
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").SelectRange "NewProject;(default package);Class1.java", "NewProject;(default package);Class3.java"
'Checks that the tree supports multiple selections and that the proper items are selected
If Not JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").CheckProperty("value", "NewProject;(default package);Class2.javaNewProject;(default package);Class1.javaNewProject;(default package);Class3.java") Then
Reporter.ReportEvent micFail, "Tree multiple selection", "The functionality is broken"
End If
'Uses the OpenContextMenu method to perform copy/paste operation between packages
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").OpenContextMenu ("NewProject;(default package);Class1.java")
'Note that after invokation JavaMenu becomes a WinMenu. This is to be expected.
JavaWindow("Java - Class3.java - Eclipse").WinMenu("ContextMenu").Select "Copy  Ctrl+C"
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").Select "NewProject;org.eclipse.core.launcher"
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").OpenContextMenu ("NewProject;org.eclipse.core.launcher")
JavaWindow("Java - Class3.java - Eclipse").WinMenu("ContextMenu").Select "Paste Ctrl+V"
'Calls a user function that verifies the content of the tree.
TreeContentCheck ("JavaProject")
'Collapses the tree object.
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").Collapse "NewProject"
'Checks that after the work on the tree is finished, there are no extra items in its root.
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").CheckProperty "items count", 1

 

Back to top

CreateObject Method

Description

Creates an instance of any Java object within your application.

Syntax

object.CreateObject (ClassName)

Arguments

ParameterDescription
ClassName Required. A String value.
The Java class name.
Required. None
Any arguments required for the object's constructor. Enter the values in a comma separated list. If no arguments are required for the constructor, you do not need to supply a value for the ConsArgs argument.

Return Type

A Variant.

Returns an object reference. You can use this reference to access the object's methods and properties, without using the Object property.

IMPORTANT

  • 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.
  • It is recommended to use the CreateObject method on a 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.
  • For more information on the CreateObject method, and additional documentation on standard JDK classes, see: http://docs.oracle.com/javase/6/docs/api/index.html

Example

Create a New Object (VBScript)
'The following example uses the CreateObject method to create a rectangle object.

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

 

Back to top

DblClick Method

Description

Double-clicks the specified location with the specified mouse button.

Syntax

object.DblClick (X, Y, [MouseButton])

Arguments

ParameterDescription
X Required. A Variant.
The x coordinate of the location on the applet to be clicked.
Y Required. A Variant.
The y-coordinate of the location on the applet to be clicked.
MouseButton Optional. A String value.
Indicates whether the double-click should be performed with the left or right mouse button.
Possible values: 
   "LEFT" (default)
   "RIGHT"
Default value = "LEFT"

Return Type

None.

IMPORTANT

You must enter valid x- and y-coordinates.

Example

Double-Click an Object (VBScript)
'The following example uses the DblClick method to double-click the "Periodic JavaButton" object at
'coordinates 503 and 55, using the left mouse button.
Browser("Periodic").Page("Periodic").JavaApplet("Periodic").JavaButton("Frame").DblClick 5, 5, "LEFT"

 

Back to top

Deselect Method

Description

Clears the selection of a node in a tree.

Syntax

object.Deselect (Item)

Arguments

ParameterDescription
Item Required. A Variant.
The tree path of the node to deselect. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.

Return Type

None.

Example

Deselect a Node in a Tree (VBScript)
'The following example uses the Deselect method to clear the selection of: "She's So Heavy" from the JTree tree.

Browser("SwingSet demo").Page("SwingSet demo").JavaApplet("SwingSetApplet").JavaTree("JTree").Deselect "Music;Rock;The Beatles;Abbey Road;She's So Heavy"
Select a Range of Tree Items and then Clear Some (VBScript)
'This example selects a range of items, and then clears some items within that range.
'It deletes the items that remain selected and runs a function that verifies that the proper
'items remain.

'Selects nodes Class1-9 under the NewProject(default package) tree node.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").SelectRange "NewProject;(default package);Class1.java", "NewProject;(default package);Class9.java"
'Clears the selection of the Class3 node.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").Deselect "NewProject;(default package);Class3.java"
'Clears the selection of the Class5-8 nodes.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").DeselectRange "NewProject;(default package);Class5.java", "NewProject;(default package);Class8.java"
'Opens the context menu and select to Delete the items that remain selected.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").OpenContextMenu "NewProject;(default package);Class8.java"
JavaWindow("Java - AdditionalClass1.java").WinMenu("ContextMenu").Select "Delete    Delete"
'If a confirmation window opens, clicks Yes to close the window.  If it doesn't open, reports the failure to the run results.
If Not JavaWindow("Java - AdditionalClass1.java").JavaWindow("Confirm Delete").Exist Then
    Reporter.ReportEvent micFail, "Confirm delete", "The delete operation was not accompanied with confirm dialog"
    Else
    JavaWindow("Java - AdditionalClass1.java").JavaWindow("Confirm Delete").JavaButton("Yes").Click
End If
'Runs a function to confirm that the remaining items match the expected list.
VerifyTreeContent (TreeName)

 

Back to top

DeselectRange Method

Description

Clears the selection of the specified range of nodes in a tree.

Syntax

object.DeselectRange (Item1, Item2)

Arguments

ParameterDescription
Item1 Required. A Variant.
The tree path of the first node in the range to deselect. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.
Item2 Required. A Variant.
The tree path of the last node in the range to deselect. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.

Return Type

None.

Example

Select a Range of Tree Items and then Clear Some (VBScript)
'This example selects a range of items, and then clears some items within that range.
'It deletes the items that remain selected and runs a function that verifies that the proper
'items remain.

'Selects nodes Class1-9 under the NewProject(default package) tree node.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").SelectRange "NewProject;(default package);Class1.java", "NewProject;(default package);Class9.java"
'Clears the selection of the Class3 node.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").Deselect "NewProject;(default package);Class3.java"
'Clears the selection of the Class5-8 nodes.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").DeselectRange "NewProject;(default package);Class5.java", "NewProject;(default package);Class8.java"
'Opens the context menu and select to Delete the items that remain selected.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").OpenContextMenu "NewProject;(default package);Class8.java"
JavaWindow("Java - AdditionalClass1.java").WinMenu("ContextMenu").Select "Delete    Delete"
'If a confirmation window opens, clicks Yes to close the window.  If it doesn't open, reports the failure to the run results.
If Not JavaWindow("Java - AdditionalClass1.java").JavaWindow("Confirm Delete").Exist Then
    Reporter.ReportEvent micFail, "Confirm delete", "The delete operation was not accompanied with confirm dialog"
    Else
    JavaWindow("Java - AdditionalClass1.java").JavaWindow("Confirm Delete").JavaButton("Yes").Click
End If
'Runs a function to confirm that the remaining items match the expected list.
VerifyTreeContent (TreeName)
Deselect a Range of Nodes in a Tree (VBScript)
'The following example uses the DeselectRange method to clear the selection of a range of nodes from the JTree list.

Browser("Java Examples").Page("Java Examples").Frame("MAIN").JavaApplet("SwingSetApplet").JavaTree("JTree").DeselectRange "Music;Rock;The Beatles;Abbey Road;You Never Give Me Your Money", "Music;Rock;The Beatles;Abbey Road;Carry That Weight"

 

Back to top

Expand Method

Description

Expands an expandable Java tree.

Syntax

object.Expand (Item)

Arguments

ParameterDescription
Item Required. A Variant.
The tree path of the node to expand within the tree. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.

Return Type

None.

Example

Example (C#)

     
Expand a Subfolder (VBScript)
'The following example uses the Expand method to expand the Jazz subfolder in the Music folder.

Browser("SwingSet demo").Page("SwingSet demo").JavaApplet("SwingSetApplet").JavaTree("JTree").Expand "Music;Jazz"
Create a New Java Project in Eclipse (VBScript)
'This examples shows how to use the Expand, Select, GetItem methods of JavaTree to create
'a new Java Project in Eclipse

'Invokes the wizard from the main menu.
JavaWindow("Java - Eclipse SDK").JavaMenu("File").JavaMenu("New").JavaMenu("Project...").Select
'Expands the Tree to see whether the JavaProject item exists.
JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaTree("Wizards:").Expand "Java"
'Verifies that the item with desired name exists in the tree
JavaProject = JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaTree("Wizards:").GetItem(6)
'If the item exists the project can be created.
If JavaProject = "Java;Java Project" Then
JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaTree("Wizards:").Select "Java;Java Project"
Else
   'If the item does not exist, the project cannot be created and the test cannot continue.
   Reporter.ReportEvent micFail, "Cannot create Java project.", "Java Project item was not found in required place of the Projects tree."
ExitTest
End If
JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaButton("Next >").Click
'Verifies that desirable dialog box appears, if it does, creates the project.
'otherwise, reports the error.
If JavaWindow("Java - Eclipse SDK").JavaWindow("New Java Project").Exist Then
JavaWindow("Java - Eclipse SDK").JavaWindow("New Java Project").JavaButton("Create Project").Click
Else
Reporter.ReportEvent micFail, "New Java Project dialog", "The dialog box didn't appear."
End If

 

Back to top

ExtendSelect Method

Description

Selects an additional node in the tree.

Syntax

object.ExtendSelect (Item)

Arguments

ParameterDescription
Item Required. A Variant.
The path of the node to be selected in the tree. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.

Return Type

None.

IMPORTANT

You can use this method, for example, to simulate using the control button to select multiple, non-consecutive nodes in a tree.

Example

Define New Classes in the JavaProject Tree in Eclipse (VBScript)
'This example shows how to use the methods: ExtendSelect and AddRange to define a set of classes
'in JavaProject tree in Eclipse to be moved out from the project's "build path"

'Selects a default package to see which classes should be excluded.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").Select "NewProject;(default package)"
'Selects the first item to be removed.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").Select "NewProject;(default package);AdditionalClass1.java"
'Adds another one that is located right after it in the list
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").ExtendSelect "NewProject;(default package);AdditionalClass2.java"
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").AddRange "NewProject;(default package);Class1.java", "NewProject;(default package);Class3.java"
'Uses the AddRange method here because there are 3 items Class1-Class3.
'If it used the ExtendSelect method then 3 records are added, whereas using AddRange yields  1 record.
JavaWindow("Java - AdditionalClass1.java").JavaTree("Tree").OpenContextMenu "NewProject;(default package);AdditionalClass1.java"
JavaWindow("Java - AdditionalClass1.java").WinMenu("ContextMenu").Select "Build Path;Exclude"
'Checks that the items are excluded from the build path and appear in the root tree hierarchy
TreeContentCheck ("JavaProject")
Add a Node to Already Selected Nodes (VBScript)
'The following example uses the ExtendSelect method to add the "She's So Heavy" node to the selected nodes.

Browser("SwingSet demo").Page("SwingSet demo").JavaApplet("SwingSetApplet").JavaTree("JTree").ExtendSelect "Music;Rock;The Beatles;Abbey Road;She's So Heavy"

 

Back to top

FireEvent Method

Description

Simulates an event on a test object using one of several pre-defined event constants.

Syntax

object.FireEvent (EventType)

Arguments

ParameterDescription
EventType Required. A tagJAVAEVENTTYPE Value.
The name of the pre-defined constant for the event you want to fire.
Required. None

Any parameters of the event's constructor except for the source and EventID. You can pass any Java constant that is used as one of the event’s constructor parameters using its string instead of its value. Enter the values in a comma separated list. If no additional parameters are required, you do not need to supply a value for the EventArguments argument.

Return Type

None.

IMPORTANT

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 event that has a constructor.

For more information on the FireEvent method, and additional documentation on AWTEvents, see:

http://docs.oracle.com/javase/6/docs/api/java/awt/AWTEvent.html

For additional documentation on MouseEvents, see:

http://docs.oracle.com/javase/6/docs/api/java/awt/event/MouseEvent.html

For additional documentation on KeyEvents, see:

http://docs.oracle.com/javase/6/docs/api/java/awt/event/KeyEvent.html

Example

Fire a Mouse Click Event (VBScript)
'The following example uses the FireEvent method to fire a MouseClick event on the MySpinButton_0 JavaSpin.
Browser("Browser").Page("Page").JavaApplet("mybuttonapplet").JavaSpin("MySpinButton_0").FireEvent micMouseClick, 0, "BUTTON1_MASK", 4, 4, 1, "OFF"

 

Back to top

FireEventEx Method

Description

Simulates an event on a Java test object, given the ClassName, Event ID, and Event Parameters.

Syntax

object.FireEventEx (ClassName, EventId)

Arguments

ParameterDescription
ClassName Required. A String value.
The name of the Java class representing the event to be activated.
EventId Required. A String value.
The event ID number or the final field string that represents the event ID.
Required. None

Any parameters of the event's constructor except for the source and EventID. You can pass any Java constant that is used as one of the event’s constructor parameters using its string instead of its value.Enter the values in a comma separated list. If no additional parameters are required, you do not need to supply a value for the EventArguments argument.

Return Type

None.

IMPORTANT

You can use FireEventEx for any Java event.

For more information on the FireEventEx method, and additional documentation on AWTEvents, see:

http://docs.oracle.com/javase/6/docs/api/java/awt/AWTEvent.html

For additional documentation on MouseEvents, see:

http://docs.oracle.com/javase/6/docs/api/java/awt/event/MouseEvent.html

For additional documentation on KeyEvents, see:

http://docs.oracle.com/javase/6/docs/api/java/awt/event/KeyEvent.html

Example

Fire a Mouse Click Event on a Check Box (VBScript)
'The following example uses the FireEventEx method to fire a MouseClick event on the MyCheckBox_0 Java check box.
Browser("Browser").Page("Page").JavaApplet("mybuttonapplet").JavaCheckBox("MyCheckBox_0").FireEventEx "java.awt.event.MouseEvent", "MOUSE_CLICKED", 0, "BUTTON1_MASK", 4, 4, 1, "False"

 

Back to top

GetColumnHeader Method

Description

Returns the header of the specified column in the tree.

Syntax

object.GetColumnHeader (Column)

Arguments

ParameterDescription
Column Required. A Variant.

The name or index of the column whose header you want to return. Specify index values in the format "#N" where N is the numeric index. Index values begin with 0.

Return Type

A Variant.

Example

Compare the Header Name and Column Value with a String (VBScript)
'The following example checks the column headers and value against a fixed value
header1 = JavaWindow("choose file").JavaTree("file list").GetColumnHeader(0)
header2 = JavaWindow("choose file").JavaTree("file list").GetColumnHeader(1)
If header1 <> "Name" And header2 <> "Modified" Then
Reporter.ReportEvent micFail, "file list", "wrong header names"
End If
modified_value = JavaWindow("choose file").JavaTree("file list").GetColumnValue("root;Program Files", "Modified")
If modified_value <> "Yesterday" Then
Reporter.ReportEvent micFail, "file list", "wrong modification value"
End If

 

Back to top

GetColumnValue Method

Description

Returns the text from the specified column in the specified node in the tree.

Syntax

object.GetColumnValue (Item, Column)

Arguments

ParameterDescription
Item Required. A Variant.
The name or index of the node from which you want to return the value. Specify index values in the format "#N" where N is the numeric index. Index values begin with 0. 
Column Required. A Variant.
The name or index of the column from which you want to return the value. Specify index values in the format "#N" where N is the numeric index. Index values begin with 0.

Return Type

A Variant.

Example

Compare the Header Name and Column Value with a String (VBScript)
'The following example checks the column headers and value against a fixed value
header1 = JavaWindow("choose file").JavaTree("file list").GetColumnHeader(0)
header2 = JavaWindow("choose file").JavaTree("file list").GetColumnHeader(1)
If header1 <> "Name" And header2 <> "Modified" Then
Reporter.ReportEvent micFail, "file list", "wrong header names"
End If
modified_value = JavaWindow("choose file").JavaTree("file list").GetColumnValue("root;Program Files", "Modified")
If modified_value <> "Yesterday" Then
Reporter.ReportEvent micFail, "file list", "wrong modification value"
End If

 

Back to top

GetItem Method

Description

Returns the value of the node specified by the index.

Syntax

object.GetItem (index)

Arguments

ParameterDescription
index Required. A Variant.

The numeric index of the node you want to retrieve. Index values begin with 0.

Note: To calculate the index, count only the expanded nodes in the tree. Do not count child nodes of a collapsed parent node. The first root node in the tree is numbered 0.

Return Type

A Variant.

Example

Create a New Java Project in Eclispe (VBScript)
'This examples shows how to use the Expand, Select, GetItem methods of JavaTree to create
'a new Java Project in Eclipse

'Invokes the wizard from the main menu.
JavaWindow("Java - Eclipse SDK").JavaMenu("File").JavaMenu("New").JavaMenu("Project...").Select
'Expands the Tree to see whether the JavaProject item exists.
JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaTree("Wizards:").Expand "Java"
'Verifies that the item with desired name exists in the tree
JavaProject = JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaTree("Wizards:").GetItem(6)
'If the item exists the project can be created.
If JavaProject = "Java;Java Project" Then
JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaTree("Wizards:").Select "Java;Java Project"
Else
   'If the item does not exist, the project cannot be created and the test cannot continue.
   Reporter.ReportEvent micFail, "Cannot create Java project.", "Java Project item was not found in required place of the Projects tree."
ExitTest
End If
JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaButton("Next >").Click
'Verifies that desirable dialog box appears, if it does, creates the project.
'otherwise, reports the error.
If JavaWindow("Java - Eclipse SDK").JavaWindow("New Java Project").Exist Then
JavaWindow("Java - Eclipse SDK").JavaWindow("New Java Project").JavaButton("Create Project").Click
Else
Reporter.ReportEvent micFail, "New Java Project dialog", "The dialog box didn't appear."
End If
Get the Value of a Tree Node (VBScript)
'The following example uses the GetItem method to retrieve the value of the second node in the tree.

Item = Browser("index").Page("Java Examples").Frame("MAIN").JavaApplet("TreeApplet").JavaTree("Tree View 2").GetItem("1")

 

Back to top

GetStatics Method

Description

Returns the Java object capable of accessing static members (methods and fields) of the specified Java class.

Syntax

object.GetStatics (ClassName)

Arguments

ParameterDescription
ClassName Required. A String value.
The Java class name whose static members you want to access.

Return Type

A Variant.

A reference to a Java object.

IMPORTANT

The class loader of the Java test object on which the GetStatics method is performed is used to load the class specified as a parameter of the GetStatics method.

Example

Get a Static Field of a Class (VBScript)
'The following example uses the GetStatics method to retrieve the value of the
'out field of the java.lang.System class.
Set OutStream = JavaWindow("Win").JavaRadioButton("SomeButton").GetStatics("java.lang.System").out
Invoke a Static Method of a Class (VBScript)
'The following example uses the GetStatics method to retrieve the object
'through which static members of the java.lang.System class can be accessed.
'It then uses this object to invoke the gc method of the .java.lang.System class,
'which runs the garbage collector on the application.
Set SystemStatics = Browser("Browser").Page("Page").JavaApplet("mybuttonapplet.htm").JavaObject("MyButton").GetStatics("java.lang.System")
SystemStatics.gc
Print a String to the Standard Output (VBScript)
'The following example uses the GetStatics method to print the "Hello, World!" string to the standard
'output, by using the static out field of the java.lang.System class.
JavaWindow("Win").JavaEdit("Name").GetStatics("java.lang.System").out.println ("Hello, World!")

 

Back to top

MouseDrag Method

Description

Performs a mouse drag and drop operation from the specified X1, Y1 coordinates to the specified Xn, Yn coordinates.

Syntax

object.MouseDrag (X1, Y1, X2, Y2, [MouseButton])

Arguments

ParameterDescription
X1 Required. A Variant.
The x-coordinate of the location from which to begin the mouse drag.
Y1 Required. A Variant.
The y-coordinate of the location from which to begin the mouse drag.
X2 Required. A Variant.
The x-coordinate of the location where the mouse drag stops.
Y2 Required. A Variant.
The y-coordinate of the location where the mouse drag stops.
MouseButton Optional. A String value.
Indicates whether the click should be performed with the left or right mouse button. 
Possible values: 
       "LEFT" (default)
       "RIGHT"
Default value = "LEFT"

Return Type

None.

Example

Perform Mouse Drag and Drop Operations (VBScript)
'##IS_EXAMPLE For="JAVAPACKAGELib~Setting~MouseDrag", Caption="Perform Mouse Drag and Drop Operations"
'The following example uses the MouseDrag method to perform a mouse drag and drop operation on a Java table object.
Browser("Browser").Page("Page").JavaApplet("Periodic").JavaTable("Periodic").MouseDrag 4, 10, 10, 10, "LEFT"

 

Back to top

OpenContextMenu Method

Description

Opens the context menu of a node in a Java tree.

Syntax

object.OpenContextMenu (Item)

Arguments

ParameterDescription
Item Required. A Variant.
The path of the tree node whose context menu you want to open. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.

Return Type

None.

Example

Select a Range of Nodes and Copy and Paste Them (VBScript)
'This example copies classes from an Eclipse Java project to another package using the methods
'SelectRange and OpenContextMenu.

'Expands the project's tree to get to desirable package
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").Expand "NewProject"
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").Expand "NewProject;(default package)"
'Selects the range of classes to copy
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").SelectRange "NewProject;(default package);Class1.java", "NewProject;(default package);Class3.java"
'Checks that the tree supports multiple selections and that the proper items are selected
If Not JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").CheckProperty("value", "NewProject;(default package);Class2.javaNewProject;(default package);Class1.javaNewProject;(default package);Class3.java") Then
Reporter.ReportEvent micFail, "Tree multiple selection", "The functionality is broken"
End If
'Uses the OpenContextMenu method to perform copy/paste operation between packages
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").OpenContextMenu ("NewProject;(default package);Class1.java")
'Note that after invokation JavaMenu becomes a WinMenu. This is to be expected.
JavaWindow("Java - Class3.java - Eclipse").WinMenu("ContextMenu").Select "Copy  Ctrl+C"
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").Select "NewProject;org.eclipse.core.launcher"
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").OpenContextMenu ("NewProject;org.eclipse.core.launcher")
JavaWindow("Java - Class3.java - Eclipse").WinMenu("ContextMenu").Select "Paste Ctrl+V"
'Calls a user function that verifies the content of the tree.
TreeContentCheck ("JavaProject")
'Collapses the tree object.
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").Collapse "NewProject"
'Checks that after the work on the tree is finished, there are no extra items in its root.
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").CheckProperty "items count", 1
Select an Item from the Context Menu of a Java Tree (VBScript)
'This following example deletes a resource from the Eclipse package viewer.

JavaWindow("Eclipse").JavaTree("Tree").OpenContextMenu "Project111;src;org.demo;Main.java"
JavaWindow("Eclipse").WinMenu("ContextMenu").Select "Delete"

 

Back to top

PressKey Method

Description

Presses the specified key and modifier in the object.

Syntax

object.PressKey (Key, [Modifier])

Arguments

ParameterDescription
Key Required. A String value.
The keyboard key(s) to press. If you want to press a function key (F1-F12), use a constant from the following list:
Constant
Action
micF1
Presses the F1 key.
micF2
Presses the F2 key.
micF3
Presses the F3 key.
micF4
Presses the F4 key.
micF5
Presses the F5 key.
micF6
Presses the F6 key.
micF7
Presses the F7 key.
micF8
Presses the F8 key.
micF9
Presses the F9 key.
micF10
Presses the F10 key.
micF11
Presses the F11 key.
micF12
Presses the F12 key.

Modifier Optional. A String value.
The modifier(s) to use.
Supported modifiers:
micCtrl
micAlt
micShift
micCtrlAlt
micCtrlShift
micCtrlShiftAlt
micShiftAlt

Default value = ""

Return Type

None.

IMPORTANT

When typing keys during a recording session, UFT records the PressKey method when one or more hot keys (such as F-keys, Alt, Ctrl, and so on) are used. 

It also records the PressKey method for any typed key in a Java object that supports text editing, but does not support the Set method.

Example

Use the Ctrl-X and Ctrl-V Shortcuts to Cut and Paste (VBScript)
'The following example enters text in an edit box and then uses the PressKey method to cut the word 'edit'
'and paste it in a different location using the Ctrl-X and Ctrl-V shortcut keys.

'Place the cursor at the beginning of the text box.
Browser("Java Examples").Page ("Java Examples")
.Frame("MAIN").JavaApplet("TextAreaApplet").JavaEdit("Text field").SetCaretPos 0, 0
'Enter a sentence in the text box.
Browser("Java Examples").Page("Java Examples").Frame("MAIN").JavaApplet("TextAreaApplet").JavaEdit("Text field ").Set "Set the edit text."
'Select (highlight) the word 'edit'.
Browser("Java Examples").Page("Java Examples").Frame("MAIN").JavaApplet("TextAreaApplet").JavaEdit("Text field").SetSelection 0, 8, 0, 12
'Cut the word 'edit'
Browser("Java Examples").Page("Java Examples").Frame("MAIN").JavaApplet("TextAreaApplet").JavaEdit("Text field").PressKey "X", micCtrl
'Place the cursor at the end of the text.
Browser("Java Examples").Page("Java Examples").Frame("MAIN").JavaApplet("TextAreaApplet").JavaEdit("Text field").SetCaretPos 0, 12
'Insert a space at the end of the text.
Browser("Java Examples").Page("Java Examples").Frame("MAIN").JavaApplet("TextAreaApplet").JavaEdit("Text field").Insert " ", 0, 12
'Paste the word 'edit' at the end of the text.
Browser("Java Examples").Page("Java Examples").Frame("MAIN").JavaApplet("TextAreaApplet").JavaEdit("Text field").PressKey "V", micCtrl

 

Back to top

Select Method

Description

Selects a node in a tree.

Syntax

object.Select (Item)

Arguments

ParameterDescription
Item Required. A Variant.
The tree path of the node to select in the tree. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.

Return Type

None.

Example

Create a New Java Project in Eclipse (VBScript)
'This examples shows how to use the Expand, Select, GetItem methods of JavaTree to create
'a new Java Project in Eclipse

'Invokes the wizard from the main menu.
JavaWindow("Java - Eclipse SDK").JavaMenu("File").JavaMenu("New").JavaMenu("Project...").Select
'Expands the Tree to see whether the JavaProject item exists.
JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaTree("Wizards:").Expand "Java"
'Verifies that the item with desired name exists in the tree
JavaProject = JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaTree("Wizards:").GetItem(6)
'If the item exists the project can be created.
If JavaProject = "Java;Java Project" Then
JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaTree("Wizards:").Select "Java;Java Project"
Else
   'If the item does not exist, the project cannot be created and the test cannot continue.
   Reporter.ReportEvent micFail, "Cannot create Java project.", "Java Project item was not found in required place of the Projects tree."
ExitTest
End If
JavaWindow("Java - Eclipse SDK").JavaWindow("New Project").JavaButton("Next >").Click
'Verifies that desirable dialog box appears, if it does, creates the project.
'otherwise, reports the error.
If JavaWindow("Java - Eclipse SDK").JavaWindow("New Java Project").Exist Then
JavaWindow("Java - Eclipse SDK").JavaWindow("New Java Project").JavaButton("Create Project").Click
Else
Reporter.ReportEvent micFail, "New Java Project dialog", "The dialog box didn't appear."
End If
Select a Node in a Tree (VBScript)
'The following example uses the Select method to select "Hamburger" from the Entrees list in the
'Foodlist applet.

Browser("FastFoodHaven").Page("KidsMeals").JavaApplet("Foodlist").JavaTree("Entrees").Select "Hamburger"

 

Back to top

SelectRange Method

Description

Selects the specified range of nodes in a tree.

Syntax

object.SelectRange (Item1, Item2)

Arguments

ParameterDescription
Item1 Required. A Variant.
The tree path of the first node in the range to be selected. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.
Item2 Required. A Variant.
The tree path of the last node in the range to be selected. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.

Return Type

None.

Example

Select a Range of Nodes (VBScript)
'The following example uses the SelectRange method to select a range of nodes in the tree.

Browser("Java Examples").Page("Java Examples").Frame("MAIN").JavaApplet("SwingSetApplet").JavaTree("JTree").SelectRange "Music;Rock;The Beatles;Abbey Road;You Never Give Me Your Money", "Music;Rock;The Beatles;Abbey Road;Carry That Weight"
Select a Range of Nodes and Copy and Paste Them (VBScript)
'This example copies classes from an Eclipse Java project to another package using the methods
'SelectRange and OpenContextMenu.

'Expands the project's tree to get to desirable package
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").Expand "NewProject"
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").Expand "NewProject;(default package)"
'Selects the range of classes to copy
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").SelectRange "NewProject;(default package);Class1.java", "NewProject;(default package);Class3.java"
'Checks that the tree supports multiple selections and that the proper items are selected
If Not JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").CheckProperty("value", "NewProject;(default package);Class2.javaNewProject;(default package);Class1.javaNewProject;(default package);Class3.java") Then
Reporter.ReportEvent micFail, "Tree multiple selection", "The functionality is broken"
End If
'Uses the OpenContextMenu method to perform copy/paste operation between packages
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").OpenContextMenu ("NewProject;(default package);Class1.java")
'Note that after invokation JavaMenu becomes a WinMenu. This is to be expected.
JavaWindow("Java - Class3.java - Eclipse").WinMenu("ContextMenu").Select "Copy  Ctrl+C"
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").Select "NewProject;org.eclipse.core.launcher"
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").OpenContextMenu ("NewProject;org.eclipse.core.launcher")
JavaWindow("Java - Class3.java - Eclipse").WinMenu("ContextMenu").Select "Paste Ctrl+V"
'Calls a user function that verifies the content of the tree.
TreeContentCheck ("JavaProject")
'Collapses the tree object.
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").Collapse "NewProject"
'Checks that after the work on the tree is finished, there are no extra items in its root.
JavaWindow("Java - Class3.java - Eclipse").JavaTree("Tree").CheckProperty "items count", 1

 

Back to top

SetItemState Method

Description

Sets the state of the check box icon of the specified node in the tree.

Syntax

object.SetItemState (Item, State)

Arguments

ParameterDescription
Item Required. A Variant.
The path of the tree node whose context menu you want to open. The path is a list of the names or index values separated by the separator character specified in the Tree view path separator option in the Java pane of the Options dialog box.  Default separator value = semi-colon (;). Specify index values in the format "#N" where N is the numeric value. Index values begin with 0.

State Required. A long integer value.
The state you want to set. The state can either be an index, or one of the following state constants:

micChecked (1)--Selects the node's check box
micUnchecked (0)--Clears the node's check box
micClick (-1)--Clicks the node icon
micDblClick (-2)--Double-clicks the node icon

Return Type

None.

Example

Select the Check Boxes for All Nodes in a Java Tree (VBScript)
'The following example selects the check box for each visible (expanded) node in a Java tree

cnt = JavaWindow("SWT Controls").JavaTree("Tree").GetROProperty("items count")
For i = 0 To cnt - 1
            itm = JavaWindow("SWT Controls").JavaTree("Tree").GetItem(i)
            JavaWindow("SWT Controls").JavaTree("Tree").SetItemState itm, 1
Next

 

Back to top

Type Method

Description

Types the specified text in the object.

Syntax

object.Type (Text)

Arguments

ParameterDescription
Text Required. A String value.
The text to type and/or the modifier(s) to press.
Supported modifiers:
micAlt
micShift
micCtrlAlt
micCtrlShift
micCtrlShiftAlt
micShiftAlt

Return Type

None.

IMPORTANT

This method is not recorded. (Keyboard operations are recorded using the Set or PressKey methods.) The Type method is useful for entering a combination of text and keyboard modifiers. You concatenate text strings and keyboard modifiers using the ampersand (&) symbol. For example, you can enter: Type "Hello World" & micCtrl & "S"

To add this method to your test, use the Step Generator or enter it manually in the Keyword View or Editor. For more information, see the Unified Functional Testing User Guide.

Note: Although the Type method is supported for most objects, if you enter a Type statement for an object in which a user cannot enter text, the method has no visual effect.

Example

Type Text in an Edit Box (VBScript)
'The following example uses the Type method to type ABC in a Java edit box.
Browser("Periodic").Page("Periodic").JavaApplet("Periodic").JavaEdit("Text").Type "ABC"

 

Back to top