Search in sources :

Example 6 with TestCaseStep

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

the class DaoTestCaseImpl method getScreenshotAsSqlLobValue.

/**
     * Determine the first available screenshot inside of the testcase and respectively in the assigned steps.
     * For Details of the transformation, see {@link org.springframework.jdbc.support.lob.LobHandler}.
     *
     * @return a {@link SqlLobValue}
     */
protected SqlLobValue getScreenshotAsSqlLobValue(TestCase testCase) {
    try {
        Path screenShotPath = testCase.getScreenShotPath();
        if (screenShotPath == null) {
            //get first step exception
            for (TestCaseStep step : testCase.getStepsAsSortedSet()) {
                if (step.getScreenShotPath() != null) {
                    screenShotPath = step.getScreenShotPath();
                    break;
                }
            }
        }
        if (screenShotPath != null) {
            final InputStream blobIs = Files.newInputStream(screenShotPath);
            final int length = (int) screenShotPath.toFile().length();
            return new SqlLobValue(blobIs, length, lobHandler);
        }
        return null;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) SqlLobValue(org.springframework.jdbc.core.support.SqlLobValue) InputStream(java.io.InputStream) TestCaseStep(org.sakuli.datamodel.TestCaseStep) IOException(java.io.IOException)

Example 7 with TestCaseStep

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

the class CacheHandlingResultServiceImpl method removeCachedInitSteps.

protected void removeCachedInitSteps() {
    for (TestCase tc : testSuite.getTestCases().values()) {
        List<TestCaseStep> filteredSteps = new ArrayList<>();
        for (TestCaseStep step : tc.getSteps()) {
            if (step.getState() != null && step.getState().isFinishedWithoutErrors()) {
                filteredSteps.add(step);
            } else {
                logger.debug("remove cached and not called step '{}'", step.getId());
            }
        }
        tc.setSteps(filteredSteps);
    }
}
Also used : TestCase(org.sakuli.datamodel.TestCase) ArrayList(java.util.ArrayList) TestCaseStep(org.sakuli.datamodel.TestCaseStep)

Example 8 with TestCaseStep

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

the class AbstractOutputBuilder method generateTestCaseScreenshotsHTML.

/**
     * Generates '<div></div>' tag for the screenshots included in the {@link TestCase} and the suppressed {@link TestCaseStep}s.
     */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
protected String generateTestCaseScreenshotsHTML(TestCase testCase) {
    StringBuilder sb = new StringBuilder();
    ScreenshotDiv caseDiv = screenshotDivConverter.convert(testCase.getException());
    if (caseDiv != null) {
        sb.append(caseDiv.getPayloadString());
    }
    for (TestCaseStep step : testCase.getStepsAsSortedSet()) {
        ScreenshotDiv stepDiv = screenshotDivConverter.convert(step.getException());
        if (stepDiv != null) {
            sb.append(stepDiv.getPayloadString());
        }
    }
    return sb.toString();
}
Also used : TestCaseStep(org.sakuli.datamodel.TestCaseStep) ScreenshotDiv(org.sakuli.services.forwarder.gearman.model.ScreenshotDiv)

Example 9 with TestCaseStep

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

the class AbstractPerformanceDataBuilder method addTestCaseStepPerformanceData.

/**
     * Generates the performance data for assigned {@link TestCaseStep}s as an {@link String}.
     *
     * @param data            already produced performance data
     * @param testCaseSteps   {@link SortedSet} of {@link TestCaseStep}s
     * @param countOfTestCase current count of the parent {@link TestCase}
     * @return formatted payload string
     */
protected static String addTestCaseStepPerformanceData(String data, SortedSet<TestCaseStep> testCaseSteps, int countOfTestCase) {
    int j = 1;
    for (TestCaseStep step : testCaseSteps) {
        final String stepName = String.format("s_%03d_%03d_%s", countOfTestCase, j, step.getId());
        if (step.getState().isFinishedWithoutErrors()) {
            data = addPerformanceDataRow(data, stepName, step.getDuration(), step.getWarningTime(), 0);
        } else {
            //add data performance data with unknown state
            data = addUnknownPerformanceDataRow(data, stepName);
        }
        j++;
    }
    return data;
}
Also used : TestCaseStep(org.sakuli.datamodel.TestCaseStep)

Example 10 with TestCaseStep

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

the class TestCaseActionTest method testAddTestCaseStep.

@Test
public void testAddTestCaseStep() throws Throwable {
    sample.setWarningTime(0);
    sample.setCriticalTime(0);
    long now = new Date().getTime();
    testling.addTestCaseStep("step for JUnit", "" + (now - 3000), "" + now, //warning
    2);
    TestCaseStep step = testSuiteMock.getTestCases().get(sample.getId()).getSteps().get(0);
    assertNotNull(step);
    assertEquals(step.getName(), "step_for_JUnit");
    assertEquals(step.getDuration(), 3.0f, "duration is not correct");
    assertEquals(step.getState(), TestCaseStepState.WARNING);
    testling.addTestCaseStep("step2 for JUnit", "" + (now + 300), "" + (now + 4300), //no warning
    5);
    TestCaseStep step2 = testSuiteMock.getTestCases().get(sample.getId()).getSteps().get(1);
    assertNotNull(step2);
    assertEquals(step2.getName(), "step2_for_JUnit");
    assertEquals(step2.getDuration(), 4.0f, "duration is not correct");
    assertEquals(step2.getState(), TestCaseStepState.OK);
}
Also used : TestCaseStep(org.sakuli.datamodel.TestCaseStep) Date(java.util.Date) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Aggregations

TestCaseStep (org.sakuli.datamodel.TestCaseStep)21 Test (org.testng.annotations.Test)10 BaseTest (org.sakuli.BaseTest)8 TestCase (org.sakuli.datamodel.TestCase)8 TestSuite (org.sakuli.datamodel.TestSuite)6 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 DaoTestCaseStep (org.sakuli.services.forwarder.database.dao.DaoTestCaseStep)3 IOException (java.io.IOException)2 TestCaseStepBuilder (org.sakuli.datamodel.builder.TestCaseStepBuilder)2 DaoTestCase (org.sakuli.services.forwarder.database.dao.DaoTestCase)2 InputStream (java.io.InputStream)1 DateTime (org.joda.time.DateTime)1 LogToResult (org.sakuli.actions.logging.LogToResult)1 SakuliForwarderException (org.sakuli.exceptions.SakuliForwarderException)1 DaoTestSuite (org.sakuli.services.forwarder.database.dao.DaoTestSuite)1 ScreenshotDiv (org.sakuli.services.forwarder.gearman.model.ScreenshotDiv)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 SimpleJdbcInsert (org.springframework.jdbc.core.simple.SimpleJdbcInsert)1