在RFT中如何通過指令碼獲取已新增到某個指令碼中的測試物件?

TIB發表於2010-01-21

 

如何通過指令碼獲取已新增到某個指令碼中的測試物件?(已新增到指令碼中的測試物件在指令碼資源管理器中的測試物件節點下會列出來。)

 

下面的指令碼將列印Login指令碼中的測試物件的相關資訊:

        Vector vector = new Vector();

        vector.addElement (new Login());

        Vector testScript = vector;

       

        for(int i = 0; i < testScript.size(); i++)

        {

            if(testScript.elementAt(i) instanceof RationalTestScript)

            {

                RationalTestScript ts = (RationalTestScript)testScript.elementAt(i);

                IScriptDefinition sd = ts.getScriptDefinition();

                Enumeration e = sd.getTestObjectNames();

 

                while(e.hasMoreElements())

                {

                    String currentObjName = (String)e.nextElement();

                    String role = sd.getRole(currentObjName);

                    String mapID = sd.getMapId(currentObjName);

                    String curClassName = (String)ts.getMap().find(mapID).getClassName();

                    String objClassName = (String)ts.getMap().find(mapID).getTestObjectClassName();

                   

                    System.out.println(role);

                    System.out.println(mapID);

                    System.out.println(curClassName);

                    System.out.println(objClassName);

                   

                }

               

            }

               

        }

 

輸出:

Button

B.JGKG3Ig8tvE:kFGtR:MFnGLmf:8WT

Html.INPUT.submit

GuiTestObject

Text

9.JGKG3Ig8tvE:kFGtR:MFnGLmf:8WU

Html.INPUT.text

TextGuiTestObject

Text

A.JGKG3Ig8tvE:kFGtR:MFnGLmf:8WU

Html.INPUT.password

TextGuiTestObject

 

 

其中使用getScriptDefinition 方法來獲取IscriptDefinition型別的物件,也就是指令碼相關的定義物件,其中就包含測試物件。

Persists the definition about the artifacts associated with the script as an object that implements this interface when the script is created or updated. Object-map information is maintained to improve the resilience of scripts relative to changes in shared object maps. Also, verification points and other assocatied artifacts are managed by the script definition interface.

 

再通過getTestObjectNames方法來獲取測試物件的集合。

Returns an enumerator for the TestObject names associated with a script. Each object returned by the enumerator is a java.lang.String value known to be unique relative to a script.

 

對於測試物件集合中的每一個元素,通過getRole方法來獲取測試物件的角色,通過getMapId來獲取測試物件的對映ID

 

通過getMap可返回與測試指令碼關聯的物件對映(object map),再根據MapID,通過find方法查詢返回對映的測試物件,然後通過getClassNamegetTestObjectClassName返回物件的型別以及測試物件類名。

 

相關文章