RSS
热门关键字:  java  Ajax  JSP  JSF  Struts
当前位置 : 首页>Spring>列表

RFT与Spring结合进行自动化脚本开发之一

来源: 作者: 时间:2007-09-24 点击:

<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>

  base-test-object-map.xml 可以作为公有的测试对象地图,其中customEditorConfigurer向容器注册了一个属性编辑,pkg.BaseTestObjectScript是一个RFT脚本,此脚本有getBrowserTestObject()和documentTestObject(),可以在这个类中放入基本的测试对象,通过Spring将这些对象封装为bean, 然后有其他的spring配置文件来import,这样就实现了对象的继承。pkg.BaseTestObjectScript的代码如下:

  java 代码

package pkg;

import resources.pkg.BaseTestObjectScriptHelper;

import com.rational.test.ft.*;
import com.rational.test.ft.object.interfaces.*;
import com.rational.test.ft.object.interfaces.siebel.*;
import com.rational.test.ft.script.*;
import com.rational.test.ft.value.*;
import com.rational.test.ft.vp.*;

public class BaseTestObjectScript extends BaseTestObjectScriptHelper
{
public void testMain(Object[] args)
{
}

public BrowserTestObject getBrowserTestObject()
{
return browser_htmlBrowser(document_H(),DEFAULT_FLAGS);
}

public GuiTestObject getDocumentTestObject()
{
return document_H();
}
}

  pkg.TestObjectPropertyEditor代码如下,其中如果用精确匹配就用=作为分隔符,如果是通过正则表达式匹配就通过:作为分隔符,然后在程序内部就会做正则表达式的转换。

  java 代码

package pkg;

import com.rational.test.ft.script.Property;
import java.beans.PropertyEditorSupport;
import java.util.StringTokenizer;
import com.rational.test.ft.value.RegularExpression;

public class TestObjectPropertyEditor extends PropertyEditorSupport
{
public void setAsText(String text)
{
String delimiter = null;
Object propValue = null;

if(text == null || text.length() < 1 || (text.indexOf(EQUAL_MARK) == -1 && text.indexOf(COLON) == -1))
{
throw new IllegalArgumentException("识别属性为空或格式不正确 =表示进行精确匹配 :表示使用正则表达式匹配");
}

if(text.indexOf(EQUAL_MARK) != -1)
{
delimiter = EQUAL_MARK;
}
else if(text.indexOf(COLON) != -1)
{
delimiter = COLON;
}

//解析字符串
StringTokenizer st = new StringTokenizer(text, delimiter);
String name = st.nextToken();
String value = st.nextToken();

propValue = value;

if(text.indexOf(COLON) != -1) //如果分隔符为 : 将propValue设置为正则表达式
{
propValue = new RegularExpression(value, false);
}
setValue(new Property(name, propValue));
}

public String getAsText()
{
Property property = (Property)getValue();
return property.getPropertyName() + "-" + property.getPropertyValue();
}

public final String EQUAL_MARK = "="; //"=" 表示进行精确匹配
public final String COLON = ":"; //":" 表示使用正则表达式匹配
}

  然后介绍一下其他的Spring配置文件通过导入另一个Spring配置文件实现,测试对象的继承。如下,通过import另一个配置文件,这个spring配置文件中的对象就可以使用被导入的spring配置文件中的测试对象,从而可以实现测试对象的继承。

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
热点关注
Google Adsense
相关文章