* @return true if success, false otherwise
*/
public boolean execute(boolean debug) {
final String INTERACTIVE_REPORT_NAME = "Interactive";
boolean returnStatus = true;
TestResultsReportManager reportManager = TestResultsReportManager.getInstance();
if (testSuite == null &&
(reportManager.getReportName() == null || reportManager.getReportName().equals(INTERACTIVE_REPORT_NAME)) ) {
reportManager.startReport(new Date(), INTERACTIVE_REPORT_NAME);
}
testResults = new LinkedList<TestResult>();
for (TestData data : ds.getData()) {
if (data.isSelected()) {
data.setTestCaseDirectory(fileName.toString());
data.loadFileIfAny();
TestResult.Status status = TestResult.Status.NOT_EXECUTED;
int trial = 0;
boolean needToRetry = false;
// Retry the script "RETRY_COUNTER" times in case of failure
do {
if (TestEngine.needToRestartSUT()) {
logger.info("SUT has to be restarted");
if (!TestEngine.restartSUT()) {
logger.fatal("Failed to restart SUT - exiting");
return false;
}
}
if (trial == 0) {
logger.info("Executing test script: " + getName() + " (row " + data.getRowId() + ")");
} else {
logger.info("Retrying test script: " + getName() + " (row " + data.getRowId() + ") after SUT restart");
if (testSuite != null) {
testSuite.reportTestRetry();
}
}
TestResult testResult = initTestResult(data, requirements, trial, reportManager, ds.getData().indexOf(data), ds.getData().size());
testResults.add(testResult);
int timeout = DEFAULT_TIMEOUT;
if (debug) {
logger.info("Not using test timeout because running in debug mode");
} else {
try {
timeout = data.getIntValue("TIMEOUT");
logger.info("Using test timeout of " + timeout + " seconds");
timeout = timeout * 1000;
} catch (QTasteDataException e) {
if (e.getMessage().contains("doesn't contain")) {
logger.info("No TIMEOUT test data, using default test timeout (" + DEFAULT_TIMEOUT / 1000 + " seconds)");
} else {
logger.error(e.getMessage() + ". Using default test timeout (" + DEFAULT_TIMEOUT / 1000 + " seconds)");
}
}
}
TaskThread taskThread = new TaskThread(debug, data, testResult, timeout);
// clear cache history
CacheImpl.getInstance().clearHistory();
// initialize instantiated components
testAPI.initializeComponents();
testResult.start();
// wait till the end of the Task or Timeout
reportManager.putEntry(testResult);
taskThread.start();
boolean taskThreadTerminated = taskThread.waitForEnd();
reportManager.refresh();
// terminate instantiated components
testAPI.terminateComponents();
// exit QTaste if test thread couldn't be stopped, because we are in an unstable state