Search in sources :

Example 41 with AutomatorException

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());
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException)

Example 42 with AutomatorException

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));
        }
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) ObjectMapperService(com.testsigma.automator.service.ObjectMapperService) ArrayList(java.util.ArrayList) RuntimeDataProvider(com.testsigma.automator.utilities.RuntimeDataProvider) PathNotFoundException(com.jayway.jsonpath.PathNotFoundException) Map(java.util.Map)

Example 43 with AutomatorException

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);
                }
            }
        }
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) ObjectMapperService(com.testsigma.automator.service.ObjectMapperService) JSONObject(org.json.JSONObject) PathNotFoundException(com.jayway.jsonpath.PathNotFoundException) Map(java.util.Map)

Example 44 with AutomatorException

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);
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) WebElement(org.openqa.selenium.WebElement)

Example 45 with AutomatorException

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);
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) Timestamp(java.sql.Timestamp) ErrorUtil(com.testsigma.automator.utilities.ErrorUtil)

Aggregations

AutomatorException (com.testsigma.automator.exceptions.AutomatorException)119 TimeoutException (org.openqa.selenium.TimeoutException)31 WebElement (org.openqa.selenium.WebElement)19 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)9 Select (org.openqa.selenium.support.ui.Select)6 TestsigmaException (com.testsigma.agent.exception.TestsigmaException)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 RuntimeDataProvider (com.testsigma.automator.utilities.RuntimeDataProvider)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Map (java.util.Map)3 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)3 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)3 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)2 ElementNotDisplayedException (com.testsigma.automator.actions.exceptions.ElementNotDisplayedException)2 MobileApp (com.testsigma.automator.mobile.MobileApp)2 ObjectMapperService (com.testsigma.automator.service.ObjectMapperService)2 ErrorUtil (com.testsigma.automator.utilities.ErrorUtil)2 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2