public class AbstractTestObject extends Object
Modifier | Constructor and Description |
---|---|
protected |
AbstractTestObject(JtfObjectHandle handle,
Desktop desktop)
使用
JtfObjectHandle 创建一个测试对象。 |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
检查此测试对象与传递的对象是否相同。
|
boolean |
exists()
检查该对象是否仍在测试应用程序中。
|
<T extends TestObject> |
find(String locator)
查找由 XPath 定位器或对象映射标识符指定的对象。
|
<T extends TestObject> |
find(String locator,
FindOptions options)
查找由 XPath 定位器或对象映射标识符指定的对象。
|
<T extends TestObject> |
findAll(String locator)
查找由 XPath 定位器或对象映射标识符指定的所有对象。
|
<T extends TestObject> |
findAll(String locator,
FindOptions options)
查找由 XPath 定位器或对象映射标识符指定的所有对象。
|
protected String |
getCustomTypeName()
Deprecated.
此方法自 Silk Test 2011 之后不再使用,重写此方法无任何效果。
|
Desktop |
getDesktop()
返回此对象的桌面。
|
JtfObjectHandle |
getHandle()
返回打开代理内部使用的用以识别该对象的句柄。
|
String |
getLocator()
返回用来查找此对象的 XPath 定位器或对象映射 id。
|
Object |
getProperty(String propertyName)
获取指定属性的值。
|
protected String |
getTypeName()
Deprecated.
此方法自 Silk Test 2011 之后不再使用,始终返回一个空字符串。
|
int |
hashCode() |
void |
imageClick(String imageAsset)
点击指定图像的中间。
|
void |
imageClick(String imageAsset,
Point position)
点击图像内的某一特定位置。
|
void |
imageClick(String imageAsset,
Point position,
int occurrence)
点击图像的某一特定事件。
|
void |
imageClick(String imageAsset,
Point position,
int occurrence,
ClickType clickType)
在图像上执行某一特定鼠标操作。
|
void |
imageClick(String imageAsset,
Point position,
int occurrence,
ClickType clickType,
ModifierKey modifiers)
按住指定组合键的同时,点击图像。
|
void |
imageClick(String imageAsset,
Point position,
int occurrence,
ClickType clickType,
ModifierKey modifiers,
int timeout)
按住指定组合键的同时,点击图像。
|
void |
imageClickFile(String imageFile)
点击指定图像的中间。
|
void |
imageClickFile(String imageFile,
Point position)
点击图像内的某一特定位置。
|
void |
imageClickFile(String imageFile,
Point position,
int occurrence)
点击图像的特定事件。
|
void |
imageClickFile(String imageFile,
Point position,
int occurrence,
ClickType clickType)
在图像上执行某一特定鼠标操作。
|
void |
imageClickFile(String imageFile,
Point position,
int occurrence,
ClickType clickType,
ModifierKey modifiers)
按住指定的组合键的同时,点击图像。
|
void |
imageClickFile(String imageFile,
Point position,
int occurrence,
ClickType clickType,
ModifierKey modifiers,
int timeout)
按住指定的组合键的同时,点击图像。
|
boolean |
imageExists(String imageAsset) |
boolean |
imageExists(String imageAsset,
int occurrence) |
boolean |
imageExists(String imageAsset,
int occurrence,
Rect searchRectangle) |
boolean |
imageExistsFile(String imageFile) |
boolean |
imageExistsFile(String imageFile,
int occurrence) |
boolean |
imageExistsFile(String imageFile,
int occurrence,
Rect searchRectangle) |
Rect |
imageRectangle(String imageAsset)
返回指定图像的对象相关矩形。
|
Rect |
imageRectangle(String imageAsset,
int occurrence)
返回图像指定事件的对象相对矩形。
|
Rect |
imageRectangle(String imageAsset,
int occurrence,
Rect searchRectangle)
在指定区域内搜索图像,并返回找到的图像的对象相对矩形。
|
Rect |
imageRectangleFile(String imageFile)
返回指定图像的对象相对矩形。
|
Rect |
imageRectangleFile(String imageFile,
int occurrence)
返回图像指定事件的对象相对矩形。
|
Rect |
imageRectangleFile(String imageFile,
int occurrence,
Rect searchRectangle)
在指定区域内搜索图像,并返回找到的图像的对象相对矩形。
|
Object |
invoke(String methodName,
Object... parameters)
调用测试对象的方法。
|
protected void |
preventFinalLocator() |
void |
setProperty(String propertyName,
Object value)
设置指定属性的值。
|
String |
toString()
返回一个包含类名和测试对象属性的字符串。
|
protected AbstractTestObject(JtfObjectHandle handle, Desktop desktop)
JtfObjectHandle
创建一个测试对象。handle
- 识别该对象的句柄。desktop
- 此对象所在的桌面。如果从 Desktop
调用,仅能为 null
。
protected void preventFinalLocator()
@Deprecated protected final String getTypeName()
@Deprecated protected String getCustomTypeName()
public final boolean exists()
true
,否则为 false
。
public final Object invoke(String methodName, Object... parameters)
调用测试对象的方法。
可以调用下列方法:
例 1:对于一个 Silk Test 类型的 WPFListBox 对象,可以调用 MSDN 为 System.Windows.Controls.ListBox
定义的所有方法。
例 2:对于一个 Silk Test 类型的 DataGrid 对象,可以调用 MSDN 为 System.Windows.Forms.DataGrid
定义的所有方法。
例 3:要在被测试应用程序中调用静态 .NET 方法 String.Compare(String s1, String s2)
使用下面的代码:
mainWindow.invoke("System.String.Compare", "string1", "string2");
mainWindow
对象仅识别调用该方法的应用程序,并且可以被应用程序中的任意其他对象代替。
支持的参数类型集合取决于所测试的技术:
支持基元类型(例如 int
)和对象类型(例如
java.lang.Integer
)。基元类型值在需要时可扩充。
例如,允许将一个 int
值传递给 long
类型。
此类参数必须作为字符串传送。字符串必须与一个枚举值的名称匹配。
例如:
如果方法中的一个参数为 ClientInfoStatus
枚举类型,
那么可以使用下列字符串值: "REASON_UNKNOWN"、"REASON_UNKNOWN_PROPERTY"、
"REASON_VALUE_INVALID" 或 "REASON_VALUE_TRUNCATED"。
允许调用带有列表、数组或 var-arg 参数的方法。列表元素能够分配给目标值时,会自动转换为数组类型。
此类参数可以作为 TestObject
传递。
此类参数可以作为 TestObject
传递。
此类参数必须作为字符串传送。字符串必须与一个枚举值的名称匹配。
例如:
如果方法中的一个参数为 .NET System.Windows.Visiblity
枚举类型,
那么可以使用下列字符串值:"Visible"、"Hidden" 或 "Collapsed"。
此类参数必须作为列表传递。 列表中的元素必须与测试应用程序中 .NET 对象的一个构造函数匹配。
例如:
如果方法的一个参数为 .NET System.Windows.Vector
类型,
那么可以传递一个带有两个整数的列表,如:Arrays.asList(1, 2)
。之所以可以这样做,是因为
System.Windows.Vector
类型有一个带有两个整数参数的构造函数。
此类参数可以作为 TestObject
传递。
methodName
- 方法名,例如 "Select"。parameters
- 方法参数。若该函数不要求任何参数,则可忽略。null
,返回类型为
void
。InvalidObjectHandleException
- 如果对象的句柄无效。当测试应用程序中的对象被销毁时,会发生此情况。因此,必须再次查找定位,可以使用
find(String)
。UnsupportedMethodException
- 如果 Silk Test 类或实际中的 GUI 元素均不支持提供的方法名。
public final Object getProperty(String propertyName)
propertyName
- 属性的名称,区分大小写。public final void setProperty(String propertyName, Object value)
propertyName
- 属性的名称,区分大小写。value
- 属性新的值。
public final JtfObjectHandle getHandle()
INativeWindow.getNativeHandle()
方法。public String getLocator()
public Desktop getDesktop()
public final <T extends TestObject> T find(String locator)
PushButton okButton = myObject.find("//PushButton[@caption='ok']"); // xPath 定位器
PushButton okButton = myObject.find("ok"); // 对象映射条目
myObject.<PushButton>find("//PushButton[@caption='ok']").select(); // xPath 定位器
myObject.<PushButton>find("ok").select(); // 对象映射条目
T
- 对象的类型。必须扩展 TestObject。locator
- XPath 定位器或对象映射标识符。定义查找的对象。InvalidObjectHandleException
- 如果对象的句柄无效。当测试应用程序中的对象被销毁时,会发生此情况。因此,必须再次查找定位,可以使用
find(String)
。
public final <T extends TestObject> T find(String locator, FindOptions options)
FindOptions.throwObjectNotFoundException()
的值为 false
,则返回 null
。
否则,抛出 ObjectNotFoundException 异常。
例如:
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
- 对象的类型。必须扩展 TestObject。locator
- XPath 定位器或对象映射标识符。定义查找的对象。options
- 指定查找操作的选项。可用于覆盖默认的超时或指定未找到对象时返回 null
而不是抛出异常。InvalidObjectHandleException
- 如果对象的句柄无效。当测试应用程序中的对象被销毁时,会发生此情况。因此,必须再次查找定位,可以使用
find(String)
。InvalidObjectHandleException
- 如果对象的句柄无效。当测试应用程序中的对象被销毁时,会发生此情况。因此,必须再次查找定位,可以使用
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
- 对象的类型。必须扩展 TestObject。locator
- XPath 定位器或对象映射标识符。定义查找哪些对象。InvalidObjectHandleException
- 如果对象的句柄无效。当测试应用程序中的对象被销毁时,会发生此情况。因此,必须再次查找定位,可以使用
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
- 对象的类型。必须扩展 TestObject。locator
- XPath 定位器或对象映射标识符。定义查找哪些对象。options
- 指定查找操作的选项。可用于覆盖默认的超时或指定未找到对象时返回 null
而不是抛出异常。InvalidObjectHandleException
- 如果对象的句柄无效。当测试应用程序中的对象被销毁时,会发生此情况。因此,必须再次查找定位,可以使用
find(String)
。
public boolean imageExists(String imageAsset)
imageAsset
- public boolean imageExists(String imageAsset, int occurrence)
imageAsset
- occurrence
- public boolean imageExists(String imageAsset, int occurrence, Rect searchRectangle)
imageAsset
- occurrence
- searchRectangle
- public boolean imageExistsFile(String imageFile)
imageFile
- public boolean imageExistsFile(String imageFile, int occurrence)
imageFile
- occurrence
- public boolean imageExistsFile(String imageFile, int occurrence, Rect searchRectangle)
imageFile
- occurrence
- searchRectangle
- public Rect imageRectangle(String imageAsset)
imageAsset
- .imageasset 文件。在调用程序的类加载器根目录中搜索文件。public Rect imageRectangle(String imageAsset, int occurrence)
imageAsset
- .imageasset 文件。在调用程序的类加载器根目录中搜索文件。occurrence
- 存在多个结果时,应检查图像的哪次出现是否存在。第一次出现为 1。public Rect imageRectangle(String imageAsset, int occurrence, Rect searchRectangle)
imageAsset
- .imageasset 文件。在调用程序的类加载器根目录中搜索文件。occurrence
- 存在多个结果时,应检查图像的哪次出现是否存在。第一次出现为 1。searchRectangle
- 在哪个对象相对矩形内搜索图像public Rect imageRectangleFile(String imageFile)
imageFile
- .bmp 或 .png 文件。此路径可以为绝对路径或者重放时工作目录的相对路径。public Rect imageRectangleFile(String imageFile, int occurrence)
imageFile
- .bmp 或 .png 文件。此路径可以为绝对路径或者重放时工作目录的相对路径。occurrence
- 存在多个结果时,应检查图像的哪次出现是否存在。第一次出现为 1。public Rect imageRectangleFile(String imageFile, int occurrence, Rect searchRectangle)
imageFile
- .bmp 或 .png 文件。此路径可以为绝对路径或者重放时工作目录的相对路径。occurrence
- 存在多个结果时,应检查图像的哪次出现是否存在。第一次出现为 1。searchRectangle
- 在哪个对象相对矩形内搜索图像public void imageClick(String imageAsset)
例如
要查找图像资产 myImage
中定义的图像并点击找到的图像的中心位置,可以使用下列代码:
control.imageClick("myImage");
imageAsset
- .imageasset 文件。在调用程序的类加载器根目录中搜索文件。ImageNotFoundException
- 如果在被测试应用程序中找不到图像。
public void imageClick(String imageAsset, Point position)
例如
要查找图像资产 myImage
中定义的图像并点击找到的图像的特定位置,可以使用下列代码:
control.imageClick("myImage", new Point(10, 20));
imageAsset
- .imageasset 文件。在调用程序的类加载器根目录中搜索文件。position
- 要点击位置的坐标值。该坐标为图像左上角的相对值。要点击图像的中间,使用 'ClickPosition.Center'。ImageNotFoundException
- 如果在被测试应用程序中找不到图像。
public void imageClick(String imageAsset, Point position, int occurrence)
例如
要查找图像资产 myImage
中定义的图像,并点击找到的图像的第二个事件的中心位置,可以使用下列代码:
control.imageClick("myImage", ClickPosition.Center, 2);
imageAsset
- .imageasset 文件。在调用程序的类加载器根目录中搜索文件。position
- 要点击位置的坐标值。该坐标为图像左上角的相对值。要点击图像的中间,使用 'ClickPosition.Center'。occurrence
- 存在多个图像的事件时,应检查哪个事件是否存在。第一个事件为 1。ImageNotFoundException
- 如果在被测试应用程序中找不到图像。
public void imageClick(String imageAsset, Point position, int occurrence, ClickType clickType)
例如
要查找图像资产 myImage
中定义的图像,并右键单击找到的图像,可以使用下列代码:
control.imageClick("myImage", ClickPosition.Center, 1, ClickType.RIGHT);要按下鼠标左键,可以使用下列代码:
control.imageClick("myImage", ClickPosition.Center, 1, ClickType.PRESS);
imageAsset
- .imageasset 文件。在调用程序的类加载器根目录中搜索文件。position
- 要点击位置的坐标值。该坐标为图像左上角的相对值。要点击图像的中间,使用 'ClickPosition.Center'。occurrence
- 存在多个图像的事件时,应检查哪个事件是否存在。第一个事件为 1。clickType
- 期望的鼠标操作。ImageNotFoundException
- 如果在被测试应用程序中找不到图像。
public void imageClick(String imageAsset, Point position, int occurrence, ClickType clickType, ModifierKey modifiers)
imageAsset
- .imageasset 文件。在调用程序的类加载器根目录中搜索文件。position
- 要点击位置的坐标值。该坐标为图像左上角的相对值。要点击图像的中间,使用 'ClickPosition.Center'。occurrence
- 存在多个图像的事件时,应检查哪个事件是否存在。第一个事件为 1。clickType
- 期望的鼠标操作。modifiers
- 点击时按的组合键(Alt、Shift、Ctrl)。ImageNotFoundException
- 如果在被测试应用程序中找不到图像。
public void imageClick(String imageAsset, Point position, int occurrence, ClickType clickType, ModifierKey modifiers, int timeout)
imageFile
- .bmp 或 .png 文件。此路径可以为绝对路径或者重放时工作目录的相对路径。position
- 要点击位置的坐标值。该坐标为图像左上角的相对值。要点击图像的中间,使用 'ClickPosition.Center'。occurrence
- 存在多个图像的事件时,应检查哪个事件是否存在。第一个事件为 1。clickType
- 期望的鼠标操作。modifiers
- 点击时按的组合键(Alt、Shift、Ctrl)。timeout
- 等待图像出现的最大时间(以毫秒为单位)ImageNotFoundException
- 如果在被测试应用程序中找不到图像。
public void imageClickFile(String imageFile)
imageFile
- .bmp 或 .png 文件。此路径可以为绝对路径或者重放时工作目录的相对路径。ImageNotFoundException
- 如果在被测试应用程序中找不到图像。
public void imageClickFile(String imageFile, Point position)
imageFile
- .bmp 或 .png 文件。此路径可以为绝对路径或者重放时工作目录的相对路径。position
- 要点击位置的坐标值。该坐标为图像左上角的相对值。要点击图像的中间,使用 'ClickPosition.Center'。ImageNotFoundException
- 如果在被测试应用程序中找不到图像。
public void imageClickFile(String imageFile, Point position, int occurrence)
imageFile
- .bmp 或 .png 文件。此路径可以为绝对路径或者重放时工作目录的相对路径。position
- 要点击位置的坐标值。该坐标为图像左上角的相对值。要点击图像的中间,使用 'ClickPosition.Center'。occurrence
- 存在多个图像的事件时,应检查哪个事件是否存在。第一个事件为 1。ImageNotFoundException
- 如果在被测试应用程序中找不到图像。
public void imageClickFile(String imageFile, Point position, int occurrence, ClickType clickType)
imageFile
- .bmp 或 .png 文件。此路径可以为绝对路径或者重放时工作目录的相对路径。position
- 要点击位置的坐标值。该坐标为图像左上角的相对值。要点击图像的中间,使用 'ClickPosition.Center'。occurrence
- 存在多个图像的事件时,应检查哪个事件是否存在。第一个事件为 1。clickType
- 期望的鼠标操作。ImageNotFoundException
- 如果在被测试应用程序中找不到图像。
public void imageClickFile(String imageFile, Point position, int occurrence, ClickType clickType, ModifierKey modifiers)
例如
要查找图像资产 myImage
中定义的图像,并在按住 Ctrl 键的同时点击找到的图像,可以使用下列代码:
control.imageClick("myImage", ClickPosition.Center, 1, ClickType.LEFT, ModifierKey.Ctrl);
imageFile
- .bmp 或 .png 文件。此路径可以为绝对路径或者重放时工作目录的相对路径。position
- 要点击位置的坐标值。该坐标为图像左上角的相对值。要点击图像的中间,使用 'ClickPosition.Center'。occurrence
- 存在多个图像的事件时,应检查哪个事件是否存在。第一个事件为 1。clickType
- 期望的鼠标操作。modifiers
- 点击时按的组合键(Alt、Shift、Ctrl)。ImageNotFoundException
- 如果在被测试应用程序中找不到图像。
public void imageClickFile(String imageFile, Point position, int occurrence, ClickType clickType, ModifierKey modifiers, int timeout)
例如
要查找图像资产 myImage
中定义的图像,并在按住 Ctrl 键的同时点击找到的图像,可以使用下列代码:
control.imageClick("myImage", ClickPosition.Center, 1, ClickType.LEFT, ModifierKey.Ctrl);
imageAsset
- .imageasset 文件。在调用程序的类加载器根目录中搜索文件。position
- 要点击位置的坐标值。该坐标为图像左上角的相对值。要点击图像的中间,使用 'ClickPosition.Center'。occurrence
- 存在多个图像的事件时,应检查哪个事件是否存在。第一个事件为 1。clickType
- 期望的鼠标操作。modifiers
- 点击时按的组合键(Alt、Shift、Ctrl)。timeout
- 等待图像出现的最大时间(以毫秒为单位)ImageNotFoundException
- 如果在被测试应用程序中找不到图像。
public boolean equals(Object obj)
Copyright 2009-2012 Micro Focus. All Rights Reserved.