Search in sources :

Example 1 with SakuliCheckedException

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();
    }
}
Also used : Report(net.sf.sahi.ant.Report) SakuliInitException(org.sakuli.exceptions.SakuliInitException) TestRunner(net.sf.sahi.test.TestRunner) SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException) Date(java.util.Date) SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException) FileNotFoundException(java.io.FileNotFoundException) SakuliInitException(org.sakuli.exceptions.SakuliInitException) ConnectException(java.net.ConnectException) ConnectException(java.net.ConnectException)

Example 2 with SakuliCheckedException

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;
}
Also used : PumpStreamHandler(org.apache.commons.exec.PumpStreamHandler) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException)

Example 3 with SakuliCheckedException

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;
}
Also used : SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException) SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException)

Example 4 with SakuliCheckedException

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());
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException)

Example 5 with SakuliCheckedException

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);
}
Also used : Path(java.nio.file.Path) TestSuite(org.sakuli.datamodel.TestSuite) SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestCaseStepState(org.sakuli.datamodel.state.TestCaseStepState) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) Test(org.testng.annotations.Test) LoggerTest(org.sakuli.LoggerTest)

Aggregations

SakuliCheckedException (org.sakuli.exceptions.SakuliCheckedException)19 Test (org.testng.annotations.Test)13 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)8 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)7 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)6 TestSuite (org.sakuli.datamodel.TestSuite)6 IOException (java.io.IOException)4 DateTime (org.joda.time.DateTime)4 BaseTest (org.sakuli.BaseTest)4 IntegrationTest (org.sakuli.integration.IntegrationTest)4 ScreenshotDiv (org.sakuli.services.forwarder.ScreenshotDiv)4 TestCase (org.sakuli.datamodel.TestCase)3 Path (java.nio.file.Path)2 Date (java.util.Date)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 ConnectException (java.net.ConnectException)1 TreeSet (java.util.TreeSet)1 Report (net.sf.sahi.ant.Report)1 TestRunner (net.sf.sahi.test.TestRunner)1