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

RFT代码收藏四

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

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

9.使用方法findSubitem properties)在某个特定范围查找满足条件的所有对象51Testing软件测试网)A+jKc F~5x

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

7V!H(^-N@!X@"|0

        protected GuiTestObject document_htmlDocument()

~_"_2r/\M1w y0

        {51Testing软件测试网*@3d LAT ZW'~)KHL

                return new GuiTestObject(getMappedTestObject("document_htmlDocument"));51Testing软件测试网-n G.L(MY{"x4C

        }

s"wt8`L"~ L9h0

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

T J7U4G d`B-zud0

        protected GuiTestObject document_htmlDocument()          {            51Testing软件测试网cyN%M%L7vB.h-\

                  return new GuiTestObject(findTestObjectInBrowser(".class","Html.HtmlDocument",null,null));51Testing软件测试网7|(}?f[$I8pi2pg

    }51Testing软件测试网 Xj$i^,K m

         protected TestObject findTestObjectInBrowser(String property1, String value1, String property2,51Testing软件测试网s5B M]3K"Gv`R O

         String value2)51Testing软件测试网G$j.h8w0wj7M

         {             TestObject[] foundTOs ;

:Ssq"[Zc0

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

lsP,Y8ng#y0G\W:W0

                  if(null==property2)51Testing软件测试网5`/s7[9M,d0O

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

@5NzUn%k0

                  else

"~3@UZ.A]2E c-r8n0

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

Q!t q XQ.f0c0

                  //如果没有找到满足条件的TestObject51Testing软件测试网M%Dc fa5c

                  if(foundTOs.length<1)51Testing软件测试网\vW/C:zv,h@v([

                  {51Testing软件测试网;N0XY/t` K:bt

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

;d/N$?[2g0

                       "+property1+"<"+value1+">,"+property2+"<"+value2+">");51Testing软件测试网~4v-\Jx/I$g8p]%s

             }                  //如果找到多个TestObject满足条件,51Testing软件测试网*K2k9U$w2q iTKx

                  else if(foundTOs.length>1)51Testing软件测试网V/bS!H6KR

                  {51Testing软件测试网.D/L2fU OS

                       throw new AmbiguousRecognitionException("Found multi-TestObject with51Testing软件测试网,\#r5[([bHR | Kn-U

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

q_ e4\Y4gT;^5g0

             }                  //返回唯一的查找结果51Testing软件测试网d8f/B T;}/}(^D} g

                  return foundTOs[0];51Testing软件测试网-W x9G UA%gXAh;L H

         }51Testing软件测试网*H'c$N j4F,a [D

10.添加等待时间51Testing软件测试网 W^_my/c8E

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

"? ~eZp \"pX C#z0

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

_`/WHA8KN ko0

11.如何提高脚本的复用程度和兼容性

;pC9EDepst9E0

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

S0{^s M3W0

12.ComboBox/List Control中提取参数51Testing软件测试网9d;nw+c caZ

import resources.GetListDataExampleHelper;51Testing软件测试网7V#u#xqtC

import com.rational.test.ft.*;
v#L&a0xEI;["Gy0import com.rational.test.ft.object.interfaces.*;51Testing软件测试网0|!zu rM1k Z
import com.rational.test.ft.scrīpt.*;51Testing软件测试网XO0E2A~UGC9t
import com.rational.test.ft.value.*;51Testing软件测试网 P9k+Wd@2Z/h4[xP
import com.rational.test.ft.vp.*;

~ l,| ][*D!k0

public class GetListDataExample extends GetListDataExampleHelper
W8Z2s:i{g0{
\0Ne+O/j!z9I(t0public void testMain (Object[] args)
1vc0il7K0msJ?0{
Q Y#Eqb-eaYn&~(Af0startApp("ClassicsJavaA");

/FMq!M~]i0

// Frame: ClassicsCD51Testing软件测试网+T4mK%Q0Z)f
tree2Tree().click(atPath("Composers->Schubert->Location(PLUS_MINUS)"));
#e$UJ!L8P3h D0tree2Tree().click(atPath("Composers->Schubert->Die schone Mullerin, Op. 25"));51Testing软件测试网Bs&oHF%J%Ml:A
placeOrderButton2Button().click();
51Testing软件测试网8`${%C FS.Qku

//Declare variables for list
]Ia+uF]0ITestDataList nameList;51Testing软件测试网'jM L2L j`G8f
ITestDataElementList nameListElements;51Testing软件测试网,s BN7zQ&e
ITestDataElement nameListElement;

WC+} pG#Pq V0

// Frame: Member Logon
.\r:@2uS o0nameComboComboBox().waitForExistence();
51Testing软件测试网&b6q-J#~ oS

// Available test data types: {selected=Selected List Element, list=List Elements}51Testing软件测试网8b-Md7I1sBL{
java.util.Hashtable ht = nameComboComboBox().getTestDataTypes();51Testing软件测试网2S)DFs!vk5g RFo
System.out.println(ht);
51Testing软件测试网-V'C(BS,|-d Y$F

// Get all elements
i Q@BcYf0nameList = (ITestDataList)nameComboComboBox().getTestData("list");
51Testing软件测试网1{c pq r9x?3j;^

nameListElements = nameList.getElements();

WHzZjJEB3n"g0

int listElemCount = nameList.getElementCount();

]ODa)`'U0

for (int i = 0; i < listElemCount; i++)51Testing软件测试网'B:y)Kn"?5j&w*c5U u
{51Testing软件测试网-Y!u`&W\A8b+e l
nameListElement = nameListElements.getElement(i);
}!i&lw/B$E8fo0System.out.println(nameListElement.getElement());
51Testing软件测试网 So.P1IF5Opg

// Click on each element51Testing软件测试网n1Z2x*zs/@xi v0`
nameComboComboBox().click();51Testing软件测试网@g w$m(yt"zsL
nameComboComboBox().click(atText(nameListElement.getElement().toString()));51Testing软件测试网.UKK)eYf/VWX
};
51Testing软件测试网p'@"H;r&_&g

cancelorderlogonButton().click();51Testing软件测试网*z9K/} Y*D

// Frame: ClassicsCD
5V;X1m X4Wy0ClassicsJavaFrame(ANY,MAY_EXIT).close();51Testing软件测试网6o7w#{FNR
}

@#VHV cB0

}

7o*s_1y:K*}0

 51Testing软件测试网Z)AZ,Wl}Q#N0f


TAG: Rational

 

评分:0

我来说两句

Open Toolbar