use of org.sakuli.actions.logging.LogToResult in project sakuli by ConSol.
the class TestCaseAction method addTestCaseStep.
/**
* Save a new step to a existing test case. Must be called before {@link #saveResult(String, String, String, String,
* String)}
*
* @param stepName name of this step
* @param startTime start time in milliseconds
* @param stopTime end time in milliseconds
* @param warningTime warning threshold in seconds. If the threshold is set to 0, the execution time will never exceed, so the state will be always OK!
* @throws SakuliException
*/
@LogToResult(message = "add a step to the current test case")
public void addTestCaseStep(String stepName, String startTime, String stopTime, int warningTime) throws SakuliException {
if (stepName == null || stepName.isEmpty() || stepName.equals("undefined")) {
handleException("Please set a Name - all values of the test case step need to be set!");
}
String errormsg = TestCaseStepHelper.checkWarningTime(warningTime, stepName);
if (errormsg != null) {
handleException(errormsg);
}
TestCaseStep step = findStep(stepName);
try {
step.setStartDate(new Date(Long.parseLong(startTime)));
step.setStopDate(new Date(Long.parseLong(stopTime)));
step.setWarningTime(warningTime);
} catch (NullPointerException | NumberFormatException e) {
loader.getExceptionHandler().handleException(e);
}
logger.debug("duration of the step \"" + stepName + "\": " + step.getDuration() + " sec.");
step.refreshState();
logger.debug("result of step \"" + stepName + "\": " + step.getState());
loader.getCurrentTestCase().addStep(step);
logger.debug("test case step \"" + step.getName() + "\" saved to test case \"" + loader.getCurrentTestCase().getId() + "\"");
}
use of org.sakuli.actions.logging.LogToResult in project sakuli by ConSol.
the class Environment method takeScreenshot.
/**
* Takes a screenshot of the current screen and saves it to the overgiven path. If there ist just a file name, the
* screenshot will be saved in your testsuite log folder.
*
* @param pathName "pathname/filname.format" or just "filename.format"<br> for example "test.png".
*/
@LogToResult(message = "take a screenshot from the current screen and save it to the file system", logClassInstance = false)
public String takeScreenshot(final String pathName) {
Path folderPath;
String message;
if (pathName.contains(File.separator)) {
folderPath = Paths.get(pathName.substring(0, pathName.lastIndexOf(File.separator)));
message = pathName.substring(pathName.lastIndexOf(File.separator) + 1, pathName.lastIndexOf("."));
} else {
folderPath = loader.getActionProperties().getScreenShotFolder();
message = pathName.substring(0, pathName.lastIndexOf("."));
}
try {
loader.getScreen().capture();
return loader.getScreenshotActions().takeScreenshot(message, folderPath, pathName.substring(pathName.lastIndexOf(".") + 1)).toFile().getAbsolutePath();
} catch (IOException e) {
loader.getExceptionHandler().handleException("Can't create Screenshot for path '" + pathName + "': " + e.getMessage(), resumeOnException);
}
return null;
}
Aggregations