JavaToolbar Object
Description
A Java toolbar.
Operations
The sections below list the built-in methods and properties that you can use as operations for the JavaToolbar object.
Note: You can also view a list and descriptions of the JavaToolbar 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.
Important
Operations performed on toolbar objects in a JavaFX application are not recorded. Instead, actions are recorded on the objects contained in the toolbar.
Methods
CaptureBitmap | Saves a screen capture of the object as a .png or .bmp image using the specified file name. |
Check | Checks whether the actual value of an item matches the expected value. |
CheckProperty | Checks whether the actual value of the specified object property matches the specified expected value within the specified timeout. |
ChildObjects | Returns the collection of child objects contained within the object. |
GetAllROProperties | Returns the collection of properties and current values from the object in the application. |
Click | Clicks the specified location with the specified mouse button. |
CreateObject | Creates an instance of any Java object within your application. |
DblClick | Double-clicks the specified location with the specified mouse button. |
FireEvent | Simulates an event on a test object using one of several pre-defined event constants. |
FireEventEx | Simulates an event on a Java test object, given the ClassName, Event ID, and Event Parameters. |
GetContent | Returns a string containing the names of all of the buttons in the toolbar. |
GetItem | Returns the name of the toolbar button specified by its index. |
GetItemProperty | Returns the current value of a property for a toolbar button. |
GetItemsCount | Returns the number of buttons in the toolbar. |
GetROProperty | Returns the current value of the description property from the object in the application. |
GetSelection | Returns a list of all the buttons in a toolbar that are pressed or checked. |
GetStatics | Returns the Java object capable of accessing static members (methods and fields) of the specified Java class. |
GetTOProperties | Returns the collection of properties and values used to identify the object. |
GetTOProperty | Returns the value of the specified description property from the test object description. |
Highlight | Highlights the object in the application. |
MouseDrag | Performs a mouse drag and drop operation from the specified X1, Y1 coordinates to the specified Xn, Yn coordinates. |
Output | Retrieves the current value of an item and stores it in a specified location. |
Press | Clicks the specified toolbar button. |
PressKey | Presses the specified key and modifier in the object. |
RefreshObject | Instructs UFT One to re-identify the object in the application the next time a step refers to this object. |
SetTOProperty | Sets the value of the specified description property in the test object description. |
ShowDropdown | Opens the dropdown menu associated with the specified toolbar button by clicking the arrow part of the button. |
ToString | Returns a string that represents the test object. |
Type | Types the specified text in the object. |
WaitProperty | Waits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step. |
Properties
Exist | Checks whether the object currently exists in the open application. |
Object | Accesses the native methods and properties of the object. |
Click Method
Description
Clicks the specified location with the specified mouse button.
Syntax
object.Click (X, Y, [MouseButton])
Arguments
Parameter | Description |
---|---|
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
'The following example uses the Click method to click the Periodic JavaToolBar object at coordinates '503 and 55 using the left mouse button. Browser("Periodic").Page("Periodic").JavaApplet("Periodic").JavaToolBar("Periodic").Click 503, 55, "LEFT"
CreateObject Method
Description
Creates an instance of any Java object within your application.
Syntax
object.CreateObject (ClassName, ConsArgs)
Arguments
Parameter | Description |
---|---|
ClassName |
Required. A String value. The Java class name. |
ConsArgs |
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.
- We recommend using 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 the Java documentation.
Example
'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)
DblClick Method
Description
Double-clicks the specified location with the specified mouse button.
Syntax
object.DblClick (X, Y, [MouseButton])
Arguments
Parameter | Description |
---|---|
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
'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"
FireEvent Method
Description
Simulates an event on a test object using one of several pre-defined event constants.
Syntax
object.FireEvent (EventType, EventArguments)
Arguments
Parameter | Description |
---|---|
EventType |
Required. A Numeric Value. Possible values: micMouseEnter, micMouseExit, micMouseClick, micMousePress, micMouseRelease, micMouseDrag, micMouseMove, micKeyPress, micKeyRelease, micKeyType, micFocusGain, micFocusLost. Note: The FireEvent method is supported only for java.awt.* components . The events for org.eclipse.swt.widgets.* controls are not supported. |
EventArguments |
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.
- This method is not supported for SWT-based controls.
For more information on the FireEvent method, and additional documentation on events, see the Java documentation.
Example
'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"
FireEventEx Method
Description
Simulates an event on a Java test object, given the ClassName, Event ID, and Event Parameters.
Syntax
object.FireEventEx (ClassName, EventId, EventArguments)
Arguments
Parameter | Description |
---|---|
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. |
EventArguments |
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.
- This method is not supported for SWT-based controls.
For more information on the FireEventEx method, and additional documentation on events, see the Java documentation.
Example
'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"
GetContent Method
Description
Returns a string containing the names of all of the buttons in the toolbar.
Syntax
object.GetContent
Return Type
A String value.
The returned string contains all of the items in the toolbar separated by a semicolon (;).
Example
'The following example uses the GetContent method to retrieve all the buttons in a 'toolbar in order to press each item listed in the array. tbItems = JavaWindow("SwingSet").JavaToolBar("SwingSet2$ToggleButtonToolBar").GetContent() itemArray = Split(tbItems, ";") i = 1 For j = LBound(itemArray) To UBound(itemArray) JavaWindow("SwingSet").JavaToolBar("SwingSet2$ToggleButtonToolBar").Press (i) i = i + 1 Next
'The following example uses GetContenet method to get all ToolBar buttons names. 'Then Comparing values and Reporting result. 'Getting JavaToolBar Content. AllNamesInStringByGetContent = JavaWindow("ToolBarDemo").JavaToolBar("Toolbar").GetContent ExpectedNames = "Name1; Name2; Name3; Name4" 'Compares the ExpectedNames string with the result of GelContent, reporting results. If ExpectedNames = AllNamesInStringByGetContent Then Reporter.ReportEvent micPass, "ToolBar content.", "All Buttons Names verification." Else Reporter.ReportEvent micFail, "ToolBar content.", "All Buttons Names verification." End If
GetItem Method
Description
Returns the name of the toolbar button specified by its index.
Syntax
object.GetItem (Item)
Arguments
Parameter | Description |
---|---|
Item |
Required. A Variant. Numeric index of the button (without quotes or in the format "#N"). Index values begin with 1. |
Return Type
A String value.
Example
'The following example uses the GetItem method to check whether the name of a button at a 'particular location matches the button name that is expected for that position. result = False actualName = JavaWindow("SwingSet").JavaToolBar("SwingSet2$ToggleButtonToolBar").GetItem(itemIndex) If actualName = expectedName Then result = TrueEndIf
GetItemProperty Method
Description
Returns the current value of a property for a toolbar button.
Syntax
object.GetItemProperty (Item, Property)
Arguments
Parameter | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Item |
Required. A Variant. Label of the toolbar button in the toolbar or its numeric index (without quotes or in the format "#N"). Index values begin with 1. | ||||||||||
Property |
Required. A String value. Property to retrieve from the toolbar button. The following properties are supported:
|
Return Type
A String value.
Example
'The following example uses the GetSelection method to store the list of selected toolbar 'buttons in an array. It then loops through the items in the array and, using the 'GetItemProperty method, retrieves the corresponding index for each selected item. Dim indexArray() selString = JavaWindow("SwingSet").JavaToolBar("SwingSet2$ToggleButtonToolBar").GetSelection() selArray = Split(selString, ";") i = 0 For j = LBound(selArray) To UBound(selArray) ReDim Preserve indexArray(k) indexArray(i) = JavaWindow("SwingSet").JavaToolBar("SwingSet2$ToggleButtonToolBar").GetItemProperty(selArray(j), "index") i = i + 1 Next
'The following example uses the GetItemProperty method to verify that a Toolbar item is Enabled. 'If it Enabled a button is pressed. If not the status is reported. 'Gets the state of item #1 (enabled or not) JBState = JavaWindow("ToolBarDemo").JavaToolBar("Toolbar").GetItemProperty("#1", "enabled") 'If the item is enabled, presses the button If JBState Then JavaWindow("ToolBarDemo").JavaButton("Button").Click Else 'If Not Reporter.ReportEvent micWarning, "Button Press", "ToolBarItem not Enabled. Button Not Pressed." 'Reports that button is not pressed. End If
GetItemsCount Method
Description
Returns the number of buttons in the toolbar.
Syntax
object.GetItemsCount
Return Type
A long integer value.
Example
'The following example counts and then iterates through all the buttons in a toolbar 'to press each one. tbItems = JavaWindow("SwingSet").JavaToolBar("SwingSet2$ToggleButtonToolBar").GetItemsCount() For i = 1 To tbItems JavaWindow("SwingSet").JavaToolBar("SwingSet2$ToggleButtonToolBar").Press (i) Next
'The following example adds a new item to the JavaToolbar. It verifies the addition 'using the GetItemsCount method before the addition and after. 'Gets the number of items prior to the addition, keeping the result in the ItemsCount variable. Count ItemsCount = JavaWindow("ToolBarDemo").JavaToolBar("Toolbar").GetItemsCount 'Adds the new Item JavaWindow("ToolBarDemo").JavaEdit("NewItemName").Set "NewItem" JavaWindow("ToolBarDemo").JavaButton("InsertNewItem").Click 'Gets the new number of items. NewItemsCount = JavaWindow("ToolBarDemo").JavaToolBar("Toolbar").GetItemsCount 'Compares the number of items before and after the addition and reports the results. If NewItemsCount = ItemsCount + 1 Then Reporter.ReportEvent micPass, "Adding New Item", "Item Added" Else Reporter.ReportEvent micFail, "Adding New Item", "Item not Added" End If
GetSelection Method
Description
Returns a list of all the buttons in a toolbar that are pressed or checked.
Syntax
object.GetSelection
Return Type
All of the selected items in the toolbar separated by a semicolon (;).
For JavaFX applications, an empty string is returned as you cannot select items in a JavaFX toolbar object.
Example
'The following example presses all Toolbar items (One by One) and verifies that the button just 'pressed is selected. Only one button can be selected at a time. 'Gets the number of items. ICount = JavaWindow("ToolBarDemo").JavaToolBar("Toolbar").GetItemsCount For i = 1 To ICount 'Presses on the i-th item JavaWindow("ToolBarDemo").JavaToolBar("Toolbar").Press ("#" & i) 'Gets the string of all names of the selected items. 'In this case, it just the currently selected item SelectedItemIs = JavaWindow("ToolBarDemo").JavaToolBar("Toolbar").GetSelection 'Gets the name of the pressed item. ItemName = JavaWindow("ToolBarDemo").JavaToolBar("Toolbar").GetItemProperty("#" & i, "name") 'Compares the names and reports the results. If SelectedItemIs = ItemName Then Reporter.ReportEvent micPass, "Pressing on Button " & "#" & i, "Button Pressed" Else Reporter.ReportEvent micFail, "Pressing on Button " & "#" & i, "Button Not Pressed" End If Next
'The following example uses the GetSelection method to store the list of selected toolbar 'buttons in an array. It then loops through the items in the array and, using the 'GetItemProperty method, retrieves the corresponding index for each selected item. Dim indexArray() selString = JavaWindow("SwingSet").JavaToolBar("SwingSet2$ToggleButtonToolBar").GetSelection() selArray = Split(selString, ";") i = 0 For j = LBound(selArray) To UBound(selArray) ReDim Preserve indexArray(k) indexArray(i) = JavaWindow("SwingSet").JavaToolBar("SwingSet2$ToggleButtonToolBar").GetItemProperty(selArray(j), "index") i = i + 1 Next
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
Parameter | Description |
---|---|
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
'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
'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
'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!")
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
Parameter | Description |
---|---|
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
'##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"
Press Method
Description
Clicks the specified toolbar button.
Syntax
object.Press (Item)
Arguments
Parameter | Description |
---|---|
Item |
Required. A Variant. The toolbar button to press. The button label (with quotes) or numeric index (without quotes or in the format "#N") can denote the button. The name reflects the button's attached text (tooltip). The index of the first button in the toolbar is 1. |
Return Type
None.
IMPORTANT
When recording operations on toolbar buttons, UFT One records the button label value for the Item argument if the label has a value and that value is unique in the toolbar. Otherwise UFT One records the button index.
This method is not supported for JavaFX toolbar controls. Instead, you should use a .Click method on the child objects contained in the toolbar.
Example
'The following example uses the Press method to press the "Help" toolbar button. Browser("Developer Server").Page("Developer Server").JavaApplet("Main").JavaToolBar("ToolBar").Press "Help"
'The following example uses the Press method to press the toolbar button with the index 22. Browser("Developer Server").Page("Developer Server").JavaApplet("Main").JavaToolBar("ToolBar").Press 22
'The following example presses all Toolbar items (One by One) and verifies that the button just 'pressed is selected. Only one button can be selected at a time. 'Gets the number of items. ICount = JavaWindow("ToolBarDemo").JavaToolBar("Toolbar").GetItemsCount For i = 1 To ICount 'Presses on the i-th item JavaWindow("ToolBarDemo").JavaToolBar("Toolbar").Press ("#" & i) 'Gets the string of all names of the selected items. 'In this case, it just the currently selected item SelectedItemIs = JavaWindow("ToolBarDemo").JavaToolBar("Toolbar").GetSelection 'Gets the name of the pressed item. ItemName = JavaWindow("ToolBarDemo").JavaToolBar("Toolbar").GetItemProperty("#" & i, "name") 'Compares the names and reports the results. If SelectedItemIs = ItemName Then Reporter.ReportEvent micPass, "Pressing on Button " & "#" & i, "Button Pressed" Else Reporter.ReportEvent micFail, "Pressing on Button " & "#" & i, "Button Not Pressed" End If Next
'The following example counts and then iterates through all the buttons in a toolbar 'to press each one. tbItems = JavaWindow("SwingSet").JavaToolBar("SwingSet2$ToggleButtonToolBar").GetItemsCount() For i = 1 To tbItems JavaWindow("SwingSet").JavaToolBar("SwingSet2$ToggleButtonToolBar").Press (i) Next
PressKey Method
Description
Presses the specified key and modifier in the object.
Syntax
object.PressKey (Key, [Modifier])
Arguments
Parameter | Description |
---|---|
Key |
Required. A String value. 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. micLeft. Presses the left arrow key. micRight. Presses the right arrow key. micDwn. Presses the down arrow key. micUp. Presses the up arrow key. micTab. Presses the TAB key. micReturn. Presses the RETURN or ENTER key. micBack. Presses the BACK key. micDel. Presses the DELETE key. micHome. Presses the HOME key. micEnd. Presses the END key. micEsc. Presses the ESC key. micPause. Presses the PAUSE key. micPrintScr. Presses the PRINT SCREEN key; supported for JavaFX only. micIns. Presses the INSERT 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 One records the PressKey method when one or more hot keys (such as F-keys, Alt, and Ctrl) 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
'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
ShowDropdown Method
Description
Opens the dropdown menu associated with the specified toolbar button by clicking the arrow part of the button.
Syntax
object.ShowDropdown (Item)
Arguments
Parameter | Description |
---|---|
Item |
Required. A Variant. The toolbar button for which you want to show the drop-down item. The button label (with quotes) or numeric index (without quotes or in the format "#N") can denote the button. The index of the first button in the toolbar is numbered 1. |
Return Type
None
IMPORTANT
This method is not supported for toolbar objects in JavaFX applications. Instead, you should use a method from the combo box child item contained in the toolbar.
Example
'The following example selects the "Project" item from the context menu of an 'Eclipse drop-down toolbar button. JavaWindow("Eclipse").JavaToolBar("ToolBar").ShowDropdown "#1" JavaWindow("Eclipse").WinMenu("ContextMenu").Select "Project..."
Type Method
Description
Types the specified text in the object.
Syntax
object.Type (Text)
Arguments
Parameter | Description |
---|---|
Text |
Required. A String value. For additional supported keyboard presses, see PressKey method. |
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 UFT One 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
'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"
See also: