executionSteps) {
// length() trick: it's necessary as there sounds to be a bug in java where exists() always
// returns false or true if the file in mapped on a remote network drive
if (!seleniumServerReportFile.exists() || seleniumServerReportFile.length() <= 1) {
traceln(LOG_PRIORITY_SEVERE, "Result file not found!");
executionSteps.add(new CExecutionStep(RESULT_FAILURE, "selenium server probably crashed!"));
executionSteps.add(new CExecutionStep(RESULT_FAILURE, "run: report not found!"));
return new CReturnStatus(RESULT_FAILURE, executionSteps);
} else {
executionSteps.add(new CExecutionStep(RESULT_NOT_EXECUTED, "run: result file found"));
}
String line;
boolean errorDetected = false;
try {
FileInputStream fileInputStream = new FileInputStream(seleniumServerReportFile);
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!");
}
}
bufferedReader.close();
fileInputStream.close();
} 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);
}
}
}
|