gpt4 book ai didi

java - 如何获取 RFT 版本号?

转载 作者:行者123 更新时间:2023-12-02 07:38:30 30 4
gpt4 key购买 nike

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

我仔细研究了文档,发现最接近的是

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

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

最佳答案

我在 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。作为替代方案,将文件内容加载为字符串并使用正则表达式对其进行解析,使用此匹配模式:[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;
}

关于java - 如何获取 RFT 版本号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11887180/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com