Search in sources :

Example 21 with TestSuite

use of org.sakuli.datamodel.TestSuite in project sakuli by ConSol.

the class Icinga2OutputBuilderTest method testBuildErrorInCase.

@Test
public void testBuildErrorInCase() throws Exception {
    TestSuite testSuite = new TestSuiteExampleBuilder().withState(TestSuiteState.ERRORS).withId("TEST-SUITE-ID").withTestCases(Collections.singletonList(new TestCaseExampleBuilder().withId("TEST-CASE-ID").withState(TestCaseState.ERRORS).withException(new SakuliException("MY-TEST-ERROR-CASE")).buildExample())).buildExample();
    ReflectionTestUtils.setField(testling, "testSuite", testSuite);
    Assert.assertEquals(testling.build(), "[CRIT] Sakuli suite \"TEST-SUITE-ID\" (120.00s) EXCEPTION: 'CASE \"TEST-CASE-ID\": MY-TEST-ERROR-CASE'. (Last suite run: 17.08.14 14:02:00)\n" + "[CRIT] case \"TEST-CASE-ID\" EXCEPTION: MY-TEST-ERROR-CASE");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) SakuliException(org.sakuli.exceptions.SakuliException) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) Test(org.testng.annotations.Test)

Example 22 with TestSuite

use of org.sakuli.datamodel.TestSuite in project sakuli by ConSol.

the class SakuliExceptionHandlerTest method testContainsExceptionsStep.

@Test
public void testContainsExceptionsStep() throws Exception {
    TestSuite ts = new TestSuite();
    TestCase tc = new TestCase(null, null);
    ts.addTestCase(tc);
    TestCaseStep step = new TestCaseStep();
    step.addException(new SakuliException("bla3"));
    tc.addStep(step);
    assertTrue(SakuliExceptionHandler.containsException(ts));
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) TestCaseStep(org.sakuli.datamodel.TestCaseStep) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 23 with TestSuite

use of org.sakuli.datamodel.TestSuite in project sakuli by ConSol.

the class TestCaseAction method saveResult.

/****************
     * TEST CASE HANDLING
     *********************/
/**
     * save the Result of a test Case
     *
     * @param testCaseId  id of the corresponding test case
     * @param startTime   start time in milliseconds
     * @param stopTime    end time in milliseconds
     * @param lastURL     URL to the last visited page during this test case
     * @param browserInfo detail information about the used browser
     * @throws SakuliException
     */
@LogToResult(message = "save the result of the current test case")
public void saveResult(String testCaseId, String startTime, String stopTime, String lastURL, String browserInfo) throws SakuliException {
    if (!loader.getCurrentTestCase().getId().equals(testCaseId)) {
        handleException("testcaseID '" + testCaseId + "' to save the test case Result ist is not valid!");
    }
    TestSuite testSuite = loader.getTestSuite();
    testSuite.setBrowserInfo(browserInfo);
    //set TestCase vars
    TestCase tc = loader.getCurrentTestCase();
    tc.setLastURL(lastURL);
    try {
        tc.setStartDate(new Date(Long.parseLong(startTime)));
        tc.setStopDate(new Date(Long.parseLong(stopTime)));
        logger.debug("test case duration = " + tc.getDuration());
        tc.refreshState();
    } catch (NumberFormatException | NullPointerException e) {
        handleException("Duration could not be calculated! " + "Check if the warning and critical threshold is set correctly in your test case!  " + "=> START date: " + startTime + "\tSTOP date: " + stopTime + "\n" + e.getMessage());
    }
    //release current test case -> indicates that this case is finished
    loader.setCurrentTestCase(null);
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) Date(java.util.Date) LogToResult(org.sakuli.actions.logging.LogToResult)

Example 24 with TestSuite

use of org.sakuli.datamodel.TestSuite 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;
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) SakuliInitException(org.sakuli.exceptions.SakuliInitException)

Example 25 with TestSuite

use of org.sakuli.datamodel.TestSuite in project sakuli by ConSol.

the class SakuliStarter method main.

/**
     * The Sakuli-Starter executes a specific sakuli-testsuite. 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 args relative or absolute path to the folder of your test suite
     */
public static void main(String[] args) {
    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    options.addOption(help);
    options.addOption(run);
    options.addOption(browser);
    options.addOption(sakuliHome);
    options.addOption(sahiHome);
    options.addOption(encrypt);
    options.addOption(anInterface);
    try {
        CommandLine cmd = parser.parse(options, args);
        final String browserValue = getOptionValue(cmd, browser);
        final String testSuiteFolderPath = getOptionValue(cmd, run);
        final String sakuliMainFolderPath = getOptionValue(cmd, sakuliHome);
        final String sahiHomePath = getOptionValue(cmd, sahiHome);
        final String ethInterface = getOptionValue(cmd, anInterface);
        final String strToEncrypt = getOptionValue(cmd, encrypt);
        if (cmd.hasOption(run.getLongOpt()) || cmd.hasOption(run.getOpt())) {
            TestSuite testSuite = runTestSuite(testSuiteFolderPath, sakuliMainFolderPath, browserValue, sahiHomePath);
            //return the state as system exit parameter
            //return values are corresponding to the error codes in file "sahi_return_codes.txt"
            System.exit(testSuite.getState().getErrorCode());
        } else if (cmd.hasOption(encrypt.getLongOpt()) || cmd.hasOption(encrypt.getOpt())) {
            System.out.printf("\nString to Encrypt: %s \n...", strToEncrypt);
            final Entry<String, String> secret = encryptSecret(strToEncrypt, ethInterface);
            System.out.printf("\nEncrypted secret with interface '%s': %s", secret.getKey(), secret.getValue());
            System.out.println("\n\n... now copy the secret to your testcase!");
            System.exit(0);
        } else {
            CmdPrintHelper.printHelp(options);
            System.exit(SYSTEM_EXIT_VALUE_HELP);
        }
    } catch (ParseException e) {
        System.err.println("Parsing of command line failed: " + e.getMessage());
        CmdPrintHelper.printHelp(options);
        System.exit(SYSTEM_EXIT_VALUE_HELP);
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("Error: " + e.getMessage());
        System.exit(TestSuiteState.ERRORS.getErrorCode());
    }
}
Also used : Entry(java.util.Map.Entry) TestSuite(org.sakuli.datamodel.TestSuite) SakuliCipherException(org.sakuli.exceptions.SakuliCipherException) FileNotFoundException(java.io.FileNotFoundException) SakuliInitException(org.sakuli.exceptions.SakuliInitException)

Aggregations

TestSuite (org.sakuli.datamodel.TestSuite)41 Test (org.testng.annotations.Test)34 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)21 BaseTest (org.sakuli.BaseTest)15 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)15 TestCase (org.sakuli.datamodel.TestCase)13 SakuliException (org.sakuli.exceptions.SakuliException)7 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)6 TestCaseStep (org.sakuli.datamodel.TestCaseStep)6 Path (java.nio.file.Path)5 Date (java.util.Date)5 TestCaseStepBuilder (org.sakuli.datamodel.builder.TestCaseStepBuilder)2 SakuliInitException (org.sakuli.exceptions.SakuliInitException)2 FileNotFoundException (java.io.FileNotFoundException)1 Entry (java.util.Map.Entry)1 Future (java.util.concurrent.Future)1 GearmanJobServerConnection (org.gearman.common.GearmanJobServerConnection)1 DateTime (org.joda.time.DateTime)1 Matchers.anyString (org.mockito.Matchers.anyString)1 LoggerTest (org.sakuli.LoggerTest)1