RFT读取配置文件的例子.docx
《RFT读取配置文件的例子.docx》由会员分享,可在线阅读,更多相关《RFT读取配置文件的例子.docx(21页珍藏版)》请在冰豆网上搜索。
![RFT读取配置文件的例子.docx](https://file1.bdocx.com/fileroot1/2023-1/5/3cd74b9f-d8fe-4340-b27a-16c1482ff586/3cd74b9f-d8fe-4340-b27a-16c1482ff5861.gif)
RFT读取配置文件的例子
用RFT写的一个动态读取xlsx文件的例子:
RFT框架采用了三层架构:
对象层、任务层和测试用例层。
∙AppObjects:
whereyouwillstoreinformationaboutyourapplication’sGUIelements.ItisalsowhereyouwillwriteyourGetterMethods,whichreturnobjectsenablingtheCallertoqueryandmanipulatetheseGUIelements.Typically,thesemethodsarecalledwithinthe Task layer.
∙Tasks:
whereyouwillwritereusablemethodsthatexercisecommonfunctionsinyourapplication.Itisalsowhereyouwillwritemethodstomanipulateandquerycomplex,application-specificcontrols.MethodsintheTaskarecalledby TestCases.
∙TestCases:
methodsthatnavigatethroughanapplication,verifyitsstate,andlogresults.
对象层:
存储AUT的GUI元素信息,并且由框架自动创建Getter方法用于返回对象。
例如,登录窗口的用户名输入框、密码输入框、确认登录按钮等对象的获取都可放在名为LoginObject的测试脚本中.
packageapplicationOmon;
importlib.ExcelService;
importcom.rational.test.ft.object.interfaces.GuiTestObject;
importcom.rational.test.ft.object.interfaces.TestObject;
importcom.rational.test.ft.object.interfaces.TextGuiTestObject;
publicclassLoginObjectextendsGetterMethod{
publicstaticStringUSERNAME="Email";
publicstaticStringPASSWORD="Passwd";
publicstaticStringSIGNIN="Signin";
publicstaticStringLINK="Gmail";
publicGuiTestObjectgetButton_SignIn()
{
GuiTestObjectgto=getSubmitButton(SIGNIN);
returngto;
}
publicTextGuiTestObjectgetText_Email()
{
TextGuiTestObjectgto=getEditText(USERNAME);
returngto;
}
publicTextGuiTestObjectgetText_passwd()
{
TextGuiTestObjectgto=getEditPassword(PASSWORD);
returngto;
}
publicGuiTestObjectgetlink()
{
GuiTestObjectgto=getObjectLink(LINK);
returngto;
}
}
用例层:
编写测试用例的脚本的地方,一般用于实现业务流程的测试。
packagetestCase;
importresources.testCase.LoginHelper;
importiterator.DataIterator;
importjava.util.HashMap;
importcom.rational.test.ft.*;
importcom.rational.test.ft.object.interfaces.*;
importcom.rational.test.ft.object.interfaces.SAP.*;
importcom.rational.test.ft.object.interfaces.WPF.*;
importcom.rational.test.ft.object.interfaces.dojo.*;
importcom.rational.test.ft.object.interfaces.siebel.*;
importcom.rational.test.ft.object.interfaces.flex.*;
importcom.rational.test.ft.object.interfaces.generichtmlsubdomain.*;
importcom.rational.test.ft.script.*;
importcom.rational.test.ft.value.*;
importcom.rational.test.ft.vp.*;
importcom.ibm.rational.test.ft.object.interfaces.sapwebportal.*;
importapplicationOmon.*;
importlib.*;
importjava.io.InputStream;
importjava.util.Iterator;
importjava.util.List;
importjava.util.Map;
//BEGINcustomimports
//TODO:
Addcustomimportshere.
//ENDcustomimports
/**
*Description:
FunctionalTestScript
*
*@author*******
*/
publicclassLoginextendsLoginHelper{
/**
*ScriptName:
LoginGenerated:
Dec2,20102:
42:
01PM
*Description:
FunctionalTestScriptOriginalHost:
WinNTVersion5.1
*Build2600(S)
*
*@since2010/12/02
*@author***
*/
LoginObjectlf=newLoginObject();
//ExcelDataed=newExcelData();
publicvoidtestMain(Object[]args){
SetGetPropertys=null;
DataLoaddl=newDataLoad();
dl.loadData();
startBrowser("InternetExplorer",dl.getURL());
sleep(10);
lf.getlink().click();
sleep
(1);
try{
s=dl.getProperty("001");
lf.getText_Email().setText(s.getEmail());
lf.getText_passwd().setText(s.getPwd());
}catch(Exceptione){
System.out.println("ReadExcelfialure!
");
}
lf.getButton_SignIn().click();
}
}
属性设置:
SetGetProperty.java
packageapplicationOmon;
importjava.util.HashMap;
publicclassSetGetProperty{
publicStringemail="";//EamilAddress
publicStringpwd="";//Password
publicStringgetEmail(){
returnemail;
}
publicvoidsetEmail(Stringemail){
this.email=email;
}
publicStringgetPwd(){
returnpwd;
}
publicvoidsetPwd(Stringpwd){
this.pwd=pwd;
}
}
Script方法,GetterMethod.java
packageapplicationOmon;
importjava.util.ArrayList;
importjava.util.List;
importlib.ExcelService;
importcom.rational.test.ft.object.interfaces.BrowserTestObject;
importcom.rational.test.ft.object.interfaces.GuiTestObject;
importcom.rational.test.ft.object.interfaces.RootTestObject;
importcom.rational.test.ft.object.interfaces.TestObject;
importcom.rational.test.ft.object.interfaces.TextGuiTestObject;
importcom.rational.test.ft.script.RationalTestScript;
publicclassGetterMethodextendsRationalTestScript{
/**
*htmlBrowser:
withdefaultstate..class:
Html.HtmlBrowser.browserName:
*MSInternetExplorer
*/
protectedBrowserTestObjectbrowser_htmlBrowser(){
returnnewBrowserTestObject(getMappedTestObject("browser_htmlBrowser"));
}
/**
*htmlBrowser:
withspecifictestcontextandstate..class:
*Html.HtmlBrowser.browserName:
MSInternetExplorer
*/
protectedBrowserTestObjectbrowser_htmlBrowser(TestObjectanchor,
longflags){
returnnewBrowserTestObject(
getMappedTestObject("browser_htmlBrowser"),anchor,flags);
}
/*-------------------------FindLinkSTART--------------------------------------*/
/**
*Gmail:
withdefaultstate..text:
Gmail.id:
.href:
*.class:
Html.A.title:
.name
*:
.classIndex:
5
*/
publicGuiTestObjectgetObjectLink(Stringname){
GuiTestObjectlink=null;
RootTestObjecttestObj=getRootTestObject();
try{
link=getObjectLink(".text",name);
}catch(Exceptione){
returnnull;
}
returnlink;
}
publicGuiTestObjectgetObjectLink(Stringname,Stringvalue){
GuiTestObjectlink=null;
RootTestObjecttestObj=getRootTestObject();
try{
link=getObjectLink(null,name,value);
}catch(Exceptione){
returnnull;
}
returnlink;
}
publicGuiTestObjectgetObjectLink(TestObjectroot,Stringname,
Stringvalue){
GuiTestObjectlink=null;
try{
link=getObjectLink(root,name,value,0);
}catch(Exceptione){
returnnull;
}
returnlink;
}
publicGuiTestObjectgetObjectLink(TestObjectroot,Stringname,
Stringvalue,intindex){
GuiTestObjectlink=null;
doubletimer=0;
doubletimeEnd=20;
doubleaddTime=1;
if(root==null){
root=getRootTestObject();
}
try{
while(timerTestObject[]to=root.find(atList(atDescendant(".class",
"Html.A",name,value)));
if(to.length>0){
link=(GuiTestObject)to[index];
link.waitForExistence();
returnlink;
}
sleep(addTime);
timer=timer+addTime;
}
}catch(Exceptione){
returnnull;
}
returnlink;
}
/*-------------------------FindLinkEND--------------------------------------*/
/*--------------------------------------------------------------------------------------------------------*/
/*--------------------------FindTXETBOXSTART-----------------------------------*/
publicTextGuiTestObjectgetEditText(Stringname){
TextGuiTestObjectobj=null;
try{
obj=getEditText(null,".name",name,0);
}catch(Exceptione){
returnnull;
}
returnobj;
}
publicTextGuiTestObjectgetEditText(Stringname,Stringvalue){
TextGuiTestObjectobj=null;
try{
obj=getEditText(null,name,value,0);
}catch(Exceptione){
returnnull;
}
returnobj;
}
publicTextGuiTestObjectgetEditText(TestObjectroot,Stringname,
Stringvalue){
TextGuiTestObjectobj=null;
try{
obj=getEditText(root,name,value,0);
}catch(Exceptione){
returnnull;
}
returnobj;
}
publicTextGuiTestObjectgetEditText(TestObjectroot,Stringname,
Stringvalue,intindex){
TextGuiTestObjectText=null;
doubletimer=0;
doubletimeEnd=20;
doubleaddTime=1;
if(root==null){
root=getRootTestObject();
}
try{
while(timerTestObject[]to=root.find(atList(atDescendant(".class",
"Html.INPUT.text",name,value)));
if(to.length>0){
Text=(TextGuiTestObject)to[index];
Text.waitForExistence();
returnText;
}
sleep(addTime);
timer=timer+addTime;
}
}catch(Exceptione){
returnnull;
}
returnText;
}
/*--------------------------FindTEXTBOXEND-------------------------------------*/
/*--------------------------------------------------------------------------------------------------------*/
/*--------------------------FindTXETPASSWORDSTART-----------------------------------*/
publicTextGuiTestObjectgetEditPassword(Stringname){
TextGuiTestObjectobj=null;
try{
obj=getEditPassword(null,".name",name,0);
}catch(Exceptione){
returnnull;
}
returnobj;
}
publicTextGuiTestObjectgetEditPassword(Stringname,Stringvalue){
TextGuiTestObjectobj=null;
try{
obj=getEditPassword(null,name,value,0);
}catch(Exceptione){
returnnull;
}
returnobj;
}
publicTextGuiTestObjectgetEditPassword(TestObjectroot,Stringname,
Stringvalue){
TextGuiTestObjectobj=null;
try{
obj=getEditPassword(root,name,value,0);
}catch(Exceptione){
returnnull;
}
returnobj;
}
publicTextGuiTestObjectgetEditPassword(TestObjectroot,Stringname,
Stringvalue,intindex){
TextGuiTestObjectTextPwd=null;
doubletimer=0;
doubletimeEnd=20;
doubleaddTime=1;
if(root==null){
root=getRootTestObject();
}
try{
while(timerTestObject[]to=root.find(atList(atDescendant(".class",
"Html.INPUT.password",name,value)));
if(to.length>0){
TextPwd=(TextGuiTestObject)to[index];
TextPwd.waitForE