2012-08-09 54 views
0

Rational Functional Tester腳本如何判斷它在哪個版本的RFT上執行/構建?如何獲得RFT版本號?

我通過文檔挖,和最近我發現了

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

返回OS版本信息,這可能是接近,但仍然沒有什麼爸爸正在尋找;Ø

回答

1

我沒在API或Windows註冊表中找不到任何東西。

我能想到的唯一方法就是創建一個自定義方法並將其包含在你的助手類中。 您可以在文件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。 作爲替代,加載該文件的內容爲字符串,並用一個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)前往幫助>關於RFT,它顯示版本。