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);
}
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;
}
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;
}
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");
}
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 + "()");
}
Aggregations