public class AbstractTestObject extends Object
Modifier | Constructor and Description |
---|---|
protected |
AbstractTestObject(JtfObjectHandle handle,
Desktop desktop)
Creates a test object with a
JtfObjectHandle . |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Checks if this test object is the same as the passed one.
|
boolean |
exists()
Checks if the object still exists in the test application.
|
<T extends TestObject> |
find(String locator)
Finds an object specified by an XPath locator or an object map identifier.
|
<T extends TestObject> |
find(String locator,
FindOptions options)
Finds an object specified by an XPath locator or an object map identifier.
|
<T extends TestObject> |
findAll(String locator)
Finds all objects specified by an XPath locator or an object map identifier.
|
<T extends TestObject> |
findAll(String locator,
FindOptions options)
Finds all objects specified by an XPath locator or an object map identifier.
|
protected String |
getCustomTypeName()
Deprecated.
Since Silk Test 2011, this method is not used anymore. Overriding it does not have any effect.
|
Desktop |
getDesktop()
Returns the desktop for this object.
|
JtfObjectHandle |
getHandle()
Returns a handle that the Open Agent internally uses to identify that object.
|
String |
getLocator()
Returns the XPath locator or object map id that was used to find this object.
|
Object |
getProperty(String propertyName)
Gets the value of the specified property.
|
protected String |
getTypeName()
Deprecated.
Since Silk Test 2011, this method is not used anymore. It always returns an empty string.
|
int |
hashCode() |
void |
imageClick(String imageAsset)
Clicks in the middle of the specified image.
|
void |
imageClick(String imageAsset,
Point position)
Clicks on a specific position within an image.
|
void |
imageClick(String imageAsset,
Point position,
int occurrence)
Clicks on a specific occurrence of an image.
|
void |
imageClick(String imageAsset,
Point position,
int occurrence,
ClickType clickType)
Executes a specific mouse action on an image.
|
void |
imageClick(String imageAsset,
Point position,
int occurrence,
ClickType clickType,
ModifierKey modifiers)
Clicks on an image while pressing the specified key modifiers.
|
void |
imageClick(String imageAsset,
Point position,
int occurrence,
ClickType clickType,
ModifierKey modifiers,
int timeout)
Clicks on an image while pressing the specified key modifiers.
|
void |
imageClickFile(String imageFile)
Clicks in the middle of the specified image.
|
void |
imageClickFile(String imageFile,
Point position)
Clicks on a specific position within an image.
|
void |
imageClickFile(String imageFile,
Point position,
int occurrence)
Clicks on a specific occurrence of an image.
|
void |
imageClickFile(String imageFile,
Point position,
int occurrence,
ClickType clickType)
Executes a specific mouse action on an image.
|
void |
imageClickFile(String imageFile,
Point position,
int occurrence,
ClickType clickType,
ModifierKey modifiers)
Clicks on an image while pressing the specified key modifiers.
|
void |
imageClickFile(String imageFile,
Point position,
int occurrence,
ClickType clickType,
ModifierKey modifiers,
int timeout)
Clicks on an image while pressing the specified key modifiers.
|
boolean |
imageExists(String imageAsset)
Returns whether the specified image exists.
|
boolean |
imageExists(String imageAsset,
int occurrence)
Returns whether the given occurrence of an image exists.
|
boolean |
imageExists(String imageAsset,
int occurrence,
Rect searchRectangle)
Returns whether an image exists in the specified area within the object's rectangle.
|
boolean |
imageExistsFile(String imageFile)
Returns whether the specified image exists.
|
boolean |
imageExistsFile(String imageFile,
int occurrence)
Returns whether the given occurrence of an image exists.
|
boolean |
imageExistsFile(String imageFile,
int occurrence,
Rect searchRectangle)
Returns whether an image exists in the specified area within the object's rectangle.
|
Rect |
imageRectangle(String imageAsset)
Returns the object-relative rectangle of the specified image.
|
Rect |
imageRectangle(String imageAsset,
int occurrence)
Returns the object-relative rectangle of the specified occurrence of an image.
|
Rect |
imageRectangle(String imageAsset,
int occurrence,
Rect searchRectangle)
Searches for an image within the specified area and returns the object-relative rectangle of the found image.
|
Rect |
imageRectangleFile(String imageFile)
Returns the object-relative rectangle of the specified image.
|
Rect |
imageRectangleFile(String imageFile,
int occurrence)
Returns the object-relative rectangle of the specified occurrence of an image.
|
Rect |
imageRectangleFile(String imageFile,
int occurrence,
Rect searchRectangle)
Searches for an image within the specified area and returns the object-relative rectangle of the found image.
|
Object |
invoke(String methodName,
Object... parameters)
Invokes a method on the test object.
|
protected void |
preventFinalLocator() |
void |
setProperty(String propertyName,
Object value)
Sets the value of the specified property.
|
String |
toString()
Returns a string that contains the class name and the test object's attributes.
|
protected AbstractTestObject(JtfObjectHandle handle, Desktop desktop)
JtfObjectHandle
.handle
- the handle that identifies the object.desktop
- the desktop on which this object lives. Should only be null
if called from the
Desktop
.
protected void preventFinalLocator()
@Deprecated protected final String getTypeName()
@Deprecated protected String getCustomTypeName()
public final boolean exists()
true
if the object still exists and false
otherwise.
public final Object invoke(String methodName, Object... parameters)
Invokes a method on the test object.
The following methods can be called:
Example 1: For an object of the Silk Test type WPFListBox, all methods can be called that MSDN defines for
the type System.Windows.Controls.ListBox
.
Example 2: For an object of the Silk Test type DataGrid, you can call all methods that MSDN defines for the type System.Windows.Forms.DataGrid
.
Example 3: To call the static .NET method String.Compare(String s1, String s2)
inside the application under test, use the following code:
mainWindow.invoke("System.String.Compare", "string1", "string2");
mainWindow
only identifies the application inside which the method is called and can be replaced by any other object in the application.
The set of supported parameter types depends on the tested technology:
Both primitive types (for example int
) and object types (for example
java.lang.Integer
) are supported. Primitive types are widened if necessary,
allowing, for example, to pass an int
where a long
is expected.
Such a parameter must be passed as string. The string must match the name of an enum value.
Example:
If the method expects a parameter of the enum type ClientInfoStatus
you can use the following string values: "REASON_UNKNOWN", "REASON_UNKNOWN_PROPERTY",
"REASON_VALUE_INVALID", or "REASON_VALUE_TRUNCATED".
Allows calling methods with list, array or var-arg parameters. Conversion to an array type is done automatically, provided the elements of the list are assignable to the target array type.
Such a parameter can be passed as TestObject
.
Such a parameter can be passed as TestObject
.
Such a parameter must be passed as string. The string must match the name of an enum value.
Example:
If the method expects a parameter of the .NET enum type System.Windows.Visiblity
you can use the following string values: "Visible", "Hidden", or "Collapsed".
Such a parameter must be passed as list. The elements in the list must match one constructor for the .NET object in the test application.
Example:
If the method expects an parameter of the .NET type System.Windows.Vector
you can pass a list with two integers like this: Arrays.asList(1, 2)
. This works because the
System.Windows.Vector
type has a constructor with two integer arguments.
Such a parameter can be passed as TestObject
.
methodName
- The method name, e.g. "Select".parameters
- The method parameters. If the function does not require any parameters, you can omit them.null
for methods with the return type
void
.InvalidObjectHandleException
- if the object's handle is invalid. This happens if the object in the
test application was destroyed. Therefore it must be located again, e.g: with
find(String)
.UnsupportedMethodException
- if the given method name is not supported by either the Silk Test class or
the actual GUI element.
public final Object getProperty(String propertyName)
propertyName
- the case-sensitive name of the property.public final void setProperty(String propertyName, Object value)
propertyName
- the case-sensitive name of the property.value
- the new value for the property.
public final JtfObjectHandle getHandle()
INativeWindow.getNativeHandle()
method.public String getLocator()
public Desktop getDesktop()
public final <T extends TestObject> T find(String locator)
PushButton okButton = myObject.find("//PushButton[@caption='ok']"); // xPath locator
PushButton okButton = myObject.find("ok"); // object map entry
myObject.<PushButton>find("//PushButton[@caption='ok']").select(); // xPath locator
myObject.<PushButton>find("ok").select(); // object map entry
T
- The type of the object. Must extend TestObject.locator
- The XPath locator or object map identifier. Defines which object to find.InvalidObjectHandleException
- if the object's handle is invalid. This happens if the object in the
test application was destroyed. Therefore it must be located again, e.g: with
find(String)
.
public final <T extends TestObject> T find(String locator, FindOptions options)
FindOptions.throwObjectNotFoundException()
is
false
, the value null
is returned.
Otherwise an ObjectNotFoundException is thrown.
Examples:
FindOptions options = new FindOptions(false, 5000);
PushButton okButton = myObject.find("//PushButton[@caption='ok']", options); // xPath locator
PushButton okButton = myObject.find("ok", options); // object map entry
myObject.<PushButton>find("//PushButton[@caption='ok']", options).select(); // xPath locator
myObject.<PushButton>find("ok", options).select(); // object map entry
T
- The type of the object. Must extend TestObject.locator
- The XPath locator or object map identifier. Defines which object to find.options
- Specifies options for the find operation. Can be used to override the default timeout or to specify
that null
should be returned if no object is found instead of throwing an exception.InvalidObjectHandleException
- if the object's handle is invalid. This happens if the object in the
test application was destroyed. Therefore it must be located again, e.g: with
find(String)
.InvalidObjectHandleException
- if the object's handle is invalid. This happens if the object in the
test application was destroyed. Therefore it must be located again, e.g: with
find(String)
.
public final <T extends TestObject> List<T> findAll(String locator)
List<DomLink> allLinks = browserPage.findAll("//DomLink"); // xPath locator
List<PushButton> okButtons = myObject.findAll("ok"); // object map entry
T
- The type of the object. Must extend TestObject.locator
- The XPath locator or object map identifier. Defines which objects to find.InvalidObjectHandleException
- if the object's handle is invalid. This happens if the object in the
test application was destroyed. Therefore it must be located again, e.g: with
find(String)
.
public final <T extends TestObject> List<T> findAll(String locator, FindOptions options)
List<DomLink> allLinks = browserPage.findAll("//DomLink", new FindOptions(30*1000)); // xPath locator
List<PushButton> okButtons = myObject.findAll("ok", new FindOptions(30*1000)); // object map entry
T
- The type of the object. Must extend TestObject.locator
- The XPath locator or object map identifier. Defines which objects to find.options
- Specifies options for the find operation. Can be used to override the default timeout or to specify
that null
should be returned if no object is found instead of throwing an exception.InvalidObjectHandleException
- if the object's handle is invalid. This happens if the object in the
test application was destroyed. Therefore it must be located again, e.g: with
find(String)
.
public boolean imageExists(String imageAsset)
imageAsset
- a .imageasset file. The file is searched in the root of caller's classloader.public boolean imageExists(String imageAsset, int occurrence)
imageAsset
- a .imageasset file. The file is searched in the root of caller's classloader.occurrence
- for which occurrence of the image the existence should be checked, if there are multiple results. The first occurrence is 1.public boolean imageExists(String imageAsset, int occurrence, Rect searchRectangle)
imageAsset
- a .imageasset file. The file is searched in the root of caller's classloader.occurrence
- for which occurrence of the image 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 imagepublic boolean imageExistsFile(String imageFile)
imageFile
- a .bmp or .png file. This path can be either absolute or relative to
the working directory during playback.public boolean imageExistsFile(String imageFile, int occurrence)
imageFile
- a .bmp or .png file. This path can be either absolute or relative to
the working directory during playback.occurrence
- for which occurrence of the image the existence should be checked, if there are multiple results. The first occurrence is 1.public boolean imageExistsFile(String imageFile, int occurrence, Rect searchRectangle)
imageFile
- a .bmp or .png file. This path can be either absolute or relative to
the working directory during playback.occurrence
- for which occurrence of the image 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 imagepublic Rect imageRectangle(String imageAsset)
imageAsset
- a .imageasset file. The file is searched in the root of caller's classloader.public Rect imageRectangle(String imageAsset, int occurrence)
imageAsset
- a .imageasset file. The file is searched in the root of caller's classloader.occurrence
- for which occurrence of the image the existence should be checked, if there are multiple results. The first occurrence is 1.public Rect imageRectangle(String imageAsset, int occurrence, Rect searchRectangle)
imageAsset
- a .imageasset file. The file is searched in the root of caller's classloader.occurrence
- for which occurrence of the image 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 imagepublic Rect imageRectangleFile(String imageFile)
imageFile
- a .bmp or .png file. This path can be either absolute or relative to
the working directory during playback.public Rect imageRectangleFile(String imageFile, int occurrence)
imageFile
- a .bmp or .png file. This path can be either absolute or relative to
the working directory during playback.occurrence
- for which occurrence of the image the existence should be checked, if there are multiple results. The first occurrence is 1.public Rect imageRectangleFile(String imageFile, int occurrence, Rect searchRectangle)
imageFile
- a .bmp or .png file. This path can be either absolute or relative to
the working directory during playback.occurrence
- for which occurrence of the image 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 imagepublic void imageClick(String imageAsset)
Example
To search for an image that is defined in the image asset myImage
and to click in the center of the found image, you can use the following code:
control.imageClick("myImage");
imageAsset
- a .imageasset file. The file is searched in the root of caller's classloader.ImageNotFoundException
- if the image was not found in the application under test
public void imageClick(String imageAsset, Point position)
Example
To search for an image that is defined in the image asset myImage
and to click on specific position inside the found image, you can use the following code:
control.imageClick("myImage", new Point(10, 20));
imageAsset
- a .imageasset file. The file is searched in the root of caller's classloader.position
- the coordinates at which to click. The coordinates are relative to the upper-left corner of the
image. For clicking the middle of the image use 'ClickPosition.Center'.ImageNotFoundException
- if the image was not found in the application under test
public void imageClick(String imageAsset, Point position, int occurrence)
Example
To search for an image that is defined in the image asset myImage
and to click in the center of the second occurrence of the found image, you can use the following code:
control.imageClick("myImage", ClickPosition.Center, 2);
imageAsset
- a .imageasset file. The file is searched in the root of caller's classloader.position
- the coordinates at which to click. The coordinates are relative to the upper-left corner of the
image. For clicking the middle of the image use 'ClickPosition.Center'.occurrence
- which occurrence of the image should be clicked, if there are multiple occurrences. The first
occurrence is 1.ImageNotFoundException
- if the image was not found in the application under test
public void imageClick(String imageAsset, Point position, int occurrence, ClickType clickType)
Example
To search for an image that is defined in the image asset myImage
and to righ-click on the found image, you can use the following code:
control.imageClick("myImage", ClickPosition.Center, 1, ClickType.RIGHT);The press the left mouse button, you can use the following code:
control.imageClick("myImage", ClickPosition.Center, 1, ClickType.PRESS);
imageAsset
- a .imageasset file. The file is searched in the root of caller's classloader.position
- the coordinates at which to click. The coordinates are relative to the upper-left corner of the
image. For clicking the middle of the image use 'ClickPosition.Center'.occurrence
- which occurrence of the image should be clicked, if there are multiple occurrences. The first
occurrence is 1.clickType
- the desired mouse action.ImageNotFoundException
- if the image was not found in the application under test
public void imageClick(String imageAsset, Point position, int occurrence, ClickType clickType, ModifierKey modifiers)
Example
To search for an image that is defined in the image asset myImage
and to click on the found image while pressing the Ctrl key, you can use the following code:
control.imageClick("myImage", ClickPosition.Center, 1, ClickType.LEFT, ModifierKey.Ctrl);
imageAsset
- a .imageasset file. The file is searched in the root of caller's classloader.position
- the coordinates at which to click. The coordinates are relative to the upper-left corner of the
image. For clicking the middle of the image use 'ClickPosition.Center'.occurrence
- which occurrence of the image should be clicked, if there are multiple occurrences. The first
occurrence is 1.clickType
- the desired mouse action.modifiers
- The modifier keys (Alt, Shift, Ctrl) to press while clickingImageNotFoundException
- if the image was not found in the application under test
public void imageClick(String imageAsset, Point position, int occurrence, ClickType clickType, ModifierKey modifiers, int timeout)
imageFile
- a .bmp or .png file. This path can be either absolute or relative to the
working directory during playback.position
- the coordinates at which to click. The coordinates are relative to the upper-left corner of the
image. For clicking the middle of the image use 'ClickPosition.Center'.occurrence
- which occurrence of the image should be clicked, if there are multiple occurrences. The first
occurrence is 1.clickType
- the desired mouse action.modifiers
- The modifier keys (Alt, Shift, Ctrl) to press while clickingtimeout
- Maximum time (in ms) to wait for the image to appearImageNotFoundException
- if the image was not found in the application under test
public void imageClickFile(String imageFile)
imageFile
- a .bmp or .png file. This path can be either absolute or relative to the
working directory during playback.ImageNotFoundException
- if the image was not found in the application under test
public void imageClickFile(String imageFile, Point position)
imageFile
- a .bmp or .png file. This path can be either absolute or relative to the
working directory during playback.position
- the coordinates at which to click. The coordinates are relative to the upper-left corner of the
image. For clicking the middle of the image use 'ClickPosition.Center'.ImageNotFoundException
- if the image was not found in the application under test
public void imageClickFile(String imageFile, Point position, int occurrence)
imageFile
- a .bmp or .png file. This path can be either absolute or relative to the
working directory during playback.position
- the coordinates at which to click. The coordinates are relative to the upper-left corner of the
image. For clicking the middle of the image use 'ClickPosition.Center'.occurrence
- which occurrence of the image should be clicked, if there are multiple occurrences. The first
occurrence is 1.ImageNotFoundException
- if the image was not found in the application under test
public void imageClickFile(String imageFile, Point position, int occurrence, ClickType clickType)
imageFile
- a .bmp or .png file. This path can be either absolute or relative to the
working directory during playback.position
- the coordinates at which to click. The coordinates are relative to the upper-left corner of the
image. For clicking the middle of the image use 'ClickPosition.Center'.occurrence
- which occurrence of the image should be clicked, if there are multiple occurrences. The first
occurrence is 1.clickType
- the desired mouse action.ImageNotFoundException
- if the image was not found in the application under test
public void imageClickFile(String imageFile, Point position, int occurrence, ClickType clickType, ModifierKey modifiers)
imageFile
- a .bmp or .png file. This path can be either absolute or relative to the
working directory during playback.position
- the coordinates at which to click. The coordinates are relative to the upper-left corner of the
image. For clicking the middle of the image use 'ClickPosition.Center'.occurrence
- which occurrence of the image should be clicked, if there are multiple occurrences. The first
occurrence is 1.clickType
- the desired mouse action.modifiers
- The modifier keys (Alt, Shift, Ctrl) to press while clickingImageNotFoundException
- if the image was not found in the application under test
public void imageClickFile(String imageFile, Point position, int occurrence, ClickType clickType, ModifierKey modifiers, int timeout)
Example
To search for an image that is defined in the image asset myImage
and to click on the found image while pressing the Ctrl key, you can use the following code:
control.imageClick("myImage", ClickPosition.Center, 1, ClickType.LEFT, ModifierKey.Ctrl);
imageAsset
- a .imageasset file. The file is searched in the root of caller's classloader.position
- the coordinates at which to click. The coordinates are relative to the upper-left corner of the
image. For clicking the middle of the image use 'ClickPosition.Center'.occurrence
- which occurrence of the image should be clicked, if there are multiple occurrences. The first
occurrence is 1.clickType
- the desired mouse action.modifiers
- The modifier keys (Alt, Shift, Ctrl) to press while clickingtimeout
- Maximum time (in ms) to wait for the image to appearImageNotFoundException
- if the image was not found in the application under test
public boolean equals(Object obj)
public String toString()
Copyright 2009-2012 Micro Focus. All Rights Reserved.