use of org.sakuli.exceptions.SakuliInitException in project sakuli by ConSol.
the class CommonInitializingServiceImpl method initTestSuite.
/**
* {@inheritDoc}
*/
@Override
public void initTestSuite() throws SakuliInitException {
checkConfiguration(testSuite);
logger.info("initialize test suite with id '{}'", testSuite.getId());
testSuite.clearException();
testSuite.setState(TestSuiteState.RUNNING);
testSuite.setStartDate(new Date());
testSuite.setStopDate(null);
try {
testSuite.setHost(InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException e) {
testSuite.setHost("UNKNOWN HOST");
}
/**
* Optional init actions
*/
if (testSuiteProperties.isLoadTestCasesAutomatic()) {
try {
testSuite.setTestCases(null);
testSuite.setTestCases(TestSuiteHelper.loadTestCases(testSuiteProperties));
} catch (IOException e) {
throw new SakuliInitException(e, String.format("Cannot read testsuite.suite '%s' file", testSuiteProperties.getTestSuiteSuiteFile().toString()));
}
}
logger.info("test suite with guid '{}' has been initialized!", testSuite.getGuid());
logger.debug("test suite data after initialization: {}", testSuite.toString());
}
use of org.sakuli.exceptions.SakuliInitException 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.SakuliInitException in project sakuli by ConSol.
the class SakuliStarter method runTestSuite.
/**
* Executes a specific Sakuli test suite in the assigend 'testSuiteFolder'. A test suite has to contain as minimum
* following files:
* <ul>
* <li>testsuite.suite = specifies the testcases</li>
* <li>testsuite.properties = specifies the runtime settings like the browser for the test suite.</li>
* </ul>
*
* @param testSuiteFolderPath path to the Sakuli test suite
* @param sakuliHomeFolderPath path to the folder which contains 'config' and the 'libs' folder
* @param browser (optional) browser for the test execution, default: property 'testsuite.browser'
* @param sahiHomeFolder (optional) specifies a different sahi proxy as in the 'sakuli.properties' file
* @return the {@link TestSuiteState} of the Sakuli test execution.
* @throws FileNotFoundException
*/
public static TestSuite runTestSuite(String testSuiteFolderPath, String sakuliHomeFolderPath, String browser, String sahiHomeFolder) throws FileNotFoundException {
LOGGER.info(String.format("\n\n=========== START new SAKULI Testsuite from '%s' =================", testSuiteFolderPath));
//temp log cache for init stuff -> should be in the log file
String tempLogCache = "";
//check and set the path to the test suite
tempLogCache = SakuliFolderHelper.checkTestSuiteFolderAndSetContextVariables(testSuiteFolderPath, tempLogCache);
//check and set the sakuli main folder
tempLogCache = SakuliFolderHelper.checkSakuliHomeFolderAndSetContextVariables(sakuliHomeFolderPath, tempLogCache);
//if sahi home have been set overwrite the default
if (isNotEmpty(sahiHomeFolder)) {
tempLogCache = SakuliFolderHelper.checkSahiProxyHomeAndSetContextVariables(sahiHomeFolder, tempLogCache);
}
//set browser for test execution if not empty
if (isNotEmpty(browser)) {
tempLogCache = SakuliFolderHelper.setTestSuiteBrowserContextVariable(browser, tempLogCache);
}
//because of the property loading strategy, the logger must be initialized through the Spring Context!
SahiConnector sahiConnector = BeanLoader.loadBean(SahiConnector.class);
LOGGER.debug(tempLogCache);
//Call init services
InitializingServiceHelper.invokeInitializingServcies();
TestSuite result = BeanLoader.loadBean(TestSuite.class);
/***
* SAKULI Starter to run the test suite with embedded sahi proxy
*/
try {
sahiConnector.init();
//start the execution of the test suite
LOGGER.debug("start new sakuli test suite");
sahiConnector.startSahiTestSuite();
}/**
* will be catched if the Sahi-Proxy could not shutdown;
*/
catch (SakuliInitException e) {
LOGGER.error("Unexpected error occurred:", e);
System.exit(99);
} finally {
LOGGER.info("========== TEAR-DOWN SAKULI TEST SUITE '{}' ==========", result.getId());
TeardownServiceHelper.invokeTeardownServices();
//finally shutdown context and return the result
result = BeanLoader.loadBean(TestSuite.class);
BeanLoader.releaseContext();
}
return result;
}
use of org.sakuli.exceptions.SakuliInitException in project sakuli by ConSol.
the class SahiProxy method startProxy.
/**
* Starts a seperate Thread for the sahi proxy.
* You can do a shutdown with
*
* @param asyncron init if a separate thread should started
* @throws SakuliInitException if the specified files in the sahi.properties are not valid
*/
public void startProxy(boolean asyncron) throws SakuliInitException, FileNotFoundException {
sahiProxy = new Proxy(props.getProxyPort());
if (Files.exists(props.getSahiHomeFolder()) && Files.exists(props.getSahiConfigFolder())) {
logger.info("START Sahi-PROXY: Sahi-Home folder '{}', Sahi-Configuration folder '{}'", props.getSahiHomeFolder().toAbsolutePath().toString(), props.getSahiConfigFolder().toAbsolutePath().toString());
try {
injectCustomJavaScriptFiles();
//set the custom paths to the sahi environment
Configuration.init(props.getSahiHomeFolder().toAbsolutePath().toString(), props.getSahiConfigFolder().toAbsolutePath().toString());
Configuration.setUnmodifiedTrafficLogging(false);
Configuration.setModifiedTrafficLogging(false);
//Starts the sahi proxy as asynchron Thread
sahiProxy.start(asyncron);
Thread.sleep(200);
} catch (RuntimeException e) {
logger.error("RUNTIME EXCEPTION");
throw new SakuliInitException(e);
} catch (Throwable e) {
logger.error("THROWABLE EXCEPTION");
throw new SakuliInitException(e.getMessage());
}
} else {
throw new FileNotFoundException("the path to '" + SahiProxyProperties.PROXY_HOME_FOLDER + "=" + props.getSahiHomeFolder().toAbsolutePath().toString() + "' or '" + SahiProxyProperties.PROXY_CONFIG_FOLDER + "=" + props.getSahiConfigFolder().toAbsolutePath().toString() + "' is not valid, please check the properties files!");
}
}
Aggregations