Java 如何获取RFT版本号?

Java 如何获取RFT版本号?,java,automated-tests,rft,Java,Automated Tests,Rft,RationalFunctionalTester脚本如何确定它在哪个版本的RFT下执行/构建 我翻遍了文档,找到的最接近的是 com.rational.test.ft.script.ScriptUtilities.getOperatingSystemVersion() 返回操作系统版本信息,可能很接近,但仍然不是爸爸想要的;O我在API或Windows注册表中没有找到任何内容 我能想到的唯一方法是创建一个自定义方法并将其包含在助手类中。 您可以在文件C:\IBM\SDP\Functional

RationalFunctionalTester脚本如何确定它在哪个版本的RFT下执行/构建

我翻遍了文档,找到的最接近的是

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

返回操作系统版本信息,可能很接近,但仍然不是爸爸想要的;O

我在API或Windows注册表中没有找到任何内容

我能想到的唯一方法是创建一个自定义方法并将其包含在助手类中。 您可以在文件
C:\IBM\SDP\FunctionalTester\properties\version\IBM\u Rational\u Functional\u 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。 或者,将文件内容作为字符串加载,并使用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) 转到帮助关于RFT,它会显示版本