Java 我如何知道标签页后面的焦点在哪里以及如何在RFT中使用该组件?
我和RFT一起工作,希望知道如何在焦点所在的位置获取对象,并能够在之后处理对象。 例如,我的脚本比我写的要开始 getScreen.inputKeys{TAB}和 我想知道哪个部分有重点 在这之后,我想知道如何得到像这样的聚焦物体的特性 .getProperty.text;或.getProperty.name 我之所以需要它,是因为我想写一个测试脚本来测试我们网站中的焦点顺序 提前谢谢大家,Java 我如何知道标签页后面的焦点在哪里以及如何在RFT中使用该组件?,java,tabs,focus,rft,tab-ordering,Java,Tabs,Focus,Rft,Tab Ordering,我和RFT一起工作,希望知道如何在焦点所在的位置获取对象,并能够在之后处理对象。 例如,我的脚本比我写的要开始 getScreen.inputKeys{TAB}和 我想知道哪个部分有重点 在这之后,我想知道如何得到像这样的聚焦物体的特性 .getProperty.text;或.getProperty.name 我之所以需要它,是因为我想写一个测试脚本来测试我们网站中的焦点顺序 提前谢谢大家, Krisz您可以使用以下简单方法来完成此操作 private void hasFocus(TestObj
Krisz您可以使用以下简单方法来完成此操作
private void hasFocus(TestObject to) {
boolean hasFocus = ((Boolean)to.getProperty(".hasFocus")).booleanValue();
if (!hasFocus)
throw new RuntimeException(to.getNameInScript()+" has an invalid focus order!");
}
并在每次按TAB键后调用此方法;将预期获得焦点的测试对象作为参数。示例脚本代码:
browser_htmlBrowser().inputKeys("{TAB}");
hasFocus(firstObj());
browser_htmlBrowser().inputKeys("{TAB}");
hasFocus(secondObj());
我会搜索.hasFocus属性设置为true的对象。从那里,您可以在循环中运行该方法,以检查当前关注的元素是否是您想要的元素。如果可能的话,我个人还建议检查.id属性,因为对于给定的网页,它保证是唯一的标识符。。。但是我不完全确定.name属性是否正确
public void testMain(Object[] args) {
ArrayList<String> focusOrder = new ArrayList<String>();
String currentlyFocusedObjectName = "";
// Add element names to the list
focusOrder.add("Object1");
focusOrder.add("Object2");
// ...
focusOrder.add("Objectn");
// Iterate through the list, tabbing and checking ".name" property each time
for (String s: focusOrder) {
TestObject currentObject = getCurrentlyFocusedElement();
// Tab
getScreen().inputKeys("{TAB}");
if (currentObject != null) {
currentlyFocusedObjectName = getCurrentlyFocusedElement().getProperty(".name")
.toString();
// Do other stuff with the object
}
else {
currentlyFocusedObjectName = "";
}
// Verify that the currently focused object matches the current iteration in the list.
vpManual(s + "HasFocus", currentlyFocusedObjectName, s).performTest();
}
}
private TestObject getCurrentlyFocusedElement() {
RootTestObject root = RootTestObject.getRootTestObject();
TestObject[] focusedObjects = root.find(atProperty(".hasFocus", "true");
TestObject currentlyFocusedObject = null;
// Check to ensure that an object was found
if (focusedObjects.length > 0) {
currentlyFocusedObject = focusedObjects[0];
}
else {
unregister(focusedObjects);
return null;
}
// Clean up the object
unregister(focusedObjects);
return currentlyFocusedObject;
}
问题是…?我认为这不可能。