use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class SahiConnector method startSahiTestSuite.
/**
* starts a specific sahi test suite in sakuli
*/
public void startSahiTestSuite() throws SakuliInitException {
logger.info("Start Sakuli-Test-Suite from folder \"" + testSuite.getTestSuiteFolder().toAbsolutePath().toString() + "\"");
checkTestSuiteFile();
// ConnectionTester.checkTestCaseInitURL(testSuite);
//default sahi runner to play the sahi script
TestRunner runner = getTestRunner();
runner.setIsSingleSession(false);
//config reporter
runner.addReport(new Report("html", sakuliProperties.getLogFolder().toAbsolutePath().toString()));
//add include folder property
runner.setInitJS(getInitJSString());
try {
//is there to handle exceptions in the catch block from this.reconnect()
try {
countConnections++;
// Script-Runner starts
logger.info("Sahi-Script-Runner starts!\n");
//starts the script runner with the prefilled configurations
String output = runner.execute();
testSuite.setStopDate(new Date());
logger.info("test suite '" + testSuite.getId() + "' stopped at " + TestSuite.GUID_DATE_FORMATE.format(testSuite.getStopDate()));
logger.info("Sahi-Script-Runner executed with " + output);
//should only thrown if an exception could fetched by the backend of some reason
if (output.equals("FAILURE")) {
if (isSahiScriptTimout(testSuite.getException())) {
logger.warn("Sahi-Script-Runner timeout detected, start retry!");
SakuliException causingError = new SakuliException(testSuite.getException());
//reset all values
InitializingServiceHelper.invokeInitializingServcies();
this.reconnect(causingError);
} else if (testSuite.getException() == null) {
throw new SakuliInitException("SAHI-Proxy returned 'FAILURE' ");
}
}
} catch (ConnectException | IllegalMonitorStateException e) {
//Reconnect - wait for Thread "sahiRunner"
this.reconnect(e);
}
} catch (Throwable e) {
sakuliExceptionHandler.handleException(e);
} finally {
logger.info("test suite finished");
//shutdown sahi proxy!
sahiProxy.shutdown();
}
}
use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class Application method killAppPID.
private Application killAppPID(Integer pid) throws SakuliException {
try {
String cmd = String.format(Settings.isWindows() ? "Taskkill /PID %d /F" : "kill -9 %d", pid);
CommandExecutorHelper.execute(cmd, 0);
} catch (Exception e) {
throw new SakuliException(e, String.format("could not kill application with PID '%d'.", pid));
}
return this;
}
use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class CommandLineUtil method runCommand.
public static CommandLineResult runCommand(String command, boolean throwException) throws SakuliException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ByteArrayOutputStream error = new ByteArrayOutputStream();
CommandLineResult result = new CommandLineResult();
try {
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(outputStream, error));
int exitCode = executor.execute(CommandLine.parse(command));
result.setExitCode(exitCode);
result.setOutput(error.toString() + outputStream.toString());
} catch (Exception e) {
if (throwException) {
throw new SakuliException(e, String.format("Error during execution of command '%s': %s", command, error.toString()));
}
result.setExitCode(resolveExitCode(e.getMessage()));
result.setOutput(e.getMessage());
}
return result;
}
use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class TestSuiteTest method testGetExceptionMessage.
@Test
public void testGetExceptionMessage() {
TestSuite testSuite = new TestSuite();
String message = "suite-exception";
testSuite.addException(new SakuliException(message));
assertEquals(testSuite.getExceptionMessages(false), message);
assertEquals(testSuite.getExceptionMessages(true), message);
TestCase tc1 = new TestCase("case1", "case1");
String messageCase = "case-exception";
tc1.addException(new SakuliException(messageCase));
testSuite.addTestCase(tc1.getId(), tc1);
assertEquals(testSuite.getExceptionMessages(false), message + "\n" + "CASE \"" + tc1.getId() + "\": " + messageCase);
assertEquals(testSuite.getExceptionMessages(true), message + " -- CASE \"" + tc1.getId() + "\": " + messageCase);
}
use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class TestSuiteTest method testGetExceptionMessageWithErrorInStep.
@Test
public void testGetExceptionMessageWithErrorInStep() {
TestSuite testSuite = new TestSuite();
String message = "suite-exception";
testSuite.addException(new SakuliException(message));
assertEquals(testSuite.getExceptionMessages(false), message);
assertEquals(testSuite.getExceptionMessages(true), message);
TestCase tc1 = new TestCase("case1", "case1");
String messageCase = "case-exception";
tc1.addException(new SakuliException(messageCase));
testSuite.addTestCase(tc1.getId(), tc1);
TestCaseStep step1 = new TestCaseStepBuilder("step1").build();
String messageStep = "step-exception";
step1.addException(new SakuliException(messageStep));
tc1.addStep(step1);
assertEquals(testSuite.getExceptionMessages(false), message + "\n" + "CASE \"" + tc1.getId() + "\": " + messageCase + "\n\tSTEP \"" + step1.getId() + "\": " + messageStep);
assertEquals(testSuite.getExceptionMessages(true), message + " -- CASE \"" + tc1.getId() + "\": " + messageCase + " - STEP \"" + step1.getId() + "\": " + messageStep);
tc1.exception = null;
assertEquals(testSuite.getExceptionMessages(false), message + "\n" + "CASE \"" + tc1.getId() + "\": " + "\n\tSTEP \"" + step1.getId() + "\": " + messageStep);
assertEquals(testSuite.getExceptionMessages(true), message + " -- CASE \"" + tc1.getId() + "\": " + "STEP \"" + step1.getId() + "\": " + messageStep);
testSuite.exception = null;
assertEquals(testSuite.getExceptionMessages(false), "CASE \"" + tc1.getId() + "\": " + "\n\tSTEP \"" + step1.getId() + "\": " + messageStep);
assertEquals(testSuite.getExceptionMessages(true), "CASE \"" + tc1.getId() + "\": " + "STEP \"" + step1.getId() + "\": " + messageStep);
}
Aggregations