use of com.testsigma.automator.exceptions.AutomatorException in project testsigma by testsigmahq.
the class RestAPIRunTimeDataProcessor method updateExpectedHeaderRuntimeVariables.
private void updateExpectedHeaderRuntimeVariables() throws AutomatorException {
log.debug("Updating runtime data in expected Header, RestStep ID:" + restfulStepEntity.getId());
try {
String updatedExpectedHeaders = replaceRuntimeVariables(restfulStepEntity.getResponseHeaders());
restfulStepEntity.setResponseHeaders(updatedExpectedHeaders);
} catch (AutomatorException e) {
throw new AutomatorException("Error while replacing runtime variables in Verify Response headers." + e.getMessage());
}
}
use of com.testsigma.automator.exceptions.AutomatorException in project testsigma by testsigmahq.
the class RestAPIRunTimeDataProcessor method storeRuntimeVariblesJsonPath.
private void storeRuntimeVariblesJsonPath(String expectedStr, String actualStr) throws AutomatorException {
if (StringUtils.isNotBlank(expectedStr) && StringUtils.isNotBlank(actualStr)) {
boolean jsonPathValidationsFailed = false;
List<String> failedJsonPathsList = new ArrayList<>();
Map<String, String> pathMap = new ObjectMapperService().parseJson(expectedStr, new TypeReference<>() {
});
for (Map.Entry<String, String> map : pathMap.entrySet()) {
String name = map.getKey();
String path = map.getValue();
Object pathResult;
try {
if (path.equals(JSON_PATH_ALL)) {
pathResult = actualStr;
} else {
pathResult = JsonPath.parse(actualStr).read(path);
}
new RuntimeDataProvider().storeRuntimeVariable(name, pathResult.toString());
} catch (PathNotFoundException e) {
jsonPathValidationsFailed = true;
failedJsonPathsList.add(path);
log.error("JSON Path Error while saving response to runtime variable.", e);
}
}
if (jsonPathValidationsFailed) {
throw new AutomatorException(String.format(MSG_REST_RESPONSE_JSON_PATH_NOT_EXIST, failedJsonPathsList));
}
}
}
use of com.testsigma.automator.exceptions.AutomatorException in project testsigma by testsigmahq.
the class RestApiResponseValidator method validateJsonPath.
private void validateJsonPath(String expectedStr, String actualStr, String msg) throws AutomatorException {
if (StringUtils.isNotBlank(expectedStr)) {
Map<String, String> expectedMap = new ObjectMapperService().parseJson(expectedStr, new TypeReference<>() {
});
for (Map.Entry<String, String> map : expectedMap.entrySet()) {
String path = map.getKey();
String value = map.getValue();
Object pathResult;
try {
pathResult = JsonPath.parse(actualStr).read(path);
} catch (PathNotFoundException e) {
log.error("JSON Path Error while validating response .", e);
throw new AutomatorException(String.format(MSG_REST_RESPONSE_JSON_PATH_NOT_EXIST, path));
}
String pathResultStr;
StringBuilder sb = (testCaseStepResult.getMessage() != null) ? new StringBuilder(testCaseStepResult.getMessage()).append(AutomatorMessages.MSG_SEPARATOR) : new StringBuilder();
if (pathResult instanceof String || pathResult instanceof Number) {
pathResultStr = pathResult.toString();
if (!value.equals(pathResultStr)) {
msg = sb.append(msg).append(AutomatorMessages.MSG_SEPARATOR).append(AutomatorMessages.getMessage(AutomatorMessages.MSG_REST_ERROR_PATH, path)).toString();
testCaseStepResult.setResult(ResultConstant.FAILURE);
testCaseStepResult.setMessage(msg);
}
} else {
pathResultStr = new ObjectMapperService().convertToJson(pathResult);
if (!value.equals(pathResultStr)) {
new ObjectMapperService().parseJson(pathResultStr, Object.class);
validateJson(pathResultStr, value, JSONCompareMode.STRICT.name(), msg);
}
}
}
}
}
use of com.testsigma.automator.exceptions.AutomatorException in project testsigma by testsigmahq.
the class MobileNativeCheckAction method execute.
@Override
public void execute() throws Exception {
findElement();
WebElement targetElement = getElement();
String checkable = targetElement.getAttribute(CHECKABLE);
String checked = targetElement.getAttribute(CHECKED);
if (checkable.equals(TRUE)) {
if (!checked.equals(TRUE)) {
targetElement.click();
} else {
log.warn("The target element state is already checked, hence no action performed to check.");
setSuccessMessage(String.format(SUCCESS_MESSAGE_ALREADY_CHECKED, getFindByType(), getLocatorValue()));
return;
}
} else {
throw new AutomatorException(String.format(ELEMENT_IS_NOT_CHECKABLE, getElementSearchCriteria().getFindByType(), getElementSearchCriteria().getByValue()));
}
setSuccessMessage(SUCCESS_MESSAGE);
}
use of com.testsigma.automator.exceptions.AutomatorException 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);
}
}
Aggregations