??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲精品国产精品久久清纯直播,500福利第一精品导航,wwwww在线观看免费视频 http://www.aygfsteel.com/terrypang/Automation with Java zh-cn Thu, 19 Jun 2025 23:47:40 GMT Thu, 19 Jun 2025 23:47:40 GMT 60 RFT Best Practices - 4. 对象操作 http://www.aygfsteel.com/terrypang/archive/2009/04/20/266576.htmlterrypang terrypang Mon, 20 Apr 2009 08:44:00 GMT http://www.aygfsteel.com/terrypang/archive/2009/04/20/266576.html http://www.aygfsteel.com/terrypang/comments/266576.html http://www.aygfsteel.com/terrypang/archive/2009/04/20/266576.html#Feedback 2 http://www.aygfsteel.com/terrypang/comments/commentRss/266576.html http://www.aygfsteel.com/terrypang/services/trackbacks/266576.html 扑ֈ对象之后Q就需要对其进行操作了(jin)。在对对象进行操作之前,需要了(jin)?/span>RFT 处理对象的方式。根?/span>RFT 的文档, Java 对象的关pd下图Q?/span>
由此可见Q绝大多数的对象都是l承?/span>GuiTestObject ?/span>GuiSubitemTestObject 。类?/span>Button ?/span>CheckBox q样的简单对象,自然是承于 GuiTestObject Q而像 List ?/span>Table q样的有内部子对象的复杂对象Q一定是l承?/span>GuiSubitemTestObject 。根据这一规律Q就可以分别建立你所需要的cM(jin)?/span>
负责 Button 的类如下Q?font class="Apple-style-span" face="'Times New Roman'">
package framework.widgets;
import java.awt.Point;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rational.test.ft.object.interfaces.GuiTestObject;
import com.rational.test.ft.object.interfaces.TestObject;
public class WButton extends GuiTestObject {
public WButton(TestObject button) {
super (button);
}
public void click() {
super .click();
}
public void click( int x, int y) {
super .click( new Point(x, y));
}
public void doubleClick() {
super .doubleClick();
}
public boolean isEnabled() {
return super .isEnabled();
}
}
其他单对象也可以l承 ToggleGUITestObject ?/span>TextScrollTestObject {其他衍生于 GuiTestObject c,q些cd装了(jin)很多实用的方法可以直接用,具体请参?/span>RFT 文档中的 API ?/span>
负责TabPane的类如下Q?/p>
package framework.widgets;
import java.util.Vector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rational.test.ft.object.interfaces.GuiSubitemTestObject;
import com.rational.test.ft.object.interfaces.TestObject;
import com.rational.test.ft.script.Index;
import com.rational.test.ft.script.Text;
import com.rational.test.ft.vp.ITestData;
import com.rational.test.ft.vp.ITestDataElementList;
import com.rational.test.ft.vp.ITestDataList;
public class WTabbedPane extends GuiSubitemTestObject {
static final Logger logger = LoggerFactory.getLogger( " WTabbedPane.class " );
public WTabbedPane(TestObject tabbedPane) {
super (tabbedPane);
}
public void clickTab(String tabName) {
this .click( new Text(tabName));
}
public void clickTab( int index) {
this .click( new Index(index));
}
public int getTabCount() {
logger.info( " Get tab count " );
ITestData data = (ITestData) super .getTestData( " list " );
ITestDataList list = (ITestDataList) data;
return list.getElementCount();
}
public int findTab(String text) {
logger.info( " Find the index of tab {} " , text);
Vector contents = this .getAllTabs();
for ( int i = 0 ; i < contents.size(); i ++ ) {
if (contents.get(i).toString().equals(text)) {
return i;
}
}
return - 1 ;
}
public String getTabText( int index) {
logger.info( " Get tab text with index {} " , index);
Vector contents = this .getAllTabs();
if (index < 0 || index >= contents.size()) {
return null ;
}
return (String) contents.get(index);
}
public Vector getAllTabs() {
logger.info( " Get all tabs " );
ITestDataList dataList = (ITestDataList) super .getTestData( " list " );
ITestDataElementList elementList = (ITestDataElementList) dataList
.getElements();
return elementList.getElements();
}
}
׃面的例子可以看出来,对对象的操作可以分ؓ(f)两类Q一cL施加行ؓ(f)Q一cLd数据。对此,RFT的APIl出?jin)详l的文档Q例如对于List对象Q文档如下:(x)
由此可看出,对于List对象Q可以通过.class, .classIndex, .itemCount, .itemText, .priorLabelQaccessibleContext.accessibleNameQname和toolTipTextq些属性进行识别。获取List对象后,它支持Text和Indexq两cd对象Q可通过ITestDataList接口获得全部列表元素和已选列表元素。上面getAllTabs()Ҏ(gu)是用来获得所有Tab选项的,可以作ؓ(f)参考?/span>
q有一些更为复杂的单对象,如:(x)TextField和FrameQ以?qing)复杂对象,如?x)Table和Tree。如果你能够理解上述处理对象的方法,那么完全可以~写W合自己目需要的Ҏ(gu)Q对q些对象q行各种各样的操作?/span>
]]>RFT Best Practices - 3. 对象查找 http://www.aygfsteel.com/terrypang/archive/2009/03/31/263037.htmlterrypang terrypang Tue, 31 Mar 2009 01:31:00 GMT http://www.aygfsteel.com/terrypang/archive/2009/03/31/263037.html http://www.aygfsteel.com/terrypang/comments/263037.html http://www.aygfsteel.com/terrypang/archive/2009/03/31/263037.html#Feedback 0 http://www.aygfsteel.com/terrypang/comments/commentRss/263037.html http://www.aygfsteel.com/terrypang/services/trackbacks/263037.html 如何灉|查找H体内的对象呢?和查扄体类|可以使用q些对象Ҏ(gu)的属性,依照一定的查找逻辑q行处理。下面是一个典型的查找Ҏ(gu)Q以此ؓ(f)例进行说明:(x)
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;
}
上面的方法根据传入的参数集合对当前窗口中的所有对象进行查找。和之前的窗体查找一P最好显C的d showing=true 参数Q因为在 Swing E序的运行过E中Q内存(sh)?x)?/span>GUI 元素q行~存Q可能一个界面消׃(jin)Q但它还在内存(sh)Q等待着随后被显C。这样一来,需要这个参数过滤到所有未被显C的 GUI 元素。在实际使用q程中,可以使用如下的方法进行调用:(x) Q调用前使用RFT的对象查看器定待查扑֯象的唯一属性)(j)
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);
}
与窗口处理一P如果某些参数需要用正则表辑ּ处理Q可以用下面的Ҏ(gu)Q?/span>
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);
}
在对象查找过E中Q可能需要各U不同的查找逻辑。例如,如果对象可能存在也可能不存在Q在查找的时候就不需要等待ƈ反复查找Q这时候,可以使用如下的方法:(x)
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;
}
有时候,界面上有多个h相同属性的对象Q只能通过他们的编h区分他们Q有时候需要以某个定对象为根来进行查找;有时候需要查扄接子对象而不是所有子对象Q等{。ƈ且,q些逻辑之间也存在排列组合的情况Q实际用中可以Ҏ(gu)自n需要灵zd理。这些方法都是对上面基本Ҏ(gu)的扩展,大家可以试自己来实现?/span>
]]>RFT Best Practices - 2. H体处理 http://www.aygfsteel.com/terrypang/archive/2009/03/21/261255.htmlterrypang terrypang Sat, 21 Mar 2009 12:57:00 GMT http://www.aygfsteel.com/terrypang/archive/2009/03/21/261255.html http://www.aygfsteel.com/terrypang/comments/261255.html http://www.aygfsteel.com/terrypang/archive/2009/03/21/261255.html#Feedback 1 http://www.aygfsteel.com/terrypang/comments/commentRss/261255.html http://www.aygfsteel.com/terrypang/services/trackbacks/261255.html H体是程序的基础。无论是ȝ体,q是弹出H体Q他们往往都是需要首先定位的对象。窗体,作ؓ(f)一cȝD对象,他们都是根对象的直接子对象,针对q一特点Q对他们定位非常简单了(jin)。通常Q通过H体标题Q就能很好的扑ֈ所需的窗体。具体方法如下?/span>
private double waitCheckInterval = ((Double) getOption(IOptionName.WAIT_FOR_EXISTENCE_DELAY_BETWEEN_RETRIES))
.doubleValue();
private double waitMaxTime = ((Double) getOption(IOptionName.MAXIMUM_WAIT_FOR_EXISTENCE))
.doubleValue();
private TestObject rootTO = null ;
public boolean getRootWithCaption(String captionExpr) {
double timeNow = System.currentTimeMillis() / 1000 ;
double endTime = timeNow + waitMaxTime;
rootTO = null ;
while (rootTO == null && timeNow < endTime) {
RootTestObject root = RootTestObject.getRootTestObject();
TestObject[] ftWinObjects = null ;
RegularExpression exp = new RegularExpression(captionExpr, false );
ArrayList < Property > v = new ArrayList < Property > ();
v.add( new Property( " .captionText " , exp));
v.add( new Property( " .domain " , " Java " ));
v.add( new Property( " showing " , " true " ));
ftWinObjects = root.find(atChild((Property[]) v.toArray( new Property[ 0 ])));
if (ftWinObjects != null ) {
if (ftWinObjects.length > 1 ) {
throw new AmbiguousRecognitionException( " Find more windows with capture: " + captionExpr);
}
if (ftWinObjects.length == 1 ) {
rootTO = ftWinObjects[ 0 ];
return true ;
}
} else {
sleep(waitCheckInterval);
timeNow = System.currentTimeMillis() / 1000 ;
}
}
return false ;
}
上面的方法首先取得对象查扄间隔旉、最大等待时_(d)q声明了(jin)I的H体对象。接下来q入Ҏ(gu)Q根据查扄果和最大等待时间来循环查找H体。先获得Ҏ(gu)试对象,然后查找其直接子对象Q查找条件ؓ(f)Q窗体标题符合正则表辑ּ captionExpr 的定义,属于 Java 域,q且当前为显C状态。最后处理查扄果,如果l果大于 1 个,则抛出异常;如果l果{于 1 Q则q回 true Q如果结果ؓ(f)I,则等待ƈ重新计算旉Qƈl箋(hu)循环查找Q如果最后仍未空q出@环,则返?/span>false ?/span>
有的时候,H口的出现ƈ不是一定的Q例如很多弹出窗口。这时候,对象查找q不需要@环等待,相应的方法应为:(x)
public boolean getRootWithCaptionWithoutWait(String captionExpr) {
rootTO = null ;
sleep(waitCheckInterval);
RootTestObject root = RootTestObject.getRootTestObject();
TestObject[] ftWinObjects = null ;
RegularExpression exp = new RegularExpression(captionExpr + " $ " , false );
ArrayList < Property > v = new ArrayList < Property > ();
v.add( new Property( " .captionText " , exp));
v.add( new Property( " .domain " , " Java " ));
v.add( new Property( " showing " , " true " ));
ftWinObjects = root.find(atChild((Property[]) v.toArray( new Property[ 0 ])));
if (ftWinObjects != null ) {
if (ftWinObjects.length > 1 ) {
throw new AmbiguousRecognitionException( " Find more windows with capture: " + captionExpr);
}
if (ftWinObjects.length == 1 ) {
rootTO = ftWinObjects[ 0 ];
return true ;
}
}
return false ;
}
q样一来,可以用l一的方法来q行H体的查找。具体代码如下:(x)
protected boolean ExistWin(String winName, boolean wait) {
release();
if (wait)
return og.getRootWithCaption(winName);
else
return og.getRootWithCaptionWithoutWait(winName);
}
public boolean isDialog(String caption, boolean wait) {
return super .ExistWin(caption, wait);
}
前一个方法利用传入的H体标题正则表达式,和窗体查N辑Q进行窗体查找。后一个方法对其进行调用,q回是否查找成功的结果。事实上Q这两个Ҏ(gu)完全可以写成一个,但是在设计框架时Q应考虑到自动化操作的各个环节,应把每一个环节独立开来,才能h最大的灉|性。根据我的经验,对对象的查找和查扑的操作应独立成两个不同类来完成,其中对对象的查找应ؓ(f)一?/span>RFT ?/span>super class 。其实也是l承?/span>RationalTestScript cȝ抽象c,对对象的操作应ؓ(f)一?/span>Script Q这?/span>Script ?/span>super class 应ؓ(f)自己之前定义的对象查扄Q而不是默认的 RationalTestScript 。这一部分后面q(sh)(x)讲到?/span>
当需要关闭可能出现的错误H口Ӟ可以q样使用Q?/span>
if (aDialog.isDialog( " .*Error " , false )) {
aDialog.close();
}
当需要操作一定出现的H口Ӟ可以q样使用Q?/span>
if (aDialog.isDialog( " Warning " , true )) {
aDialog.clickButton( " Yes " );
}
x(chng)Q所有针对窗体的处理逻辑基本完整了(jin)。当?dng)可能有些被测E序可以同时打开多个实例Q这需要支持同时获取ƈ操作多个h相同标题的窗体。这L(fng)问题大家可以一同探讨如何处理?/span>
]]> RFT Best Practices - 1. 引言 http://www.aygfsteel.com/terrypang/archive/2009/03/21/261254.htmlterrypang terrypang Sat, 21 Mar 2009 12:48:00 GMT http://www.aygfsteel.com/terrypang/archive/2009/03/21/261254.html http://www.aygfsteel.com/terrypang/comments/261254.html http://www.aygfsteel.com/terrypang/archive/2009/03/21/261254.html#Feedback 0 http://www.aygfsteel.com/terrypang/comments/commentRss/261254.html http://www.aygfsteel.com/terrypang/services/trackbacks/261254.html
是一个十分优U的自动化试工具。尤其是目前?/span>7.0.1.2提供?jin)很多基设施Q例如:(x)对象的映、动作的录制 /?/span>TxT的用者在使用q程中忽略了(jin)对这些基设施背后内容的了(jin)解,以至于出C(jin)问题束手无策。其实, RFT暴露l用者,只要用好q些 API有一D|间的人,应该知道 IBM库,是专门针?/span>RFTq_(d)(j)Q如果你使用最新的 RFT7.0都变化了(jin)Q这个库有不部分都不能用了(jin)?/span>
是一个多么灵zȝ工具Q也正因一点,很多人都不明白如何能够正的使用 RFT使用的最?jng)_践就是开发属于自q试框架。只有这h能发?/span>RFT界面的项目,介绍一下如何开发自q试框架。( SwingQ?/span>
提供的基设施Q灵zL很差。具体内定w后将逐一介绍?/span>
]]>
վ֩ģ壺
|
˼ |
Ϫ |
ʯ |
|
ƽ |
Ϻ |
|
|
ʵ |
|
|
ⶫ |
Ӳ |
괨 |
|
گ |
|
ⶫ |
|
¹ |
崨 |
Ϫ |
ӳ |
|
Զ |
|
|
|
Ž |
|
ף |
|
ԭ |
|
|
ɽ |
|
|
ݳ |
Ҵ |