RFT代码收藏四
上一篇 / 下一篇 2008-06-17 14:00:32 / 个人分类:Rational
1208328177
- 自动化测试:
- 测试文档:
9.使用方法find(Subitem properties)在某个特定范围查找满足条件的所有对象
录制的脚本,使用方法document_htmlDocument()来调用页面的Document对象,使用方法text_q()来调用搜索输入框,使用方法button_search()来调用搜索按钮。这些方法是由脚本SearchLotusLink的父类SearchLotusLinkHelper定义的
protected GuiTestObject document_htmlDocument()
{
return new GuiTestObject(getMappedTestObject("document_htmlDocument"));
}
类:com.rational.test.ft.object.interfaces.TestObject,而它的方法find(Subitem properties)正是用来在某个特定范围内查找满足条件的所有对象。改造后,回放过程中所需要用到的页面对象都是在当前浏览器中即时查找得到的。通过目标对象的类型和某个属性值来定位目标对象
protected GuiTestObject document_htmlDocument() {
return new GuiTestObject(findTestObjectInBrowser(".class","Html.HtmlDocument",null,null));
}
protected TestObject findTestObjectInBrowser(String property1, String value1, String property2,
String value2)
{ TestObject[] foundTOs ;
//在当前浏览器页面中查找
if(null==property2)
foundTOs = browser_htmlBrowser().find(atDescendant(property1,value1)) ;
else
foundTOs = browser_htmlBrowser().find(atDescendant(property1,value1,property2,value2)) ;
//如果没有找到满足条件的TestObject
if(foundTOs.length<1)
{
throw new com.rational.test.ft.ObjectNotFoundException("Can NOT find TestObject with
"+property1+"<"+value1+">,"+property2+"<"+value2+">");
} //如果找到多个TestObject满足条件,
else if(foundTOs.length>1)
{
throw new AmbiguousRecognitionException("Found multi-TestObject with
"+property1+"<"+value1+">,"+property2+"<"+value2+">");
} //返回唯一的查找结果
return foundTOs[0];
}
10.添加等待时间
· 定长等待
y s'[X5K0调用Java脚本的公共父类com.rational.test.ft.scrīpt.RationalTestscrīpt里的方法:sleep(double seconds)。这一方法可以使回放过程等待若干秒。51Testing软件测试网3^fG/D+i1w/iES
这种方式直观、简单。但缺点也是明显的:固定的时间常常不能适应多变的真实环境:等待时间设置得过长,无疑会拉长测试的回放时间,降低效率;等待时间设置得过短,在某些情况下,又无法起到延时应有的效果,仍然错过了被测对象。
· 不定长等待51Testing软件测试网FRw+W(a&LOQpz
脚本记录器记录下的这些页面对象都是从接口com.rational.test.ft.object.interfaces.TestObject继承下来的,在TestObject中有一个方法waitForExistence()可以用以实现不定长的等待。在一定的时间限度内,等待该对象的出现;一旦出现后就不再等待,程序继续往下执行。最大时间限度是在"首选项"的"回放"选项里设置的。不定长等待既达到灵活等待的目的,又没有浪费不必要的等待时间,是一个值得推荐的解决方案。
11.如何提高脚本的复用程度和兼容性
充分利用Rational Functional Tester的强大功能,比如scrīptAssure技术、正则表达式,数据驱动,Rational Functional Tester API等;2)合理地编写、优化脚本。提纲挈领地对测试过程进行抽象,对关键过程进行必要的验证。
12.ComboBox/List Control中提取参数
import resources.GetListDataExampleHelper;
import com.rational.test.ft.*;
v#L&a0xEI;["Gy0import com.rational.test.ft.object.interfaces.*;51Testing软件测试网0|!zurM1k
Z
import com.rational.test.ft.scrīpt.*;51Testing软件测试网XO0E2A~UGC9t
import com.rational.test.ft.value.*;51Testing软件测试网
P9k+Wd@2Z/h4[x P
import com.rational.test.ft.vp.*;
public class GetListDataExample extends GetListDataExampleHelper
W8Z2s:i {g0{
\0Ne+O/j!z9I(t0public void testMain (Object[] args)
1vc0il7K0ms J?0{
Q Y#Eqb-eaYn&~(A f0startApp("ClassicsJavaA");
// Frame: ClassicsCD51Testing软件测试网+T4mK%Q0Z)f
tree2Tree().click(atPath("Composers->Schubert->Location(PLUS_MINUS)"));
#e$UJ!L8P3hD0tree2Tree().click(atPath("Composers->Schubert->Die schone Mullerin, Op. 25"));51Testing软件测试网Bs&oHF%J%Ml:A
placeOrderButton2Button().click();
//Declare variables for list
]Ia+uF]0ITestDataList nameList;51Testing软件测试网'jM
L2L j`G8f
ITestDataElementList nameListElements;51Testing软件测试网,s BN7zQ&e
ITestDataElement nameListElement;
// Frame: Member Logon
.\r:@2uSo0nameComboComboBox().waitForExistence();
// 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);
// Get all elements
iQ @BcYf0nameList = (ITestDataList)nameComboComboBox().getTestData("list");
nameListElements = nameList.getElements();
int listElemCount = nameList.getElementCount();
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());
// 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
};
cancelorderlogonButton().click();
// Frame: ClassicsCD
5V;X1m X4Wy0ClassicsJavaFrame(ANY,MAY_EXIT).close();51Testing软件测试网6o7w#{FNR
}