public class TestObject extends AbstractTestObject
Modifier | Constructor and Description |
---|---|
protected |
TestObject(JtfObjectHandle handle,
Desktop desktop)
使用 JtfObjectHandle 创建新 TestObject。
|
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)
确认与定位器匹配的子级对象是否因测试下的应用程序中的对象而存在。
|
boolean |
exists(String locator,
int timeout)
确认与定位器匹配的子级对象是否因测试下的应用程序中的对象而存在。
|
String |
generateLocator()
返回此对象的定位器。
|
List<TestObject> |
getChildren()
返回此对象的子级对象。
|
List<String> |
getDynamicMethodList()
返回可在此 TestObject 中动态调用的方法列表(包括其签名)。
|
TestObject |
getParent()
在测试应用程序中查找此对象的父级。
|
List<String> |
getPropertyList()
返回可为指定对象检索的属性名称列表。
|
Rect |
getRect()
返回此对象的大小和位置。
|
Rect |
getRect(boolean absoluteCoordinates)
返回此对象的大小和位置。
|
String |
getText()
获取 控件的文本。
|
Object |
getValue()
获取 控件的值,例如文本控件中的文本。
|
void |
highlightObject()
突出显示此对象。
|
void |
highlightObject(int timeout)
突出显示此对象。
|
void |
highlightObject(int timeout,
Color color)
突出显示此对象。
|
Object |
invokeMethods(List<String> names,
List<List<Object>> parameters)
动态调用以此 TestObject 开头的方法序列。
|
String |
textCapture()
返回此对象可见区域上的文本。
|
String |
textCapture(Rect captureRectangle)
返回此对象可见区域上的文本。
|
void |
textClick(String text)
单击指定文本的中间。
|
void |
textClick(String text,
int occurrence)
单击指定文本的中间。
|
void |
textClick(String text,
int occurrence,
ClickType clickType)
单击指定文本的中间。
|
void |
textClick(String text,
int occurrence,
ClickType clickType,
ModifierKey modifiers)
单击指定文本的中间。
|
void |
textClick(String text,
int occurrence,
ClickType clickType,
ModifierKey modifiers,
Point position)
单击指定文本的中间。
|
void |
textClick(String text,
int occurrence,
ClickType clickType,
ModifierKey modifiers,
Point position,
boolean exactMatch)
单击指定文本的中间。
|
boolean |
textExists(String text)
返回指定文本是否存在。
|
boolean |
textExists(String text,
int occurrence)
返回指定文本是否存在。
|
boolean |
textExists(String text,
int occurrence,
Rect searchRectangle)
返回指定文本是否存在。
|
boolean |
textExists(String text,
int occurrence,
Rect searchRectangle,
int timeout)
返回指定文本是否存在。
|
boolean |
textExists(String text,
int occurrence,
Rect searchRectangle,
int timeout,
boolean exactMatch)
返回指定文本是否存在。
|
Rect |
textRectangle(String text)
返回指定文本的对象相关矩形。
|
Rect |
textRectangle(String text,
int occurrence)
返回指定文本的对象相关矩形。
|
Rect |
textRectangle(String text,
int occurrence,
Rect searchRectangle)
返回指定文本的对象相关矩形。
|
Rect |
textRectangle(String text,
int occurrence,
Rect searchRectangle,
int timeout)
返回指定文本的对象相关矩形。
|
Rect |
textRectangle(String text,
int occurrence,
Rect searchRectangle,
int timeout,
boolean exactMatch)
返回指定文本的对象相关矩形。
|
void |
waitForChildDisappearance(String locator)
等待直到由“locator”参数指定的子级对象不存在或者直到达到超时。
|
void |
waitForChildDisappearance(String locator,
int timeout)
等待直到由“locator”参数指定的子级对象不存在或者直到达到超时。
|
void |
waitForDisappearance()
等待直到对象不存在或达到超时。
|
void |
waitForDisappearance(int timeout)
等待直到对象不存在或达到超时。
|
void |
waitForObject(String locator)
等待与指定定位器匹配的对象。
|
void |
waitForObject(String locator,
int timeout)
等待与指定定位器匹配的对象。
|
void |
waitForProperty(String propertyName,
Object expectedValue)
等待直到由“propertyName”参数指定的属性获取由“expectedValue”参数指定的值或者直到达到超时。
|
void |
waitForProperty(String propertyName,
Object expectedValue,
int timeout)
等待直到由“propertyName”参数指定的属性获取由“expectedValue”参数指定的值或者直到达到超时。
|
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
- 可确定 TestObject 的句柄desktop
- 此对象所在的桌面public String captureBitmap(String fileName)
第一次捕获对象后,代理会等待用 OPT_BITMAP_MATCH_INTERVAL 选项指定的时间间隔,然后再重新捕获对象,将此结果与第一次捕获结果进行比较以确保图像稳定。
您设置的连续位图必须与 OPT_BITMAP_MATCH_COUNT 选项匹配。如果用 OPT_BITMAP_MATCH_TIMEOUT 选项指定时间后图像不稳定,则抛出 BitmapNotStableException。
fileName
- 要将位图保存至的绝对或相对文件名。将 .png 附加到文件名以将位图另存为 PNG。public String captureBitmap(String fileName, Rect region)
第一次捕获对象后,代理会等待用 OPT_BITMAP_MATCH_INTERVAL 选项指定的时间间隔,然后再重新捕获对象,将此结果与第一次捕获结果进行比较以确保图像稳定。
您设置的连续位图必须与 OPT_BITMAP_MATCH_COUNT 选项匹配。如果用 OPT_BITMAP_MATCH_TIMEOUT 选项指定时间后图像不稳定,则抛出 BitmapNotStableException。
fileName
- 要将位图保存至的绝对或相对文件名。将 .png 附加到文件名以将位图另存为 PNG。region
- 捕获区域坐标,相对于此对象public boolean exists(String locator)
超时
参数,则代理会在指定超时过期前一直查找。如果未指定任何超时并且最初未找到任何对象,则系统会立即返回 false
。locator
- 子级对象的 XPath 定位器。例如:"//PushButton[@caption='ok']"
true
;否则返回 false
。public boolean exists(String locator, int timeout)
超时
参数,则代理会在指定超时过期前一直查找。如果未指定任何超时并且最初未找到任何对象,则系统会立即返回 false
。locator
- 子级对象的 XPath 定位器。例如:"//PushButton[@caption='ok']"
timeout
- 超时(毫秒)。如果初始查找操作未与任何项目相匹配,则代理会重新尝试查找对象直到超时过期。true
;否则返回 false
。public String generateLocator()
使用录制期间的创建方式创建定位器。
public List<TestObject> getChildren()
public List<String> getDynamicMethodList()
public TestObject getParent()
public List<String> getPropertyList()
示例使用情况
List<String> propertyList = testObject.getPropertyList();
public Rect getRect()
public Rect getRect(boolean absoluteCoordinates)
absoluteCoordinates
- 如果为 true
,则返回全局坐标(相对于整个屏幕),否则返回的坐标与包含此对象的父级窗口相对应public void highlightObject()
public void highlightObject(int timeout)
timeout
- 指定用于突出显示对象的超时(毫秒)。如果未指定任何超时,则对象将永远突出显示或直到其他对象突出显示。public void highlightObject(int timeout, Color color)
timeout
- 指定用于突出显示对象的超时(毫秒)。如果未指定任何超时,则对象将永远突出显示或直到其他对象突出显示。color
- 指定用于突出显示此对象的颜色。如果未指定任何颜色,则使用默认颜色。public Object invokeMethods(List<String> names, List<List<Object>> parameters)
除最后一个方法外,每个方法调用都必须有返回对象。每个返回对象将成为目标,即调用参数列表中具有下一参数列表的方法名称列表中的下一个方法,直到最后一个方法调用。如果方法名称、参数列表或返回的对象不匹配,则运行时错误将生成。
此方法为 WPF、Windows Forms、Silverlight、Java SWT 和 Java Swing 实施。
names
- 以调用顺序排列的方法名称列表parameters
- 列表包含每种方法的参数列表。可能省略了尾部空参数列表。public String textCapture()
捕获组合框中的文本可能附加文本字符“6”。这是因为组合框的下拉箭头是 Marlett 字体下拉箭头文本符号,对于多数其他字体,此字符为数字“6”。
public String textCapture(Rect captureRectangle)
捕获组合框中的文本可能附加文本字符“6”。这是因为组合框的下拉箭头是 Marlett 字体下拉箭头文本符号,对于多数其他字体,此字符为数字“6”。
captureRectangle
- 相对于窗口坐标的已定义矩形区域,将在此区域上捕获文本public void textClick(String text)
text
- 可被单击的文本public void textClick(String text, int occurrence)
text
- 可被单击的文本occurrence
- 应单击文本的哪个匹配项,如果存在多个结果,则第一个匹配项为 1public void textClick(String text, int occurrence, ClickType clickType)
text
- 可被单击的文本occurrence
- 应单击文本的哪个匹配项,如果存在多个结果,则第一个匹配项为 1clickType
- 所需的鼠标操作。默认:左键单击。public void textClick(String text, int occurrence, ClickType clickType, ModifierKey modifiers)
text
- 可被单击的文本occurrence
- 应单击文本的哪个匹配项,如果存在多个结果,则第一个匹配项为 1clickType
- 所需的鼠标操作。默认:左键单击。modifiers
- 单击时可按的修饰键(Alt、Shift、Ctrl)。默认:不使用修饰键。public void textClick(String text, int occurrence, ClickType clickType, ModifierKey modifiers, Point position)
text
- 可被单击的文本occurrence
- 应单击文本的哪个匹配项,如果存在多个结果,则第一个匹配项为 1clickType
- 所需的鼠标操作。默认:左键单击。modifiers
- 单击时可按的修饰键(Alt、Shift、Ctrl)。默认:不使用修饰键。position
- 可单击的坐标。坐标与文本左上角相对应。如果未指定任何坐标,则在文本中心执行单击。public void textClick(String text, int occurrence, ClickType clickType, ModifierKey modifiers, Point position, boolean exactMatch)
text
- 可被单击的文本occurrence
- 应单击文本的哪个匹配项,如果存在多个结果,则第一个匹配项为 1clickType
- 所需的鼠标操作。默认:左键单击。modifiers
- 单击时可按的修饰键(Alt、Shift、Ctrl)。默认:不使用修饰键。position
- 可单击的坐标。坐标与文本左上角相对应。如果未指定任何坐标,则在文本中心执行单击。exactMatch
- 如果为 true
,则文本必须完全匹配已捕获的文本,否则支持部分匹配public boolean textExists(String text)
text
- 可被搜索的文本public boolean textExists(String text, int occurrence)
text
- 可被搜索的文本occurrence
- 对于文本的哪个匹配项,应确认存在,如果存在多个结果,则第一个匹配项为 1public boolean textExists(String text, int occurrence, Rect searchRectangle)
text
- 可被搜索的文本occurrence
- 对于文本的哪个匹配项,应确认存在,如果存在多个结果,则第一个匹配项为 1searchRectangle
- 对象相关矩形,在其中搜索文本public boolean textExists(String text, int occurrence, Rect searchRectangle, int timeout)
text
- 可被搜索的文本occurrence
- 对于文本的哪个匹配项,应确认存在,如果存在多个结果,则第一个匹配项为 1searchRectangle
- 对象相关矩形,在其中搜索文本timeout
- 指定搜索文本所用的时间。如果未指定任何超时,则仅搜索一次文本。public boolean textExists(String text, int occurrence, Rect searchRectangle, int timeout, boolean exactMatch)
text
- 可被搜索的文本occurrence
- 对于文本的哪个匹配项,应确认存在,如果存在多个结果,则第一个匹配项为 1searchRectangle
- 对象相关矩形,在其中搜索文本timeout
- 指定搜索文本所用的时间。如果未指定任何超时,则仅搜索一次文本。exactMatch
- 如果为 true
,则文本必须完全匹配已捕获的文本,否则支持部分匹配public Rect textRectangle(String text)
text
- 可被搜索的文本public Rect textRectangle(String text, int occurrence)
text
- 可被搜索的文本occurrence
- 对于文本的哪个匹配项,应返回矩形,如果存在多个结果,则第一个匹配项为 1public Rect textRectangle(String text, int occurrence, Rect searchRectangle)
text
- 可被搜索的文本occurrence
- 对于文本的哪个匹配项,应返回矩形,如果存在多个结果,则第一个匹配项为 1searchRectangle
- 对象相关矩形,在其中搜索文本public Rect textRectangle(String text, int occurrence, Rect searchRectangle, int timeout)
text
- 可被搜索的文本occurrence
- 对于文本的哪个匹配项,应返回矩形,如果存在多个结果,则第一个匹配项为 1searchRectangle
- 对象相关矩形,在其中搜索文本timeout
- 指定搜索文本所用的时间。如果未指定任何超时,则仅搜索一次文本。public Rect textRectangle(String text, int occurrence, Rect searchRectangle, int timeout, boolean exactMatch)
text
- 可被搜索的文本occurrence
- 对于文本的哪个匹配项,应返回矩形,如果存在多个结果,则第一个匹配项为 1searchRectangle
- 对象相关矩形,在其中搜索文本timeout
- 指定搜索文本所用的时间。如果未指定任何超时,则仅搜索一次文本。exactMatch
- 如果为 true
,则文本必须完全匹配已捕获的文本,否则支持部分匹配public void waitForChildDisappearance(String locator)
locator
- 期望消失的识别对象的 XPath 定位器与此功能调用的对象相对应public void waitForChildDisappearance(String locator, int timeout)
locator
- 期望消失的识别对象的 XPath 定位器与此功能调用的对象相对应timeout
- 功能超时前的最长等待时间(毫秒)public void waitForDisappearance()
public void waitForDisappearance(int timeout)
timeout
- 功能超时前的最长等待时间(毫秒)public void waitForObject(String locator)
OPT_WAIT_RESOLVE_OBJDEF
的值来更改超时。如果 AUT 需要很长时间显示特定对象,则使用 WaitForObject,例如,在显示任意结果前处理交易时。默认情况下,由于内置同步,UI 中的操作不需要 WaitForObject。如果正常脚本执行期间您收到了随机超时错误,则考虑增加默认超时,而不要向脚本添加 WaitForObject 语句。
示例使用情况以下示例将窗口设为处于活动状态,然后等待按钮 30 秒,
除用于
window.setActive(); window.waitForObject("//PushButton[@automationId='MySampleButton']", 30000); window.<PushButton>find("//PushButton[@automationId='MySampleButton']").click();
locator
- XPath 定位器。定义要查找哪个对象。例如:"//PushButton[@caption='ok']"
public void waitForObject(String locator, int timeout)
OPT_WAIT_RESOLVE_OBJDEF
的值来更改超时。如果 AUT 需要很长时间显示特定对象,则使用 WaitForObject,例如,在显示任意结果前处理交易时。默认情况下,由于内置同步,UI 中的操作不需要 WaitForObject。如果正常脚本执行期间您收到了随机超时错误,则考虑增加默认超时,而不要向脚本添加 WaitForObject 语句。
示例使用情况以下示例将窗口设为处于活动状态,然后等待按钮 30 秒,
除用于
window.setActive(); window.waitForObject("//PushButton[@automationId='MySampleButton']", 30000); window.<PushButton>find("//PushButton[@automationId='MySampleButton']").click();
locator
- XPath 定位器。定义要查找哪个对象。例如:"//PushButton[@caption='ok']"
timeout
- 超时(毫秒)。如果初始查找操作未与任何项目相匹配,则代理会重新尝试查找对象直到超时过期。public void waitForProperty(String propertyName, Object expectedValue)
propertyName
- 可等待的属性的名称expectedValue
- 可等待的属性的值public void waitForProperty(String propertyName, Object expectedValue, int timeout)
propertyName
- 可等待的属性的名称expectedValue
- 可等待的属性的值timeout
- 功能超时前的最长等待时间(毫秒)public String getText()
public Object getValue()
Copyright 2009-2012 Micro Focus. All Rights Reserved.