Search in sources :

Example 81 with AutomatorException

use of com.testsigma.automator.exceptions.AutomatorException in project testsigma by testsigmahq.

the class WaitUntilTextIsAbsentAction method execute.

@Override
protected void execute() throws Exception {
    try {
        boolean textNotPresent = getWebDriverWait().until(ExpectedConditions.not(CustomExpectedConditions.mobileTextToBePresent(getTestData())));
        Assert.isTrue(textNotPresent, String.format(FAILURE_MESSAGE, getTimeout(), getTestData()));
        setSuccessMessage(SUCCESS_MESSAGE);
    } catch (TimeoutException e) {
        throw new AutomatorException(String.format(FAILURE_MESSAGE, getTimeout(), getTestData()), (Exception) e.getCause());
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) AutomatorException(com.testsigma.automator.exceptions.AutomatorException) TimeoutException(org.openqa.selenium.TimeoutException) TimeoutException(org.openqa.selenium.TimeoutException)

Example 82 with AutomatorException

use of com.testsigma.automator.exceptions.AutomatorException in project testsigma by testsigmahq.

the class TestsuiteRunner method getTestCase.

private TestCaseEntity getTestCase(TestCaseEntity testCaseEntity, int maxTries) throws AutomatorException {
    try {
        TestCaseEntity testCaseEntityCopy = testCaseEntity;
        testCaseEntity = AutomatorConfig.getInstance().getAppBridge().getTestCase(environmentRunResult.getId(), testCaseEntity);
        if (testCaseEntity != null) {
            if (ResultConstant.STOPPED == testCaseEntity.getResult()) {
                ExecutionEnvironmentRunner.setStoppedStatus();
            }
        }
        if ((testCaseEntity.getErrorCode() != null) && maxTries > 0) {
            RemoteWebDriver remoteWebDriver = DriverManager.getDriverManager().getDriver().getRemoteWebDriver();
            remoteWebDriver.getWindowHandle();
            Thread.sleep(this.testCaseFetchWaitInterval);
            return getTestCase(testCaseEntityCopy, maxTries - 1);
        }
        return testCaseEntity;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new AutomatorException(ErrorCodes.TEST_CASE_DETAILS_FETCH_FAILED, AutomatorMessages.FAILED_TO_FETCH_TEST_CASE_DETAILS + " - " + e.getMessage());
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) AutomatorException(com.testsigma.automator.exceptions.AutomatorException)

Example 83 with AutomatorException

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

Example 84 with AutomatorException

use of com.testsigma.automator.exceptions.AutomatorException in project testsigma by testsigmahq.

the class WebTestcaseStepRunner method execute.

protected void execute(Map<String, String> envSettings, TestCaseStepResult testCaseStepResult, TestCaseStepEntity testcaseStep, TestCaseResult testCaseResult) throws AutomatorException {
    this.settings = EnvironmentRunner.getRunnerEnvironmentEntity().getTestPlanSettings();
    this.testcaseStep = testcaseStep;
    this.testCaseResult = testCaseResult;
    this.envSettings = envSettings;
    this.testCaseStepResult = testCaseStepResult;
    runtimeDataProvider = new RuntimeDataProvider();
    setInitialElementData();
    try {
        updateRuntimeValueInElement();
        updateRuntimeValueInTestData();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        this.testCaseStepResult.setResult(ResultConstant.FAILURE);
        this.testCaseStepResult.setMessage(e.getMessage());
        return;
    }
    execute();
    if (isAutomatorException() && settings.getHasSuggestionFeature() && testcaseStep.getAddonNaturalTextActionEntity() == null) {
        diagnoseStepFailure();
    }
}
Also used : RuntimeDataProvider(com.testsigma.automator.utilities.RuntimeDataProvider) AutomatorException(com.testsigma.automator.exceptions.AutomatorException) NaturalActionException(com.testsigma.automator.actions.exceptions.NaturalActionException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 85 with AutomatorException

use of com.testsigma.automator.exceptions.AutomatorException in project testsigma by testsigmahq.

the class DriverManager method startSession.

public void startSession(DriverSessionType driverSessionType, Long entityId, Boolean isRestart) throws AutomatorException {
    RemoteWebDriver remoteWebDriver;
    beforeSessionCreateActions();
    try {
        remoteWebDriver = createDriverSession();
        storeSessionId(driverSessionType, entityId);
        this.isRestart = isRestart;
        if (!isRestart) {
            this.initialSessionId = getSessionId();
            log.info("Initial Session ID:" + this.initialSessionId);
        } else {
            this.restartSessionId = getSessionId();
            log.info("Restarted Session ID:" + this.restartSessionId);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        String errorMessage = parseErrorMessage(e.getMessage());
        if (StringUtils.isBlank(errorMessage)) {
            errorMessage = AutomatorMessages.EXCEPTION_WEBDRIVER_NOTCREATED + " - " + e.getMessage();
        } else {
            errorMessage = "Unable to create a new Test Session due to unexpected failure(0x537). " + errorMessage;
        }
        endSession();
        throw new AutomatorException(ErrorCodes.DRIVER_NOT_CREATED, errorMessage);
    }
    if (remoteWebDriver != null) {
        log.info("Driver Session ID - " + getSessionId());
    } else {
        throw new AutomatorException(ErrorCodes.DRIVER_NOT_CREATED, AutomatorMessages.EXCEPTION_WEBDRIVER_NOTCREATED);
    }
    afterSessionCreateActions();
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) AutomatorException(com.testsigma.automator.exceptions.AutomatorException) IOException(java.io.IOException)

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