RFT框架

TIB發表於2010-01-22

最近分析了一下IBM框架(也叫ITCL框架)。

http://www.ibm.com/developerworks/rational/library/06/0822_goel/

 

這個框架採用了三層架構:物件層、任務層和測試用例層。

  • AppObjects: where you will store information about your application’s GUI elements. It is also where you will write your Getter Methods, which return objects enabling the Caller to query and manipulate these GUI elements. Typically, these methods are called within the Task layer.
  • Tasks: where you will write reusable methods that exercise common functions in your application. It is also where you will write methods to manipulate and query complex, application-specific controls. Methods in the Task are called by Test Cases.
  • Test Cases: methods that navigate through an application, verify its state, and log results.

 

物件層:儲存AUTGUI元素資訊,並且由框架自動建立Getter方法用於返回物件。例如,登入視窗的使用者名稱輸入框、密碼輸入框、確認登入按鈕等物件的獲取都可放在名為Login的測試指令碼中,Login放在名為AppObject的包裡。

    public WButton getButton_signInsubmit() {

        TestObject to = button_signInsubmit(ANY, NO_STATE);

        return new WButton(to);

    }

 

    public WTextField getText_login() {

        TestObject to = text_login(ANY, NO_STATE);

        return new WTextField(to);

    }

 

    public WTextField getText_passwd() {

        TestObject to = text_passwd(ANY, NO_STATE);

        return new WTextField(to);

    }

 

任務層:在這一層中編寫可重用的方法用於執行鍼對AUT的通用功能。例如,在LoginTask中編寫AssignLoginInfo方法用於登入時的使用者名稱和密碼輸入的指令碼。這些指令碼都統一放在名為Tasks的包裡。

    //DECLARE THE OBJECT OF THE SCRIPTS EXIST IN APPOBJECT

    public AppObject.Login lgn = new AppObject.Login();

   

    public void AssignLoginInfo()

    {

        lgn.getText_login().setText("abc");

        lgn.getText_passwd().setText("New1");      

    }

 

用例層:編寫測試用例的指令碼的地方,一般用於實現業務流程的測試。例如,在YahooLogin指令碼中實現登入的全過程。這些指令碼都統一放在名為TestCase的包裡。

 

    //DECLARE THE OBJECT OF THE SCRIPTS EXIST IN TASKS

    //OBJECT CREATION OF TASKS LOGINTASK SCRIPT

    public Tasks.LoginTask lt = new Tasks.LoginTask();

 

    public void testMain(Object[] args)

    {

        //INVOKING THE BROWSER

        startBrowser("mail.yahoo.com");

        //ASSIGNED THE USER NAME AND LOGIN INFO

        lt.AssignLoginInfo();

        //CLICKED ON LOGIN/SUBMIT BUTTON

        lt.lgn.getButton_signInsubmit().click();

        //FURTHER ACTION CAN BE WRITTEN ACCORDIUNLGY

        //...

    }

 

這樣的框架的好處是:

1、分層的架構

2、把“what”從“how”中抽離出來

3、程式碼重用

4、一致和清晰的結構

5、有效的檔案組織

6

 

關於分層的思想,這篇文章也值得一看:

http://www.ibm.com/developerworks/cn/rational/r-cn-rftwindows1/

 

 

 

相關文章