use of com.testsigma.automator.utilities.ErrorUtil in project testsigma by testsigmahq.
the class TestsuiteRunner method runDataDrivenTestCase.
public void runDataDrivenTestCase(TestCaseEntity testCaseEntity, TestCaseResult testCaseResult, boolean testCaseRunFailed, boolean testCasePrerequisiteFailed) throws Exception {
ResultConstant dataDrivenStatus = ResultConstant.SUCCESS;
for (TestCaseEntity dataDrivenTestCase : testCaseEntity.getDataDrivenTestCases()) {
TestCaseResult dataDrivenTestCaseResult = new TestCaseResult(dataDrivenTestCase.getId());
dataDrivenTestCaseResult.setId(getResultId(testCaseEntity, dataDrivenTestCase.getTestDataSetName()));
dataDrivenTestCaseResult.setGroupId(testCaseResult.getGroupId());
dataDrivenTestCaseResult.setEnvRunId(environmentRunResult.getId());
dataDrivenTestCaseResult.setGroupResultId(testCaseResult.getGroupResultId());
dataDrivenTestCaseResult.setParentId(testCaseResult.getId());
dataDrivenTestCaseResult.setTestDataSetName(dataDrivenTestCase.getTestDataSetName());
dataDrivenTestCaseResult.setTestDataId(testCaseEntity.getTestDataId());
dataDrivenTestCaseResult.setStartTime(new Timestamp(System.currentTimeMillis()));
dataDrivenTestCaseResult.setVisualTestingEnabled(testCaseResult.isVisualTestingEnabled());
testCaseResult.getTestCaseResults().add(dataDrivenTestCaseResult);
try {
dataDrivenTestCase = getTestCase(dataDrivenTestCase, this.testCaseFetchMaxTries);
new ErrorUtil().checkError(dataDrivenTestCase.getErrorCode(), dataDrivenTestCase.getMessage());
} catch (AutomatorException e) {
log.error(e.getMessage(), e);
if (!(skipExecution || testCasePrerequisiteFailed)) {
testCaseRunFailed = true;
resultFailureMessage = e.getMessage();
dataDrivenTestCaseResult.setResult(ResultConstant.FAILURE);
dataDrivenTestCaseResult.setMessage(resultFailureMessage);
}
}
if (!(testCaseRunFailed || testCasePrerequisiteFailed)) {
if (ExecutionEnvironmentRunner.isRunning()) {
new TestcaseRunner(dataDrivenTestCase, dataDrivenTestCaseResult, mapStepResult, skipExecution || testCasePrerequisiteFailed, resultFailureMessage).run();
boolean isFailed = (ResultConstant.SUCCESS != dataDrivenTestCaseResult.getResult());
if (skipExecution) {
dataDrivenTestCaseResult.setResult(testCaseResult.getResult());
dataDrivenTestCaseResult.setMessage(testCaseResult.getMessage());
} else if (isFailed == dataDrivenTestCase.getExpectedToFail()) {
dataDrivenTestCaseResult.setResult(ResultConstant.SUCCESS);
} else {
dataDrivenTestCaseResult.setResult(ResultConstant.FAILURE);
}
} else {
dataDrivenTestCaseResult.setResult(ResultConstant.STOPPED);
dataDrivenTestCaseResult.setMessage(AutomatorMessages.MSG_USER_ABORTED_EXECUTION);
dataDrivenTestCaseResult.setEndTime(new Timestamp(System.currentTimeMillis()));
postTestcaseResult(dataDrivenTestCaseResult);
break;
}
} else if (testCasePrerequisiteFailed) {
dataDrivenTestCaseResult.setResult(testCaseResult.getResult());
dataDrivenTestCaseResult.setMessage(testCaseResult.getMessage());
}
dataDrivenStatus = (dataDrivenTestCaseResult.getResult().getId() > dataDrivenStatus.getId()) ? dataDrivenTestCaseResult.getResult() : dataDrivenStatus;
dataDrivenTestCaseResult.setEndTime(ObjectUtils.defaultIfNull(dataDrivenTestCaseResult.getEndTime(), new Timestamp(System.currentTimeMillis())));
postTestcaseResult(dataDrivenTestCaseResult);
}
testCaseResult.setResult(ObjectUtils.defaultIfNull(testCaseResult.getResult(), dataDrivenStatus));
if (testCaseResult.getResult() == ResultConstant.SUCCESS) {
testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_SUCCESS);
} else if (StringUtils.isBlank(testCaseResult.getMessage())) {
testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_FAILURE);
}
}
use of com.testsigma.automator.utilities.ErrorUtil in project testsigma by testsigmahq.
the class TestsuiteRunner method runSuite.
private void runSuite(TestSuiteEntity testSuiteEntity, TestSuiteResult testSuiteResult) throws AutomatorException {
resetThreadContextData();
populateThreadContextData(testSuiteEntity, testSuiteResult);
log.debug("Running test suite - " + testSuiteEntity.getName());
if (!testDeviceEntity.getCreateSessionAtCaseLevel()) {
restartCurrentSession(testSuiteResult);
}
List<TestCaseEntity> testCaseEntityList = testSuiteEntity.getTestCases();
List<TestCaseResult> testCasesResult = new ArrayList<>();
testSuiteResult.setTestCaseResults(testCasesResult);
testSuiteResult.setResult(ResultConstant.SUCCESS);
boolean executionStarted = false;
for (TestCaseEntity testCaseEntity : testCaseEntityList) {
boolean testCaseRunFailed = false;
boolean testCasePrerequisiteFailed = false;
TestCaseResult testCaseResult = new TestCaseResult(testCaseEntity.getId());
try {
testCaseResult.setId(testCaseEntity.getTestCaseResultId());
testCaseResult.setEnvRunId(testSuiteEntity.getEnvironmentResultId());
testCaseResult.setGroupResultId(testSuiteEntity.getResultId());
testCaseResult.setGroupId(testSuiteEntity.getId());
testCaseResult.setTestCaseId(testCaseEntity.getId());
testCaseResult.setTestDataSetName(testCaseEntity.getTestDataSetName());
testCaseResult.setTestDataId(testCaseEntity.getTestDataId());
testCaseResult.setIsStepGroup(testCaseEntity.getIsStepGroup());
testCaseResult.setDataDriven(testCaseEntity.getIsDataDriven());
testCaseResult.setStartTime(new Timestamp(System.currentTimeMillis()));
testCasesResult.add(testCaseResult);
testCaseResult.setVisualTestingEnabled(testPlanRunSettingEntity.isVisualTestingEnabled());
testcaseResultMap.put(testCaseEntity.getId(), testCaseResult);
if (skipExecution) {
testCaseResult.setMessage(resultFailureMessage);
} else if (hasPreRequisite(testCaseEntity)) {
testCasePrerequisiteFailed = checkTestCasePrerequisiteFailure(testCaseEntity, testCaseResult);
}
try {
if (!testCaseEntity.getIsDataDriven()) {
testCaseEntity = getTestCase(testCaseEntity, this.testCaseFetchMaxTries);
new ErrorUtil().checkError(testCaseEntity.getErrorCode(), testCaseEntity.getMessage());
}
} catch (AutomatorException e) {
log.error(e.getMessage(), e);
testCaseRunFailed = true;
resultFailureMessage = e.getMessage();
testCaseResult.setResult(ResultConstant.FAILURE);
testCaseResult.setMessage(resultFailureMessage);
}
if (!testCaseRunFailed) {
if (ExecutionEnvironmentRunner.isRunning()) {
testSuiteResult.setSessionCreatedOn(new Timestamp(System.currentTimeMillis()));
if (testCaseEntity.getIsDataDriven()) {
runDataDrivenTestCase(testCaseEntity, testCaseResult, false, testCasePrerequisiteFailed);
} else {
new TestcaseRunner(testCaseEntity, testCaseResult, mapStepResult, skipExecution || testCasePrerequisiteFailed, resultFailureMessage).run();
}
executionStarted = true;
} else {
testCaseResult.setResult(ResultConstant.STOPPED);
testCaseResult.setMessage(AutomatorMessages.MSG_USER_ABORTED_EXECUTION);
testCaseResult.setEndTime(new Timestamp(System.currentTimeMillis()));
postTestcaseResult(testCaseResult);
break;
}
}
testCaseResult.setEndTime(new Timestamp(System.currentTimeMillis()));
postTestcaseResult(testCaseResult);
} catch (Exception ex) {
log.error("Unhandled exception while processing test case");
log.error(ex.getMessage(), ex);
testCaseResult.setResult(ResultConstant.ABORTED);
testCaseResult.setMessage(ex.getMessage());
try {
postTestcaseResult(testCaseResult);
} catch (Exception e) {
log.error("Unhandled exception while posting test case results");
log.error(e.getMessage(), e);
}
}
if (testCaseResult.getResult().getId() > testSuiteResult.getResult().getId()) {
testSuiteResult.setResult(testCaseResult.getResult());
}
}
testSuiteResult.setSessionCompletedOn(new Timestamp(System.currentTimeMillis()));
testSuiteResult.setEndTime(new Timestamp(System.currentTimeMillis()));
if (testSuiteResult.getResult() == ResultConstant.SUCCESS) {
testSuiteResult.setMessage(AutomatorMessages.MSG_GROUP_SUCCESS);
} else if (StringUtils.isBlank(testSuiteResult.getMessage())) {
testSuiteResult.setMessage(AutomatorMessages.MSG_GROUP_FAILED);
}
resetThreadContextData();
}
use of com.testsigma.automator.utilities.ErrorUtil in project testsigma by testsigmahq.
the class EnvironmentRunner method beforeExecute.
protected void beforeExecute() throws AutomatorException {
checkForEmptyEnvironment();
new ScreenCaptureUtil().createScreenshotsFolder();
new ErrorUtil().checkError(testDeviceEntity.getErrorCode(), null);
new DriversUpdateService().syncBrowserDriver(testDeviceEntity);
}
Aggregations