public class TestObject extends AbstractTestObject
Modifier | Constructor and Description |
---|---|
protected |
TestObject(JtfObjectHandle handle,
Desktop desktop)
Creates a new TestObject with a JtfObjectHandle.
|
Modifier and Type | Method and Description |
---|---|
String |
captureBitmap(String fileName)
Saves a bitmap image of this object to a file.
|
String |
captureBitmap(String fileName,
Rect region)
Saves a bitmap image of this object to a file.
|
boolean |
exists(String locator)
Checks if any child object matching the locator exists for an object in the application under test.
|
boolean |
exists(String locator,
int timeout)
Checks if any child object matching the locator exists for an object in the application under test.
|
String |
generateLocator()
Returns a locator for this object.
|
List<TestObject> |
getChildren()
Returns the child objects of this object.
|
List<String> |
getDynamicMethodList()
Returns a list of methods (including their signature) that can be dynamically invoked on this TestObject.
|
TestObject |
getParent()
Looks up the parent of this object in the test application.
|
List<String> |
getPropertyList()
Returns a list of property names that can be retrieved for the given object.
|
Rect |
getRect()
Returns the size and position of this object.
|
Rect |
getRect(boolean absoluteCoordinates)
Returns the size and position of this object.
|
String |
getText()
Gets the text of the control.
|
Object |
getValue()
Gets the value of the control, e.g.: text in a text control.
|
void |
highlightObject()
Highlights this object.
|
void |
highlightObject(int timeout)
Highlights this object.
|
void |
highlightObject(int timeout,
Color color)
Highlights this object.
|
Object |
invokeMethods(List<String> names,
List<List<Object>> parameters)
Dynamically invokes a sequence of methods starting at this TestObject.
|
String |
textCapture()
Returns the text in this object's visible area.
|
String |
textCapture(Rect captureRectangle)
Returns the text in this object's visible area.
|
void |
textClick(String text)
Clicks in the center of the specified text.
|
void |
textClick(String text,
int occurrence)
Clicks in the center of the specified text.
|
void |
textClick(String text,
int occurrence,
ClickType clickType)
Clicks in the center of the specified text.
|
void |
textClick(String text,
int occurrence,
ClickType clickType,
ModifierKey modifiers)
Clicks in the center of the specified text.
|
void |
textClick(String text,
int occurrence,
ClickType clickType,
ModifierKey modifiers,
Point position)
Clicks in the center of the specified text.
|
void |
textClick(String text,
int occurrence,
ClickType clickType,
ModifierKey modifiers,
Point position,
boolean exactMatch)
Clicks in the center of the specified text.
|
boolean |
textExists(String text)
Returns whether the specified text exists.
|
boolean |
textExists(String text,
int occurrence)
Returns whether the specified text exists.
|
boolean |
textExists(String text,
int occurrence,
Rect searchRectangle)
Returns whether the specified text exists.
|
boolean |
textExists(String text,
int occurrence,
Rect searchRectangle,
int timeout)
Returns whether the specified text exists.
|
boolean |
textExists(String text,
int occurrence,
Rect searchRectangle,
int timeout,
boolean exactMatch)
Returns whether the specified text exists.
|
Rect |
textRectangle(String text)
Returns the object-relative rectangle of the specified text.
|
Rect |
textRectangle(String text,
int occurrence)
Returns the object-relative rectangle of the specified text.
|
Rect |
textRectangle(String text,
int occurrence,
Rect searchRectangle)
Returns the object-relative rectangle of the specified text.
|
Rect |
textRectangle(String text,
int occurrence,
Rect searchRectangle,
int timeout)
Returns the object-relative rectangle of the specified text.
|
Rect |
textRectangle(String text,
int occurrence,
Rect searchRectangle,
int timeout,
boolean exactMatch)
Returns the object-relative rectangle of the specified text.
|
void |
waitForChildDisappearance(String locator)
Waits until the child object specified by the 'locator' parameter does not exist or until the timeout is reached.
|
void |
waitForChildDisappearance(String locator,
int timeout)
Waits until the child object specified by the 'locator' parameter does not exist or until the timeout is reached.
|
void |
waitForDisappearance()
Waits until the object does not exist or until the timeout is reached.
|
void |
waitForDisappearance(int timeout)
Waits until the object does not exist or until the timeout is reached.
|
void |
waitForObject(String locator)
Waits for an object that matches the specified locator.
|
void |
waitForObject(String locator,
int timeout)
Waits for an object that matches the specified locator.
|
void |
waitForProperty(String propertyName,
Object expectedValue)
Waits until the property specified by the 'propertyName' parameter gets the value specified by the 'expectedValue' parameter or until the timeout is reached.
|
void |
waitForProperty(String propertyName,
Object expectedValue,
int timeout)
Waits until the property specified by the 'propertyName' parameter gets the value specified by the 'expectedValue' parameter or until the timeout is reached.
|
equals, exists, find, find, findAll, findAll, getCustomTypeName, getDesktop, getHandle, getLocator, getProperty, getTypeName, hashCode, imageClick, imageClick, imageClick, imageClick, imageClick, imageClick, imageClickFile, imageClickFile, imageClickFile, imageClickFile, imageClickFile, imageClickFile, imageExists, imageExists, imageExists, imageExistsFile, imageExistsFile, imageExistsFile, imageRectangle, imageRectangle, imageRectangle, imageRectangleFile, imageRectangleFile, imageRectangleFile, invoke, preventFinalLocator, setProperty, toString
protected TestObject(JtfObjectHandle handle, Desktop desktop)
handle
- the handle that identifies the TestObjectdesktop
- the desktop on which this object livespublic String captureBitmap(String fileName)
After capturing the object for the first time the Agent waits the time interval specified with the OPT_BITMAP_MATCH_INTERVAL option, and then recaptures the object, comparing the result against the first capture to ensure that the image is stable.
You set the number of consecutive bitmaps that must match with the OPT_BITMAP_MATCH_COUNT option. If the image is not stable after the time specified with the OPT_BITMAP_MATCH_TIMEOUT option, an BitmapNotStableException is thrown.
fileName
- the absolute or relative file name to save the bitmap to. Append .png to the filename to save the bitmap as a PNG.public String captureBitmap(String fileName, Rect region)
After capturing the object for the first time the Agent waits the time interval specified with the OPT_BITMAP_MATCH_INTERVAL option, and then recaptures the object, comparing the result against the first capture to ensure that the image is stable.
You set the number of consecutive bitmaps that must match with the OPT_BITMAP_MATCH_COUNT option. If the image is not stable after the time specified with the OPT_BITMAP_MATCH_TIMEOUT option, an BitmapNotStableException is thrown.
fileName
- the absolute or relative file name to save the bitmap to. Append .png to the filename to save the bitmap as a PNG.region
- the coordinates for the capture region, relative to this objectpublic boolean exists(String locator)
timeout
parameter is passed the agent retries finding until the given timeout expires. If no timeout is specified and no object is found initially false
is returned immediately.locator
- the XPath locator of the child object. Example:"//PushButton[@caption='ok']"
true
if a child object with the given locator is found and false
otherwise.public boolean exists(String locator, int timeout)
timeout
parameter is passed the agent retries finding until the given timeout expires. If no timeout is specified and no object is found initially false
is returned immediately.locator
- the XPath locator of the child object. Example:"//PushButton[@caption='ok']"
timeout
- the timeout in milliseconds. If the initial find operation does not match anything the agent retries to find an object until the timeout expires.true
if a child object with the given locator is found and false
otherwise.public String generateLocator()
The locator is created in the same way it is created during recording.
public List<TestObject> getChildren()
public List<String> getDynamicMethodList()
public TestObject getParent()
public List<String> getPropertyList()
Sample Usage
List<String> propertyList = testObject.getPropertyList();
public Rect getRect()
public Rect getRect(boolean absoluteCoordinates)
absoluteCoordinates
- if true
global coordinates are returned (relative to the entire screen), otherwise the returned coordinates are relative to the parent window that contains this objectpublic void highlightObject()
public void highlightObject(int timeout)
timeout
- specifies a timeout in milliseconds for highlighting the object. If no timeout is specified the object remains highlighted forever or until a different object is highlighted.public void highlightObject(int timeout, Color color)
timeout
- specifies a timeout in milliseconds for highlighting the object. If no timeout is specified the object remains highlighted forever or until a different object is highlighted.color
- specifies the color to use for highlighting this object. If no color is specified the default color is used.public Object invokeMethods(List<String> names, List<List<Object>> parameters)
Each method call except the last one must have a return object. Each return object becomes the target for calling the next method in the list of method names with the next argument list in the list of parameters until the last method call. If the method names, argument lists, or returned objects do not match, a runtime error is generated.
This method is implemented for WPF, Windows Forms, Silverlight, Java SWT and Java Swing.
names
- a list of method names in the order that they are to be calledparameters
- a list that contains a list of arguments for every method. Trailing empty argument lists may be omitted.public String textCapture()
Capturing text in combo boxes may append the text character "6". This is because the drop-down arrow for a combo box is the Marlett font drop-down arrow text symbol, which is the number "6" for most other fonts.
public String textCapture(Rect captureRectangle)
Capturing text in combo boxes may append the text character "6". This is because the drop-down arrow for a combo box is the Marlett font drop-down arrow text symbol, which is the number "6" for most other fonts.
captureRectangle
- the defined rectangular region where the text will be captured, relative to the window's coordinatespublic void textClick(String text)
text
- the text to be clickedpublic void textClick(String text, int occurrence)
text
- the text to be clickedoccurrence
- which occurrence of the text should be clicked, if there are multiple results. The first occurrence is 1.public void textClick(String text, int occurrence, ClickType clickType)
text
- the text to be clickedoccurrence
- which occurrence of the text should be clicked, if there are multiple results. The first occurrence is 1.clickType
- the desired mouse action. Default: left click.public void textClick(String text, int occurrence, ClickType clickType, ModifierKey modifiers)
text
- the text to be clickedoccurrence
- which occurrence of the text should be clicked, if there are multiple results. The first occurrence is 1.clickType
- the desired mouse action. Default: left click.modifiers
- the modifier keys (Alt, Shift, Ctrl) to press while clicking. Default: Don't use modifier keys.public void textClick(String text, int occurrence, ClickType clickType, ModifierKey modifiers, Point position)
text
- the text to be clickedoccurrence
- which occurrence of the text should be clicked, if there are multiple results. The first occurrence is 1.clickType
- the desired mouse action. Default: left click.modifiers
- the modifier keys (Alt, Shift, Ctrl) to press while clicking. Default: Don't use modifier keys.position
- the coordinates at which to click. The coordinates are relative to the the upper-left corner of the text. If no coordinates are specified the click is performed on the center of the text.public void textClick(String text, int occurrence, ClickType clickType, ModifierKey modifiers, Point position, boolean exactMatch)
text
- the text to be clickedoccurrence
- which occurrence of the text should be clicked, if there are multiple results. The first occurrence is 1.clickType
- the desired mouse action. Default: left click.modifiers
- the modifier keys (Alt, Shift, Ctrl) to press while clicking. Default: Don't use modifier keys.position
- the coordinates at which to click. The coordinates are relative to the the upper-left corner of the text. If no coordinates are specified the click is performed on the center of the text.exactMatch
- if true
the text must completely match the captured text, otherwise a partial match is allowedpublic boolean textExists(String text)
text
- the text to be searched forpublic boolean textExists(String text, int occurrence)
text
- the text to be searched foroccurrence
- for which occurrence of the text the existence should be checked, if there are multiple results. The first occurrence is 1.public boolean textExists(String text, int occurrence, Rect searchRectangle)
text
- the text to be searched foroccurrence
- for which occurrence of the text the existence should be checked, if there are multiple results. The first occurrence is 1.searchRectangle
- the object-relative rectangle in which to search the textpublic boolean textExists(String text, int occurrence, Rect searchRectangle, int timeout)
text
- the text to be searched foroccurrence
- for which occurrence of the text the existence should be checked, if there are multiple results. The first occurrence is 1.searchRectangle
- the object-relative rectangle in which to search the texttimeout
- specifies how long the text should be searched for. If no timeout is specified the text is searched only once.public boolean textExists(String text, int occurrence, Rect searchRectangle, int timeout, boolean exactMatch)
text
- the text to be searched foroccurrence
- for which occurrence of the text the existence should be checked, if there are multiple results. The first occurrence is 1.searchRectangle
- the object-relative rectangle in which to search the texttimeout
- specifies how long the text should be searched for. If no timeout is specified the text is searched only once.exactMatch
- if true
the text must completely match the captured text, otherwise a partial match is allowedpublic Rect textRectangle(String text)
text
- the text to be searched forpublic Rect textRectangle(String text, int occurrence)
text
- the text to be searched foroccurrence
- for which occurrence of the text the rectangle should be returned, if there are multiple results. The first occurrence is 1.public Rect textRectangle(String text, int occurrence, Rect searchRectangle)
text
- the text to be searched foroccurrence
- for which occurrence of the text the rectangle should be returned, if there are multiple results. The first occurrence is 1.searchRectangle
- the object relative rectangle in which to search the textpublic Rect textRectangle(String text, int occurrence, Rect searchRectangle, int timeout)
text
- the text to be searched foroccurrence
- for which occurrence of the text the rectangle should be returned, if there are multiple results. The first occurrence is 1.searchRectangle
- the object relative rectangle in which to search the texttimeout
- specifies how long the text should be searched for. If no timeout is specified the text is searched only once.public Rect textRectangle(String text, int occurrence, Rect searchRectangle, int timeout, boolean exactMatch)
text
- the text to be searched foroccurrence
- for which occurrence of the text the rectangle should be returned, if there are multiple results. The first occurrence is 1.searchRectangle
- the object relative rectangle in which to search the texttimeout
- specifies how long the text should be searched for. If no timeout is specified the text is searched only once.exactMatch
- if true
the text must completely match the captured text, otherwise a partial match is allowedpublic void waitForChildDisappearance(String locator)
locator
- the XPath locator identifying the object that is expected to disappear relative to the object this function is called onpublic void waitForChildDisappearance(String locator, int timeout)
locator
- the XPath locator identifying the object that is expected to disappear relative to the object this function is called ontimeout
- the maximum wait time in milliseconds before the function times outpublic void waitForDisappearance()
public void waitForDisappearance(int timeout)
timeout
- the maximum wait time in milliseconds before the function times outpublic void waitForObject(String locator)
OPT_WAIT_RESOLVE_OBJDEF
. Use WaitForObject if the AUT takes a long time to display a specific object, for example when a transaction is processed before showing any results. By default, an action in the UI does not require a WaitForObject, because of the built-in synchronization. If you receive random timeout errors during normal script execution, consider increasing the default timeout instead of adding WaitForObject statements to your scripts.
Sample UsageThe following example sets a window active, then waits for a button for 30 seconds,
in addition to the timeout used for the
window.setActive(); window.waitForObject("//PushButton[@automationId='MySampleButton']", 30000); window.<PushButton>find("//PushButton[@automationId='MySampleButton']").click();
locator
- the XPath locator. Defines which object to find. Example:"//PushButton[@caption='ok']"
public void waitForObject(String locator, int timeout)
OPT_WAIT_RESOLVE_OBJDEF
. Use WaitForObject if the AUT takes a long time to display a specific object, for example when a transaction is processed before showing any results. By default, an action in the UI does not require a WaitForObject, because of the built-in synchronization. If you receive random timeout errors during normal script execution, consider increasing the default timeout instead of adding WaitForObject statements to your scripts.
Sample UsageThe following example sets a window active, then waits for a button for 30 seconds,
in addition to the timeout used for the
window.setActive(); window.waitForObject("//PushButton[@automationId='MySampleButton']", 30000); window.<PushButton>find("//PushButton[@automationId='MySampleButton']").click();
locator
- the XPath locator. Defines which object to find. Example:"//PushButton[@caption='ok']"
timeout
- the timeout in milliseconds. If the initial find operation does not match anything the agent retries to find an object until the timeout expires.public void waitForProperty(String propertyName, Object expectedValue)
propertyName
- the name of the property to wait forexpectedValue
- the value of the property to wait forpublic void waitForProperty(String propertyName, Object expectedValue, int timeout)
propertyName
- the name of the property to wait forexpectedValue
- the value of the property to wait fortimeout
- the maximum wait time in milliseconds before the function times outpublic String getText()
public Object getValue()
Copyright 2009-2012 Micro Focus. All Rights Reserved.