在RFT中如何通过脚本获取已添加到某个脚本中的测试对象?

 

如何通过脚本获取已添加到某个脚本中的测试对象?(已添加到脚本中的测试对象在脚本资源管理器中的测试对象节点下会列出来。)

 

下面的脚本将打印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返回对象的类型以及测试对象类名。

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值