如何灵活查找窗体内的对象呢?和查找窗体类似,可以使用这些对象特有的属性,依照一定的查找逻辑进行处理。下面是一个典型的查找方法,以此为例进行说明:
public TestObject getObject(ArrayList<Property> v) {
rootTO.waitForExistence(waitMaxTime, waitCheckInterval);
TestObject returnObject = null;
TestObject to[] = null;
double timeNow = System.currentTimeMillis() / 1000;
double endTime = timeNow + waitMaxTime;
v.add(new Property("showing", "true"));
while (returnObject == null && timeNow < endTime) {
to = rootTO.find(atDescendant((Property[]) v.toArray(new Property[0])));
if (to.length > 1) {
throw new AmbiguousRecognitionException("Find more than one object.");
}
if (to.length == 1) {
returnObject = to[0];
} else
sleep(waitCheckInterval);
timeNow = System.currentTimeMillis() / 1000;
}
return returnObject;
}
上面的方法根据传入的参数集合对当前窗口中的所有对象进行查找。和之前的窗体查找一样,最好显示的添加showing=true参数,因为在Swing程序的运行过程中,内存中会对GUI元素进行缓存,可能一个界面消失了,但它还在内存中,等待着随后被显示。这样一来,就需要这个参数过滤到所有未被显示的GUI元素。在实际使用过程中,可以使用如下的方法进行调用: (调用前使用RFT的对象查看器确定待查找对象的唯一属性)
protected WButton getButton(String name) {
ArrayList<Property> v = new ArrayList<Property>();
v.add(new Property(".class", "javax.swing.JButton"));
v.add(new Property("accessibleContext.accessibleName", name));
TestObject to = og.getObject(v);
if (!Utility.exists(to))
throw new ObjectNotFoundException();
else
return new WButton(to);
}
与窗口处理一样,如果某些参数需要使用正则表达式处理,可以使用下面的方法:
protected WListBox getList(String label) {
RegularExpression exp = new RegularExpression(".*JComboBox$|.*JList$", false);
ArrayList<Property> v = new ArrayList<Property>();
v.add(new Property(".class", exp));
v.add(new Property(".priorLabel", label));
TestObject to = og.getObject(v);
if (!Utility.exists(to))
throw new ObjectNotFoundException();
else
return new WListBox(to);
}
在对象查找过程中,可能需要各种不同的查找逻辑。例如,如果对象可能存在也可能不存在,在查找的时候就不需要等待并反复查找,这时候,可以使用如下的方法:
public TestObject getObjectWithoutWait(ArrayList<Property> v) {
rootTO.waitForExistence();
TestObject returnObject = null;
v.add(new Property("showing", "true"));
TestObject to[] = rootTO.find(atDescendant((Property[]) v.toArray(new Property[0])));
if (to.length > 1) {
throw new AmbiguousRecognitionException(
Find more than one object.);
}
if (to.length == 1) {
returnObject = to[0];
}
return returnObject;
}
有时候,界面上有多个具有相同属性的对象,只能通过他们的编号来区分他们;有时候需要以某个确定对象为根来进行查找;有时候需要查找直接子对象而不是所有子对象,等等。并且,这些逻辑之间也存在排列组合的情况,实际使用中可以根据自身需要灵活处理。这些方法都是对上面基本方法的扩展,大家可以尝试自己来实现。
分享到:
相关推荐
资源分类:Python库 所属语言:Python 资源全名:rft-core-1.3.3.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
nrpe-3.0.1.tar.gz
RFT8.0安装手順.xls RFT8.0安装手順.xls
This paper presents a variant of the Discrete Fourier Transform (DFT)3 that is particularly destined for the implementation in embedded applications, which are characterized by limited resources in ...
RFT使用手册+.docxRFT使用手册+.docx
基于GPU的RFT算法并行化.pdf
执业医师资格考试-3-方剂学(执)rft分享.pdf
RFT7750中文版规格书.pdf
使用java生成pdf的iText5.0.6.rar以及处理亚洲文字的iTextAsian.rar 使用java生成word的iText-rft-2.1.7.rar
RFT ITCL 框架,放在这里,挣点资源分。
最新的 itext JAR 包括 rft支持
20111021到期,浮动license,请不要用于商业用途
If you are seeing error messages that contain any of these phrases... urlread, curl, urlreadwrite,...https://www.coursera.org/learn/machine-learning/discussions/vgCyrQoMEeWv5yIAC00Eog/replies/nbnnOQ8pEeWZSyIAC5bWOg/comments/UwPlxEFYEeWBGw50Rft1Mw?utm_medium=email&utm_source=other&utm_campaign=opencourse.discourse.machine...
IBM RFT 文档包IBM RFT 文档包
(c) 附加数据点可用于改进图像处理算法对入侵者形状的估计,例如:为wheel1 添加[0.008,-0.0125,0.008,-0.0125,0.1,0.1,-.1,-.1]。 PNG (d) 如果算法未能选择正确的外法线方向,按下翻转法线按钮后再次离散。 2)...
RFT8.1的破解文件及说明。
解决RFT(Rational functional tester)中的几个问题: 1 动态识别页面对象太慢 -- 页面对象缓存的特性 2 动态识别对象的代码太过于复杂 -- 描述性编程的...3 动态识别页面对象不够直观 -- 根据页面文字直接识别的特性
RFT相关资料RFT相关资料RFT相关资料RFT相关资料RFT相关资料RFT相关资料RFT相关资料
电力行业—RFT.pptx
顺络迅达电子的军工磁性器件替换选型指南,包含电感,磁珠,变压器,滤波器,功分器。对应替换目前日本美国大厂比如Aem,村田什么的。大部分可以实现原位替换