示例:添加新测试对象

此示例说明如何添加新测试对象。

关于此任务

要创建、构建和部署测试对象:

过程

  1. 创建测试对象的构造函数。

    此示例代码显示了 Java™ 测试对象:

    package sdk.sample;
    
    import com.rational.test.ft.object.interfaces.*;
    import com.rational.test.ft.object.TestObjectReference;
    import com.rational.test.ft.object.map.SpyMappedTestObject;
    
    public class ExtendedGuiTestObject extends GuiTestObject{
    
    	// FIVE Standard Contructors,  has to be defined in every new TestObject
    
    	public ExtendedGuiTestObject(SpyMappedTestObject mappedObject)
    	{
    		super(mappedObject);
    	}
    	
    	public ExtendedGuiTestObject(SpyMappedTestObject mappedObject, TestObject anchor)
    	{
    		super(mappedObject, anchor);
    	}
    	
    	public ExtendedGuiTestObject(SpyMappedTestObject mappedObject, 
    									TestObject anchor,
    									long scriptCommandFlags)
    	{
    		super(mappedObject, anchor, scriptCommandFlags);
    	}
    	
    	public ExtendedGuiTestObject(TestObjectReference ref) 
    	{
    		super(ref);
    	}
    
    	public ExtendedGuiTestObject(TestObject obj) 
    	{
    		super(obj);
    	}
    
         
           // Newly added Method for this TestObejct,  just a call forwarder using invokeProxy API
    	
    	public void performClick()
    	{
    		invokeProxy("performClick");
    	}
    }

    此示例代码显示了 .Net 测试对象:

    using TestObjectReference = Rational.Test.Ft.Object.TestObjectReference;
    using Rational.Test.Ft.Object.Interfaces;
    using Rational.Test.Ft.Object.Manager;
    using Rational.Test.Ft.Object.Map;
    
    namespace SDK.Sample
    {
    
    	public class ExtendedGuiTestObject:GuiTestObject
    	{
    		// FIVE Standard Contructors,  has to be defined in every new TestObject
    		public ExtendedGuiTestObject(SpyMappedTestObject mappedObject):base (mappedObject) {
    		}
    
    		public ExtendedGuiTestObject(SpyMappedTestObject mappedObject, TestObject anchor)
    			:base (mappedObject, anchor){
    		}
    
    		public ExtendedGuiTestObject(SpyMappedTestObject mappedObject, TestObject anchor, 
    			long scriptCommandFlags):base (mappedObject, anchor, scriptCommandFlags) {
    		}
    
    		public ExtendedGuiTestObject(TestObjectReference ref_Renamed):base (ref_Renamed) {
    		}
    
    		public ExtendedGuiTestObject(TestObject obj):base (obj) {
    		}
    
    		// Newly added Method for this TestObejct,  just a call forwarder using InvokeProxy API
    
    		public virtual void PerformClick()	{
    			InvokeProxy("performClick");
    		}
    	}
    }
  2. 为定制文件中的测试对象定义新的规范名称。

    此示例显示如何为测试对象定义新的规范名称:

    <?xml version="1.0" encoding="UTF-8"?>
    <ConfigFile L=".ConfigFile">
    	<Section L=".ConfigFileSection">
    		<Name>proxies</Name>
    		<Val L=".ProxyManager">
    			<DomainImplementation L=".DomainImplementation">
    				<Name>Net</Name>
    				<Obj L=".Proxy">
    					<ClassName>[NETProxyExtension]SDK.Sample.TestButtonProxy</ClassName>
    					<Replaces/>
    					<UsedBy>Rational.Controls.CustomButton</UsedBy>
    				</Obj>
    			</DomainImplementation>
    		</Val>
    	</Section>
    	<Section L=".ConfigFileSection">
    		<Name>testObjects</Name>
    		<Val L=".TestObjectManager">
    			<ComponentModel L=".ComponentModel">
    				<Name>Java</Name>
    			</ComponentModel>
    			<ComponentModel L=".ComponentModel">
    				<Name>Net</Name>
    				<Obj L=".TestObject">
    					<CanonicalName>ExtendedGuiTestObject</CanonicalName>
    					<TestObject>[NETProxyExtension]SDK.Sample.ExtendedGuiTestObject</TestObject>
    				</Obj>
    			</ComponentModel>
                            <ComponentModel L=".ComponentModel">
    				<Name>Java</Name>
    				<Obj L=".TestObject">
    					<CanonicalName>ExtendedGuiTestObject</CanonicalName>
    					<TestObject>sdk.sample.ExtendedGuiTestObject</TestObject>
    				</Obj>
    			</ComponentModel>
    		</Val>
    	</Section>
    </ConfigFile>
  3. 到新创建测试对象的映射代理。

    此示例显示 Java 代理源覆盖 getTestObjectClassName() 方法:

    import com.rational.test.ft.domain.*;
    .
    .
    public String getTestObjectClassName()
    {
        return "ExtendedGuiTestObject";  //  the canonical name for the newly created testObject
    }

    此示例显示 .Net 代理覆盖 GetTestObjectClassName() 方法:

    using Rational.Test.Ft.Domain;.
    .
    public override System.String GetTestObjectClassName()
    {
       return "ExtendedGuiTestObject";  //  the canonical name for the newly created testObject 
    }
  4. 构建测试对象二进制文件。
  5. 复制测试对象二进制文件到 Functional Tester 定制目录 (C:\Documents and Settings\All Users\Application Data\IBM\RFT\customization) 来部署文件。
  6. 重新启动 Functional Tester

反馈