Search in sources :

Example 11 with SakuliException

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

Example 12 with SakuliException

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

Example 13 with SakuliException

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

Example 14 with SakuliException

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);
}
Also used : SakuliException(org.sakuli.exceptions.SakuliException) Test(org.testng.annotations.Test)

Example 15 with SakuliException

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);
}
Also used : SakuliException(org.sakuli.exceptions.SakuliException) TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder) Test(org.testng.annotations.Test)

Aggregations

SakuliException (org.sakuli.exceptions.SakuliException)19 Test (org.testng.annotations.Test)12 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)8 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)7 TestSuite (org.sakuli.datamodel.TestSuite)7 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)4 Date (java.util.Date)3 BaseTest (org.sakuli.BaseTest)3 TestCase (org.sakuli.datamodel.TestCase)3 Path (java.nio.file.Path)2 SakuliExceptionHandler (org.sakuli.exceptions.SakuliExceptionHandler)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)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 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)1 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)1 After (org.aspectj.lang.annotation.After)1 DateTime (org.joda.time.DateTime)1