| xml 代码 <!--从classpath(类路径)中导入base-test-object-map.xml文件 可以使用base-test-object-map.xml文件中定义的bean--> <!--导入时候要包含完整的包名--> <import resource="classpath:pkg/base-test-object-map.xml"/> <!--设置待查找对象的识别属性 格式:propertyName-propertyValue--> <property name="objectProperties"> <list> <!--属性名称和属性精确匹配用=--> <!--属性名称和属性用正则表达式匹配用:--> <value>.class=Html.FORMvalue> 然后是怎么使用spring配置文件中的测试对象 <value>.name:.*Formvalue> list> property> <!--设置从什么对象开始查找 注入父测试对象--> <!--browserTestObject 引用的是base-test-object-map.xml文件中已经定义的bean--> <property name="parentTestObject"> <ref bean="browserTestObject"/> property> |
| java 代码 TextGuiTestObject text_userName = new TextGuiTestObject((TestObject)context.getBean("userNameText")); text_userName.setText("system"); |
| base-test-object-map.xml 代码 xml 代码 <!--sp-->xml version="1.0" encoding="gb2312"?> <!--CTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" </sp--> "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!--注册com.rational.test.ft.script.Property属性编辑器--> <bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer"> <property name="customEditors"> <map> <entry key="com.rational.test.ft.script.Property"> <bean class="pkg.TestObjectPropertyEditor"/> entry> map> property> bean> <!--实例化pkg.BaseTestObjectScript类--> <bean id="baseTestObjectScript" class="pkg.BaseTestObjectScript"/> <!--调用baseTestObjectScript中的非静态方法getBrowserTestObject产生一个BrowserTestObject测试对象--> <bean id="browserTestObject" factory-bean="baseTestObjectScript" factory-method="getBrowserTestObject" singleton="false"/> <!--调用baseTestObjectScript中的非静态方法getDocumentTestObject产生一个DocumentTestObject测试对象--> <bean id="documentTestObject" factory-bean="baseTestObjectScript" factory-method="getDocumentTestObject" singleton="false"/> beans> |