use of org.sakuli.exceptions.SakuliCheckedException 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!");
SakuliCheckedException causingError = new SakuliCheckedException(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 (Exception e) {
sakuliExceptionHandler.handleException(e);
} finally {
logger.info("test suite finished");
// shutdown sahi proxy!
sahiProxy.shutdown();
}
}
use of org.sakuli.exceptions.SakuliCheckedException in project sakuli by ConSol.
the class CommandLineUtil method runCommand.
public static CommandLineResult runCommand(String command, boolean throwException) throws SakuliCheckedException {
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 SakuliCheckedException(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.SakuliCheckedException in project sakuli by ConSol.
the class Application method killAppName.
private Application killAppName(String name) throws SakuliCheckedException {
try {
String cmd = String.format(Settings.isWindows() ? "Taskkill /IM \"%s\" /F" : "pkill \"%s\"", name);
CommandExecutorHelper.execute(cmd, 0);
} catch (Exception e) {
throw new SakuliCheckedException(e, String.format("could not kill application with name '%s'.", name));
}
return this;
}
use of org.sakuli.exceptions.SakuliCheckedException in project sakuli by ConSol.
the class ImageLib method addImagesFromFolder.
/**
* Helper methode to load all png images from folders as {@link ImageLibObject}
*
* @param paths multiple path to image folders
*/
public void addImagesFromFolder(Path... paths) throws IOException {
for (Path path : paths) {
logger.info("load all pics from \"" + path.toString() + "\" in picLib");
DirectoryStream<Path> directory = Files.newDirectoryStream(path);
for (Path file : directory) {
if (!Files.isDirectory(file)) {
try {
ImageLibObject imageLibObject = new ImageLibObject(file);
if (imageLibObject.getId() != null) {
put(imageLibObject.getId(), imageLibObject);
}
} catch (SakuliCheckedException e) {
logger.error(e.getMessage());
}
}
}
}
}
use of org.sakuli.exceptions.SakuliCheckedException in project sakuli by ConSol.
the class CommonResultServiceImplTest method testSaveAllResults.
@Test(dataProvider = "states")
public void testSaveAllResults(TestSuiteState testSuiteState, TestCaseState testCaseState, String stateOutputRegex) throws Exception {
TestCaseStepState stepState = TestCaseStepState.WARNING;
TestSuite testSuite = new TestSuiteExampleBuilder().withId("LOG_TEST_SUITE").withState(testSuiteState).withException(testSuiteState.isError() ? new SakuliCheckedException("TEST") : null).withTestCases(Collections.singletonList(new TestCaseExampleBuilder().withTestCaseSteps(Collections.singletonList(new TestCaseStepExampleBuilder().withState(stepState).buildExample())).withState(testCaseState).buildExample())).buildExample();
Path logfile = Paths.get(properties.getLogFile());
testling.tearDown(Optional.of(testSuite));
String lastLineOfLogFile = getLastLineOfLogFile(logfile, testSuiteState.isError() ? 42 : 39);
List<String> regExes = getValidationExpressions(testSuiteState, testCaseState, stepState, stateOutputRegex, "TEST");
List<String> strings = Arrays.asList(lastLineOfLogFile.split("\n"));
Iterator<String> regExIterator = regExes.iterator();
verifyOutputLines(strings, regExIterator);
}
Aggregations