Search in sources :

Example 1 with LogToResult

use of org.sakuli.actions.logging.LogToResult 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 2 with LogToResult

use of org.sakuli.actions.logging.LogToResult in project sakuli by ConSol.

the class Application method focusWindow.

/**
     * focus a specific window of the application.
     *
     * @param windowNumber indemnifies the window
     * @return this {@link Application}.
     */
@LogToResult(message = "focus application in window")
public Application focusWindow(Integer windowNumber) {
    LOGGER.debug("Focus window \"" + windowNumber + "\" in application \"" + getName() + "\".");
    App app = super.focus(windowNumber);
    sleep(sleepMillis);
    if (app == null) {
        LOGGER.warn("Application '{}' could not be focused! ... Please check if the application has been opened before or is already focused!", getName());
        return this;
    }
    return this;
}
Also used : App(org.sikuli.script.App) LogToResult(org.sakuli.actions.logging.LogToResult)

Example 3 with LogToResult

use of org.sakuli.actions.logging.LogToResult in project sakuli by ConSol.

the class Application method open.

/**
     * Opens the created application. For loadtime intensiv application change the default sleep time with {@link
     * #setSleepTime(Integer)}.
     *
     * @return this {@link Application}.
     */
@LogToResult(message = "open application")
@Override
public Application open() {
    App app = super.open();
    sleep(sleepMillis);
    if (app == null) {
        loader.getExceptionHandler().handleException("Application '" + getName() + " could not be opend! ... Please check the application name or path!", resumeOnException);
        return null;
    }
    final int tries = 5;
    for (int i = 0; i < tries && this.getPID() <= 0; i++) {
        LOGGER.info("wait {} ms more for finish loading application {} - {} of {} tries", sleepMillis, this.getName(), i, tries);
        sleep(sleepMillis);
    }
    LOGGER.info("\"{}\" - PID: {}", this.getName(), this.getPID());
    return this;
}
Also used : App(org.sikuli.script.App) LogToResult(org.sakuli.actions.logging.LogToResult)

Example 4 with LogToResult

use of org.sakuli.actions.logging.LogToResult in project sakuli by ConSol.

the class RhinoAspectTest method testCreateLoggingString.

@Test
public void testCreateLoggingString() throws Exception {
    JoinPoint jp = mock(JoinPoint.class);
    when(jp.getArgs()).thenReturn(new Object[] { "TEST", "arguments" });
    LogToResult annotation = mock(LogToResult.class);
    when(annotation.logArgsOnly()).thenReturn(true);
    when(annotation.logArgs()).thenReturn(true);
    StringBuilder result = BeanLoader.loadBean(RhinoAspect.class).createLoggingString(jp, annotation);
    assertEquals(result.toString(), "TEST, arguments");
}
Also used : LogToResult(org.sakuli.actions.logging.LogToResult) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.testng.annotations.Test)

Example 5 with LogToResult

use of org.sakuli.actions.logging.LogToResult in project sakuli by ConSol.

the class RhinoAspectTest method testAddActionLog.

@Test(dataProvider = "logLevel")
public void testAddActionLog(LogLevel logLevel) throws Exception {
    initMocks();
    Report sahiReport = BeanLoader.loadBaseActionLoader().getSahiReport();
    final int lisSize = sahiReport.getListResult().size();
    final String classContent = "Test-Action-Content";
    final String className = TestCaseAction.class.getSimpleName();
    final String methodName = "actionMethod";
    final String sampleMessage = "sample-message-for-log";
    final String arg1 = "ARG1";
    final String arg2 = "NULL";
    TestCaseAction testAction = mock(TestCaseAction.class);
    when(testAction.toString()).thenReturn(classContent);
    JoinPoint jp = mock(JoinPoint.class);
    when(jp.getTarget()).thenReturn(testAction);
    Signature signature = mock(Signature.class);
    when(jp.getSignature()).thenReturn(signature);
    when(signature.getDeclaringType()).thenReturn(TestCaseAction.class);
    when(signature.getName()).thenReturn(methodName);
    when(signature.getDeclaringTypeName()).thenReturn(TestCaseAction.class.getName());
    when(jp.getArgs()).thenReturn(new Object[] { arg1, null });
    LogToResult logToResult = mock(LogToResult.class);
    when(logToResult.logClassInstance()).thenReturn(true);
    when(logToResult.message()).thenReturn(sampleMessage);
    when(logToResult.logArgs()).thenReturn(true);
    when(logToResult.level()).thenReturn(logLevel);
    RhinoAspect testling = BeanLoader.loadBean(RhinoAspect.class);
    testling.addActionLog(jp, logToResult);
    assertLastLine(logFile, className, logLevel, "\"" + classContent + "\" " + className + "." + methodName + "() - " + sampleMessage + " with arg(s) [" + arg1 + ", " + arg2 + "]");
    verifySahiReport(logLevel.getResultType(), lisSize);
    //hide args
    when(logToResult.logArgs()).thenReturn(false);
    testling.addActionLog(jp, logToResult);
    assertLastLine(logFile, className, logLevel, "\"" + classContent + "\" " + className + "." + methodName + "() - " + sampleMessage + " with arg(s) [****, ****]");
    //without class values
    when(logToResult.logClassInstance()).thenReturn(false);
    testling.addActionLog(jp, logToResult);
    assertLastLine(logFile, className, logLevel, className + "." + methodName + "() - " + sampleMessage + " with arg(s) [****, ****]");
    //without args
    when(jp.getArgs()).thenReturn(null);
    testling.addActionLog(jp, logToResult);
    assertLastLine(logFile, className, logLevel, className + "." + methodName + "() - " + sampleMessage);
    //without message
    when(logToResult.message()).thenReturn(null);
    testling.addActionLog(jp, logToResult);
    assertLastLine(logFile, className, logLevel, className + "." + methodName + "()");
}
Also used : LogToResult(org.sakuli.actions.logging.LogToResult) Report(net.sf.sahi.report.Report) TestCaseAction(org.sakuli.actions.TestCaseAction) Signature(org.aspectj.lang.Signature) JoinPoint(org.aspectj.lang.JoinPoint) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.testng.annotations.Test)

Aggregations

LogToResult (org.sakuli.actions.logging.LogToResult)7 Date (java.util.Date)2 JoinPoint (org.aspectj.lang.JoinPoint)2 App (org.sikuli.script.App)2 Test (org.testng.annotations.Test)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Report (net.sf.sahi.report.Report)1 Signature (org.aspectj.lang.Signature)1 TestCaseAction (org.sakuli.actions.TestCaseAction)1 TestCase (org.sakuli.datamodel.TestCase)1 TestCaseStep (org.sakuli.datamodel.TestCaseStep)1 TestSuite (org.sakuli.datamodel.TestSuite)1