我从文本文件中输出以下内容:
================================================
guideMenuSuite.mts:
[monkeytalk:run] MonkeyTalk v1.0.11.beta5c_473 - 2012-07-18 11:38:51 MDT - Copyright 2012 Gorilla Logic, Inc. - www.gorillalogic.com
[monkeytalk:run] running suite guideMenuSuite.mts...
[monkeytalk:run] BCOKAS127271: -start suite (1 test)
[monkeytalk:run] BCOKAS127271: 1 : guide_menu.mt
[monkeytalk:run] BCOKAS127271: -> OK
[monkeytalk:run] BCOKAS127271: -end suite
[monkeytalk:run] result: OK
[monkeytalk:run] ...done
=================================================
在 Java 中,我需要: 1)解析设备序列号的输出(在这种情况下为 BCOKAS127271 ......它会根据正在测试的设备而变化)。2) 获取->(本例中为-> OK)之后的测试状态结果。
我尝试使用拆分,但数据一直为空...
任何建议将不胜感激。
这是我的代码:
代码
while ((strLine = br.readLine()) != null)
{
maintextarea.append(strLine + "\n");
System.out.println(strLine);
System.out.flush();
maintextarea.append(selectedSerial);
delims = "[ \\->]+";
//String[] tokens = strLine.split(delims);
//String[] tokens = strLine.substring(prefix.length()).split(delims);
String noprefixStr = strLine.substring(strLine.indexOf(prefix) + prefix.length());
String[] tokens = noprefixStr.split(delims);
//for (String t: tokens)
{
//System.out.println(t);
if (tokens.toString().contains("ERROR"))
{
testStatus = "ERROR";
maintextarea.append("\n" + selectedValue + " " + selectedSerial + " = " + testStatus + "\n");
System.out.println(selectedValue + " " + selectedSerial + " = " + testStatus);
System.out.flush();
}
else if (tokens.toString().contains("FAILURE"))
{
testStatus = "FAILED";
maintextarea.append("\n" + selectedValue + " " + selectedSerial + " = " + testStatus + "\n");
System.out.println(selectedValue + " " + selectedSerial + " = " + testStatus);
System.out.flush();
}
else if (tokens.toString().contains("OK"))
{
testStatus = "PASSED";
maintextarea.append("\n" + selectedValue + " " + selectedSerial + " = " + testStatus + "\n");
System.out.println(selectedValue + " " + selectedSerial + " = " + testStatus);
System.out.flush();
}
else
{
testStatus = "N/A";
maintextarea.append("\n" + selectedValue + " " + selectedSerial + " = " + testStatus + "\n");
System.out.println(selectedValue + " " + selectedSerial + " = " + testStatus);
System.out.flush();
}
}
}
br.close();
==================================================== ==========
更新:
我根据从这个小组收到的所有意见找到了我的解决方案!我最终使它变得非常简单并解析输出文件以获取表达式,然后基于该设置一个变量来传递或失败或错误。
这是我使用的基本代码:
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream("/home/ironmantis7x/Documents/TWC_test/MT_test_runner_output.txt"))));
String strLine;
while ((strLine = br.readLine()) != null)
{
if (strLine.contains("-> OK"))
{
testStatus = "Pass";
System.out.println("Test Result = " + testStatus);
}
}
}
catch (FileNotFoundException ex)
{
Logger.getLogger(parseFile.class.getName()).log(Level.SEVERE, null, ex);
}
对不起,我花了这么长时间才回复你们并说谢谢!
铁螳螂7x