Search in sources :

Example 1 with NaturalActionException

use of com.testsigma.automator.actions.exceptions.NaturalActionException in project testsigma by testsigmahq.

the class ActionStepExecutor method execute.

public void execute() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, NoSuchMethodException, AutomatorException, ClassNotFoundException, InstantiationException {
    Class<?> className = Class.forName(testCaseStepEntity.getSnippetClass());
    DriverAction snippet = (DriverAction) className.getDeclaredConstructor().newInstance();
    snippet.setDriver(DriverManager.getRemoteWebDriver());
    snippet.setTimeout(testCaseStepEntity.getWaitTime().longValue());
    snippet.setTestDataPropertiesEntityMap(testCaseStepEntity.getTestDataMap());
    snippet.setElementPropertiesEntityMap(testCaseStepEntity.getElementsMap());
    snippet.setAttributesMap(testCaseStepEntity.getAttributesMap());
    snippet.setGlobalElementTimeOut(testCaseStepResult.getTestPlanRunSettingEntity().getElementTimeOut().longValue());
    snippet.setRuntimeDataProvider(prepareRunTimeDataProvider());
    snippet.setEnvSettings(envSettings);
    snippet.setAdditionalData(testCaseStepEntity.getAdditionalData());
    ActionResult snippetResult = snippet.run();
    // We retry test step execution on failure based on the exception type.
    snippetResult = reTrySnippetIfEligible(snippetResult, snippet, testCaseStepEntity, testCaseStepResult);
    testCaseStepResult.getMetadata().setSnippetResultMetadata(snippet.getResultMetadata());
    testCaseStepResult.getOutputData().putAll(snippet.getTestDataParams());
    if (snippetResult == ActionResult.FAILED) {
        log.error("Test case step FAILED....");
        NaturalActionException naturalActionException = new NaturalActionException(snippet.getErrorMessage(), snippet.getException(), snippet.getErrorCode().getErrorCode().intValue());
        testCaseStepResult.setWebDriverException(naturalActionException.getErrorStackTraceTruncated());
        testCaseStepResult.setErrorCode(snippet.getErrorCode().getErrorCode().intValue());
        testCaseStepResult.setMessage(snippet.getErrorMessage());
        markTestcaseAborted(testCaseResult, testCaseStepResult, snippet);
        testCaseStepResult.getMetadata().setLog(testCaseStepResult.getWebDriverException());
        // We are throwing an InvocationTargetException to handle Auto Healing
        throw naturalActionException;
    } else {
        testCaseStepResult.setMessage(snippet.getSuccessMessage());
    }
}
Also used : ActionResult(com.testsigma.automator.constants.ActionResult) NaturalActionException(com.testsigma.automator.actions.exceptions.NaturalActionException) DriverAction(com.testsigma.automator.actions.DriverAction)

Example 2 with NaturalActionException

use of com.testsigma.automator.actions.exceptions.NaturalActionException in project testsigma by testsigmahq.

the class AddonNaturalTextActionStepExecutor method execute.

public void execute() throws IOException, IllegalAccessException, NoSuchMethodException, ClassNotFoundException, InvocationTargetException, InstantiationException, AutomatorException, NoSuchFieldException, NaturalActionException {
    AddonAction addonAction = new AddonAction(testCaseStepEntity, testCaseStepResult, this.addonElementPropertiesEntity, this.envSettings);
    ActionResult snippetResult = addonAction.run();
    if (snippetResult == ActionResult.FAILED) {
        log.error("Test case step FAILED....");
        NaturalActionException actionException;
        if (addonAction.getException() != null) {
            actionException = new NaturalActionException(addonAction.getErrorMessage(), addonAction.getException(), addonAction.getErrorCode().getErrorCode().intValue());
        } else {
            actionException = new NaturalActionException(addonAction.getErrorMessage());
        }
        testCaseStepResult.setWebDriverException(actionException.getErrorStackTraceTruncated());
        testCaseStepResult.setErrorCode(addonAction.getErrorCode().getErrorCode().intValue());
        testCaseStepResult.setMessage(addonAction.getErrorMessage());
        markTestcaseAborted(testCaseResult, testCaseStepResult, addonAction);
        testCaseStepResult.getMetadata().setLog(testCaseStepResult.getWebDriverException());
        // We are throwing an InvocationTargetException to handle Auto Healing
        throw actionException;
    } else {
        testCaseStepResult.setMessage(addonAction.getSuccessMessage());
    }
}
Also used : ActionResult(com.testsigma.automator.constants.ActionResult) NaturalActionException(com.testsigma.automator.actions.exceptions.NaturalActionException) AddonAction(com.testsigma.automator.actions.AddonAction)

Aggregations

NaturalActionException (com.testsigma.automator.actions.exceptions.NaturalActionException)2 ActionResult (com.testsigma.automator.constants.ActionResult)2 AddonAction (com.testsigma.automator.actions.AddonAction)1 DriverAction (com.testsigma.automator.actions.DriverAction)1