executionSteps) {
// parse the result file to get the result and the execution steps
File resultFile = new File("selenium_server_report.html");
if (!resultFile.exists()) {
traceln(LOG_PRIORITY_SEVERE, "Result file not found!");
executionSteps.add(new CExecutionStep(RESULT_FAILURE, "run: result file not found!"));
return new CReturnStatus(RESULT_FAILURE, executionSteps);
} else {
executionSteps.add(new CExecutionStep(RESULT_SUCCESS, "run: result file found"));
}
String line;
boolean errorDetected = false;
try {
FileInputStream fileInputStream = new FileInputStream(resultFile);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
while ((line = bufferedReader.readLine()) != null) {
line = line.trim();
System.out.println(">" + line);
if (line.startsWith("| result: | ")) {
line = bufferedReader.readLine().trim();
String globalResult = line.substring(4, line.length()-5);
if (globalResult.equalsIgnoreCase("passed")) {
executionSteps.add(new CExecutionStep(RESULT_SUCCESS, "Result: " + globalResult));
} else {
executionSteps.add(new CExecutionStep(RESULT_FAILURE, "Result: " + globalResult));
errorDetected = true;
}
} else if (line.startsWith("totalTime: | ")) {
line = bufferedReader.readLine().trim();
String totalTime = line.substring(4, line.length()-5);
executionSteps.add(new CExecutionStep(RESULT_SUCCESS, "totalTime: " + totalTime));
} else if (line.startsWith("numTestTotal: | ")) {
line = bufferedReader.readLine().trim();
String numTestTotal = line.substring(4, line.length()-5);
executionSteps.add(new CExecutionStep(RESULT_SUCCESS, "numTestTotal: " + numTestTotal));
} else if (line.startsWith("numTestPasses: | ")) {
line = bufferedReader.readLine().trim();
String numTestPasses = line.substring(4, line.length()-5);
executionSteps.add(new CExecutionStep(RESULT_SUCCESS, "numTestPasses: " + numTestPasses));
} else if (line.startsWith("numTestFailures: | ")) {
line = bufferedReader.readLine().trim();
int numTestFailures = Integer.parseInt(line.substring(4, line.length()-5));
executionSteps.add(new CExecutionStep(numTestFailures > 0 ? RESULT_FAILURE: RESULT_SUCCESS, "numTestFailures: " + numTestFailures));
} else if (line.endsWith("status_passed\">")) {
line = bufferedReader.readLine().trim();
String[] array = line.split(">");
String testName = array[1].substring(1, array[1].length()-9);
executionSteps.add(new CExecutionStep(RESULT_SUCCESS, "passed: " + testName));
} else if (line.endsWith("status_failed\"> | ")) {
line = bufferedReader.readLine().trim();
String[] array = line.split(">");
String testName = array[1].substring(1, array[1].length()-9);
executionSteps.add(new CExecutionStep(RESULT_FAILURE, "failed: " + testName));
} else {
//traceln(LOG_PRIORITY_SEVERE, "unknown tag!");
}
}
} catch (Exception e) {
traceln(LOG_PRIORITY_SEVERE, "exception whle parsing the result file: " + e);
executionSteps.add(new CExecutionStep(RESULT_FAILURE, "Exception while parsing the result file: " + e));
errorDetected = true;
}
if (errorDetected) {
return new CReturnStatus(RESULT_FAILURE, executionSteps);
} else{
return new CReturnStatus(RESULT_SUCCESS, executionSteps);
}
}
}
|