我如何获得RFT版本号?

时间:2012-08-09 15:51:01

标签: java automated-tests rft

Rational Functional Tester脚本如何确定它在哪个版本的RFT下执行/构建?

我浏览了文档,我找到的最接近的是

com.rational.test.ft.script.ScriptUtilities.getOperatingSystemVersion() 

返回操作系统版本信息,可能很接近,但仍然不是Daddy正在寻找的; O

2 个答案:

答案 0 :(得分:1)

我在API或Windows注册表中找不到任何内容。

我能想到的唯一方法是创建一个自定义方法并将其包含在helper类中。 您可以在文件C:\IBM\SDP\FunctionalTester\properties\version\IBM_Rational_Functional_Tester.*.*.swtag中找到版本,更改路径以匹配您的安装。

import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

private final static String RFTVersionFolder = "C:\\IBM\\SDP\\FunctionalTester\\properties\\version";

public static String getRFTVersionWithXML() {
        File versionFolder = new File(RFTVersionFolder);
        File[] versionFile = versionFolder.listFiles( new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return (name.endsWith(".swtag"));
                } } );

        Document versionDocument = null;
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        try {
            DocumentBuilder builder = factory.newDocumentBuilder();
            versionDocument = builder.parse(new FileInputStream(versionFile[0]));
        } catch (SAXParseException spe) {
            spe.printStackTrace();
        } catch (SAXException sxe) {
            sxe.printStackTrace();
        } catch (ParserConfigurationException pce) {
            pce.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }

        Node versionNode = versionDocument.getElementsByTagName("ProductVersion").item(0);

        return versionNode.getTextContent();
    }

这是一种非常昂贵的方法,因为它是用于XML解析的DocumentBuilder。 作为替代方案,将文件内容作为String加载并使用RegExp对其进行解析, 使用此匹配模式:[0-9] \。[0-9] \。[0-9]

public static String getRFTVersionWithRegexp() {
    File versionFolder = new File(RFTVersionFolder);
    File[] versionFile = versionFolder.listFiles( new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return (name.endsWith(".swtag"));
        } } );

    byte[] buffer = null;
    FileInputStream fin;
    try {
        fin = new FileInputStream(versionFile[0]);
        buffer = new byte[(int) versionFile[0].length()];
        new DataInputStream(fin).readFully(buffer);
        fin.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } 
    String versionFileContent = new String(buffer);
    String version = null;
    Regex r = new Regex("[0-9]\\.[0-9]\\.[0-9]", Regex.MATCH_NORMAL);
    if (r.matches(versionFileContent))
        version = r.getMatch();

    return version;
}

答案 1 :(得分:1)

1)转到帮助> 关于RFT ,它会显示版本。

相关问题