不谋万世者,不足谋一时;不谋全局者,不足谋一域。君子敏于事而慎于言 新浪微薄:土司阿哈

RFT代码收藏四

上一篇 / 下一篇  2008-06-17 14:00:33 / 个人分类:Rational

1208328177
  • 自动化测试:
  • 测试文档:

9.使用方法findSubitem properties)在某个特定范围查找满足条件的所有对象51Testing软件测试网 Q9bLJ4@jQj

录制的脚本,使用方法document_htmlDocument()来调用页面的Document对象,使用方法text_q()来调用搜索输入框,使用方法button_search()来调用搜索按钮。这些方法是由脚本SearchLotusLink的父类SearchLotusLinkHelper定义的

i4}"\xa'N7Y0

        protected GuiTestObject document_htmlDocument()

r `.?@k0

        {51Testing软件测试网+H5sP!Row2_

                return new GuiTestObject(getMappedTestObject("document_htmlDocument"));

1kr6S5OD:^6y*|0

        }

j1nH:?m0

类:com.rational.test.ft.object.interfaces.TestObject,而它的方法findSubitem properties)正是用来在某个特定范围内查找满足条件的所有对象。改造后,回放过程中所需要用到的页面对象都是在当前浏览器中即时查找得到的。通过目标对象的类型和某个属性值来定位目标对象51Testing软件测试网2i LTt,VnnD:X

        protected GuiTestObject document_htmlDocument()          {            

1^B#w:OQo'E0

                  return new GuiTestObject(findTestObjectInBrowser(".class","Html.HtmlDocument",null,null));51Testing软件测试网^W/c&_ kB/K cga#^

    }

F'\ b4R4K0

         protected TestObject findTestObjectInBrowser(String property1, String value1, String property2,51Testing软件测试网3BNCU.l p*mH5nO

         String value2)51Testing软件测试网7m6c*y8`BW

         {             TestObject[] foundTOs ;51Testing软件测试网;Y t-fU/t&G

                  //在当前浏览器页面中查找

0DVOI C)y,Ti.Q0

                  if(null==property2)

x%f3?Z/^3?qt o.}A0

                       foundTOs = browser_htmlBrowser().find(atDescendant(property1,value1)) ;

$dt~Mj'|R0

                  else51Testing软件测试网4rUN!P&wj0_^

                       foundTOs = browser_htmlBrowser().find(atDescendant(property1,value1,property2,value2)) ;

s]g j:f:LT3^ JH0

                  //如果没有找到满足条件的TestObject

?E Xx0fO,C)r0

                  if(foundTOs.length<1)

Hn$c HSK,j(Ww0

                  {

k| }Q T&K"o!X7sR7?0

                       throw new com.rational.test.ft.ObjectNotFoundException("Can NOT find TestObject with

'F'd}#p8mm,y:d PL0

                       "+property1+"<"+value1+">,"+property2+"<"+value2+">");

n tl6K"\T!| `\0

             }                  //如果找到多个TestObject满足条件,

FH4s2L6ug0

                  else if(foundTOs.length>1)

+A*_%U$Q j;Vt/\B&e0

                  {51Testing软件测试网H2zm*n9t

                       throw new AmbiguousRecognitionException("Found multi-TestObject with

v;e"BMi\0

                       "+property1+"<"+value1+">,"+property2+"<"+value2+">");

9_3YKa$r}6?u0

             }                  //返回唯一的查找结果51Testing软件测试网6{v1D7}e4b(SP Eeb

                  return foundTOs[0];

+N h;N%u gf0

         }

.g zi G*Q1f\0

10.添加等待时间51Testing软件测试网6x/Kv&Tf+?B$u

·           定长等待51Testing软件测试网pX#kT`
调用Java脚本的公共父类com.rational.test.ft.scrīpt.RationalTestscrīpt里的方法:sleep(double seconds)。这一方法可以使回放过程等待若干秒。51Testing软件测试网!M!r mx)S6\hN
这种方式直观、简单。但缺点也是明显的:固定的时间常常不能适应多变的真实环境:等待时间设置得过长,无疑会拉长测试的回放时间,降低效率;等待时间设置得过短,在某些情况下,又无法起到延时应有的效果,仍然错过了被测对象。51Testing软件测试网`B cT.S

·           不定长等待51Testing软件测试网`'w&f"d4Q3t E4Nu
脚本记录器记录下的这些页面对象都是从接口com.rational.test.ft.object.interfaces.TestObject继承下来的,在TestObject中有一个方法waitForExistence()可以用以实现不定长的等待。在一定的时间限度内,等待该对象的出现;一旦出现后就不再等待,程序继续往下执行。最大时间限度是在"首选项""回放"选项里设置的。不定长等待既达到灵活等待的目的,又没有浪费不必要的等待时间,是一个值得推荐的解决方案。51Testing软件测试网8d-T|V7_ v

11.如何提高脚本的复用程度和兼容性51Testing软件测试网*VD:c F%[S7n

               充分利用Rational Functional Tester的强大功能,比如scrīptAssure技术、正则表达式,数据驱动,Rational Functional Tester API等;2)合理地编写、优化脚本。提纲挈领地对测试过程进行抽象,对关键过程进行必要的验证。

mw1^5A Ndh0

12.ComboBox/List Control中提取参数

ox:BI@/?(_ b!e ]X3S0

import resources.GetListDataExampleHelper;

0c|A-]w(S-S8F.Z3k0

import com.rational.test.ft.*;51Testing软件测试网$Kq`e0r:v
import com.rational.test.ft.object.interfaces.*;51Testing软件测试网w1M*d;? wL;I:Z.vo
import com.rational.test.ft.scrīpt.*;51Testing软件测试网_"{UhZG,C-l
import com.rational.test.ft.value.*;51Testing软件测试网E4k7F5A o.n
import com.rational.test.ft.vp.*;
51Testing软件测试网 Gs7l)ew

public class GetListDataExample extends GetListDataExampleHelper
7{(T6H8R%DJ&{7`0{
d'd-M/bu0public void testMain (Object[] args)51Testing软件测试网"[.U7QpRx
{
\b&p6r@0startApp("ClassicsJavaA");

!qF%KP2h]I"`aa0

// Frame: ClassicsCD51Testing软件测试网Z0jJH#`Y5BAp
tree2Tree().click(atPath("Composers->Schubert->Location(PLUS_MINUS)"));
:gBt.chC*E j0tree2Tree().click(atPath("Composers->Schubert->Die schone Mullerin, Op. 25"));
"a NwU p Z w!k b0placeOrderButton2Button().click();
51Testing软件测试网'|*~y4h%VS&v ?

//Declare variables for list
LtPZ8}!sS\/Lg _0ITestDataList nameList;51Testing软件测试网'cj,J~!\O
ITestDataElementList nameListElements;51Testing软件测试网~ lt2_H&z
ITestDataElement nameListElement;
51Testing软件测试网z)m K;o.V'R

// Frame: Member Logon51Testing软件测试网#cw#L,x9}y!pL6R
nameComboComboBox().waitForExistence();

W5^ Y+][/^IZ6~2I0

// Available test data types: {selected=Selected List Element, list=List Elements}
k:v5n4A!j7S(K;~:o*uP0java.util.Hashtable ht = nameComboComboBox().getTestDataTypes();51Testing软件测试网c:qg9f T)Wkt
System.out.println(ht);

bz}8VFZD;x0

// Get all elements51Testing软件测试网i!ck I!I"h-iR
nameList = (ITestDataList)nameComboComboBox().getTestData("list");
51Testing软件测试网/N3CQI}

nameListElements = nameList.getElements();

HT6Av,o{x0

int listElemCount = nameList.getElementCount();

^8jcQ FKm0

for (int i = 0; i < listElemCount; i++)51Testing软件测试网n `i-D^-s M4J
{51Testing软件测试网8f L;j"_v&S
nameListElement = nameListElements.getElement(i);51Testing软件测试网Yo+oU|&mi+Xi HL
System.out.println(nameListElement.getElement());
51Testing软件测试网%B ATGpl

// Click on each element51Testing软件测试网8{*D9?8e3?Yi ?
nameComboComboBox().click();
1o?c%QZ?2S0Fp|0nameComboComboBox().click(atText(nameListElement.getElement().toString()));51Testing软件测试网PR jaB1P!O P2V{$u
};

7l{GQ,N3QRx0

cancelorderlogonButton().click();51Testing软件测试网T `&bDy*S

// Frame: ClassicsCD
ExpM Z?0ClassicsJavaFrame(ANY,MAY_EXIT).close();51Testing软件测试网7V-z.Q}gE8U
}

s-P(N7Ep`tw(b0

}

Q,lw5y7^0o[)NB0

 

da4BZdfQi0

TAG: Rational

飞翔~~` 引用 删除 hui0628   /   2009-02-25 11:58:36
很有价值的东东啊
 

评分:0

我来说两句

Open Toolbar