문제

How can a Rational Functional Tester script figure out under which version of RFT it executes/was built with?

I digged through the documentation, and the closest I found was

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

which returns OS version info, which might be close, but still not what Daddy is looking for ;O

도움이 되었습니까?

해결책

I didn't find anything in the APIs or in the Windows registry.

The only way I can think of is to create a custom method and include it in you helper class. You can find the versione in the file C:\IBM\SDP\FunctionalTester\properties\version\IBM_Rational_Functional_Tester.*.*.swtag, change the path to match your installation.

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();
    }

This is a quite expensive method, because it istantiates a DocumentBuilder for XML parsing. As an alternative, load the file content as a String and parse it with a RegExp, use this matching pattern: [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) Go to Help> About RFT, it shows the version.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top