use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.
the class TestCaseBuilder method build.
@Override
public TestCase build() {
TestCase newTestCase = new TestCase(name, id);
newTestCase.setStartDate(new Date());
return newTestCase;
}
use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.
the class TestCaseStepHelper method writeCachedStepDefinitions.
public static void writeCachedStepDefinitions(TestSuite testSuite) throws IOException {
if (testSuite.getTestCases() != null) {
for (TestCase tc : testSuite.getTestCases().values()) {
if (tc.getTcFile() != null) {
Path stepsCacheFile = tc.getTcFile().getParent().resolve(STEPS_CACHE_FILE);
File output = new File(stepsCacheFile.toUri());
if (!output.getParentFile().exists()) {
output.getParentFile().mkdirs();
}
try {
String stepNames = getStepName(tc.getSteps());
LOGGER.debug("write following step IDs to file '{}':\n{}", stepsCacheFile, stepNames);
FileUtils.writeStringToFile(output, stepNames, Charset.forName("UTF-8"), false);
} catch (IOException e) {
throw new IOException(String.format("error during writing into '%s' file ", stepsCacheFile), e);
}
}
}
}
}
use of org.sakuli.datamodel.TestCase 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.datamodel.TestCase in project sakuli by ConSol.
the class DatabaseResultServiceImpl method saveAllResults.
@Override
public void saveAllResults() {
LOGGER.info("======= SAVE RESULTS TO DATABASE ======");
;
try {
daoTestSuite.saveTestSuiteResult();
daoTestSuite.saveTestSuiteToSahiJobs();
if (!CollectionUtils.isEmpty(testSuite.getTestCases())) {
for (TestCase tc : testSuite.getTestCasesAsSortedSet()) {
//write testcase and steps to DB
daoTestCase.saveTestCaseResult(tc);
LOGGER.info("... try to save all STEPS for test case '" + tc.getId() + "'!");
SortedSet<TestCaseStep> steps = tc.getStepsAsSortedSet();
if (!steps.isEmpty()) {
daoTestCaseStep.saveTestCaseSteps(steps, tc.getDbPrimaryKey());
LOGGER.info("all STEPS for '" + tc.getId() + "' saved!");
} else {
LOGGER.info("no STEPS for '\" + tc.getId() +\"'found => no STEPS saved in DB!");
}
}
}
LOGGER.info("======= FINISHED: SAVE RESULTS TO DATABASE ======");
} catch (Throwable e) {
exceptionHandler.handleException(new SakuliForwarderException(e, String.format("error by saving the results to the database [%s]", testSuite.toString())), true);
}
}
use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.
the class TestSuiteHelper method loadTestCases.
/**
* read out the 'testsuite.suite' file and create the corresponding test cases objects.
*
* @param properties loaded {@link TestSuiteProperties} of a {@link TestSuite}.
* @return a map of {@link TestCase}s with her {@link TestCase#id} as key.
* @throws FileNotFoundException if files are not reachable
*/
public static HashMap<String, TestCase> loadTestCases(TestSuiteProperties properties) throws IOException {
Path testSuiteFile = properties.getTestSuiteSuiteFile();
Path testSuiteFolder = properties.getTestSuiteFolder();
HashMap<String, TestCase> tcMap = new HashMap<>();
if (!Files.exists(testSuiteFile)) {
throw new FileNotFoundException("Can not find specified " + TestSuiteProperties.TEST_SUITE_SUITE_FILE_NAME + " file at \"" + testSuiteFolder.toString() + "\"");
}
String testSuiteString = prepareTestSuiteFile(testSuiteFile);
logger.info("\n--- TestSuite initialization: read test suite information of file \"" + testSuiteFile.toAbsolutePath().toString() + "\" ----\n" + testSuiteString + "\n --- End of File \"" + testSuiteFile.toAbsolutePath().toString() + "\" ---");
//handle each line of the .suite file
String regExLineSep = System.getProperty("line.separator") + "|\n";
for (String line : testSuiteString.split(regExLineSep)) {
if (!line.startsWith("//") && !(line.isEmpty())) {
//get the start URL from suite
String startURL = line.substring(line.lastIndexOf(' ') + 1);
//extract tc file name name and generate new test case
// get tc file name
String tcFileName = line.substring(0, line.lastIndexOf(' '));
Path tcFile = Paths.get(testSuiteFolder.toAbsolutePath().toString() + File.separator + tcFileName.replace("/", File.separator));
if (Files.exists(tcFile)) {
TestCase tc = new TestCase(TestCaseHelper.convertFolderPathToName(tcFileName), TestCaseHelper.convertTestCaseFileToID(tcFileName));
tc.setStartUrl(startURL);
tc.setTcFile(tcFile);
tc.setSteps(TestCaseStepHelper.readCachedStepDefinitions(tcFile));
//set the Map with the test case id as key
tcMap.put(tc.getId(), tc);
} else {
throw new FileNotFoundException("test case path \"" + tcFile.toAbsolutePath().toString() + "\" doesn't exists - check your \"" + TestSuiteProperties.TEST_SUITE_SUITE_FILE_NAME + "\" file");
}
}
}
return tcMap;
}
Aggregations