File configFile = null;
try {
configFile = TestRunnerConfLocator.getTestRunnerConf();
} catch (FileNotFoundException ex)
{
throw new CommandOperationException(ex);
}
File resultDir = getResultsDir();
JSAP argsParser = createArgsParser(mode);
JSAPResult config = argsParser.parse(args);
boolean success = true;
if (!config.success())
{
throw new CommandArgumentsException("Invalid arguments provided.", testCommand);
}
else
{
TestRunner testRunner;
try
{
boolean testServerOnly = mode == RunMode.RUN_SERVER;
boolean generateReports = (mode == RunMode.RUN_TESTS) && config.getBoolean(REPORT_SWITCH);
boolean noBrowser = (mode == RunMode.RUN_SERVER) && config.getBoolean(NO_BROWSER_SWITCH);
testRunner = new TestRunner(configFile, resultDir, Arrays.asList(config.getStringArray("browsers")), testServerOnly, noBrowser, generateReports);
}
catch (Exception ex)
{
throw new CommandOperationException("Error parsing test runner configuration file '" + configFile.getAbsolutePath() + "'.", ex);
}
if (mode == RunMode.RUN_SERVER)
{
try
{
testRunner.runServer();
}
catch (Exception ex)
{
throw new CommandOperationException("Error running server.", ex);
}
}
else
{
try
{
success = testRunner.runTests(new File(config.getString("dir")), getTestTypeEnum(config.getString("testType")));
}
catch (Exception ex)
{
testRunner.showExceptionInConsole(ex);
throw new CommandOperationException("Error running tests.", ex);
}
}
}
if (!success) { return 1; }
return 0;