Search in sources :

Example 1 with RuntimeDataProvider

use of com.testsigma.automator.utilities.RuntimeDataProvider 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 2 with RuntimeDataProvider

use of com.testsigma.automator.utilities.RuntimeDataProvider in project testsigma by testsigmahq.

the class TestcaseStepRunner method setTestDataValue.

protected void setTestDataValue(TestCaseStepEntity step, Map<String, String> envDetails, TestCaseResult testCaseResult, TestCaseStepResult testCaseStepResult) throws AutomatorException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, IOException, InvocationTargetException {
    if (step.getTestDataMap() == null)
        return;
    int index = 0;
    Map<String, TestDataPropertiesEntity> testDataPropertiesEntityMap = step.getTestDataMap();
    for (Map.Entry<String, TestDataPropertiesEntity> entry : testDataPropertiesEntityMap.entrySet()) {
        TestDataPropertiesEntity testDataPropertiesEntity = entry.getValue();
        TestDataType testDataType = TestDataType.getTestDataType(ObjectUtils.defaultIfNull(testDataPropertiesEntity.getTestDataType(), "raw"));
        switch(testDataType) {
            case runtime:
                if (!step.getAction().startsWith("Store ")) {
                    RuntimeDataProvider runtimeDataProvider = new RuntimeDataProvider();
                    testDataPropertiesEntity.setTestDataValue(runtimeDataProvider.getRuntimeData(testDataPropertiesEntity.getTestDataValue()));
                }
                break;
            case random:
                testDataPropertiesEntity.setTestDataValue(RandomStringUtils.randomAlphanumeric(Integer.parseInt(testDataPropertiesEntity.getTestDataValue())));
                break;
            case function:
                if (!testDataPropertiesEntity.getDefaultDataGeneratorsEntity().getIsAddonFn()) {
                    DefaultDataGeneratorsEntity testDataFunctionEntity = testDataPropertiesEntity.getDefaultDataGeneratorsEntity();
                    DefaultDataGeneratorsExecutor testDataFunctionExecutor = new DefaultDataGeneratorsExecutor();
                    testDataFunctionExecutor.setTestCaseResult(testCaseResult);
                    testDataFunctionExecutor.setSettings(envDetails);
                    testDataFunctionExecutor.setDefaultDataGeneratorsEntity(testDataFunctionEntity);
                    String testDataValue = testDataFunctionExecutor.generate();
                    testDataPropertiesEntity.setTestDataName(testDataPropertiesEntity.getTestDataValue());
                    testDataPropertiesEntity.setTestDataValue(testDataValue);
                } else {
                    setTestDataValueFromAddonTestDataFunction(step, index, testDataPropertiesEntity, testCaseStepResult);
                    index++;
                }
                break;
        }
        step.setTestDataName(testDataPropertiesEntity.getTestDataName());
        step.setTestDataValue(testDataPropertiesEntity.getTestDataValue());
    }
}
Also used : RuntimeDataProvider(com.testsigma.automator.utilities.RuntimeDataProvider)

Example 3 with RuntimeDataProvider

use of com.testsigma.automator.utilities.RuntimeDataProvider in project testsigma by testsigmahq.

the class RestAPIRunTimeDataProcessor method replaceRuntimeVariables.

private String replaceRuntimeVariables(String inputData) throws AutomatorException {
    log.debug("Replacing runtime parameters in :" + inputData);
    String updatedData = inputData;
    String[] names = StringUtils.substringsBetween(inputData, NaturalTextActionConstants.restDataiRunStartPattern, NaturalTextActionConstants.restDataiRunaEndPattern);
    if (names == null) {
        return inputData;
    }
    for (String runTimeVarName : names) {
        String runTimeValue = new RuntimeDataProvider().getRuntimeData(runTimeVarName);
        if (runTimeValue == null) {
            throw new AutomatorException(String.format(MSG_RUN_TIME_VARIABLE_NOT_SET, runTimeVarName));
        }
        String runTimeVarPattern = String.format("%s%s%s", NaturalTextActionConstants.restDataRunStartPattern, Pattern.quote(runTimeVarName), NaturalTextActionConstants.restDatRunaEndPattern);
        updatedData = updatedData.replaceAll(runTimeVarPattern, Matcher.quoteReplacement(runTimeValue));
        log.debug(String.format("Replaced runtime var:%s with %s", runTimeVarName, runTimeValue));
    }
    return updatedData;
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) RuntimeDataProvider(com.testsigma.automator.utilities.RuntimeDataProvider)

Example 4 with RuntimeDataProvider

use of com.testsigma.automator.utilities.RuntimeDataProvider 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 5 with RuntimeDataProvider

use of com.testsigma.automator.utilities.RuntimeDataProvider in project testsigma by testsigmahq.

the class DriverManager method afterEndSessionActions.

protected void afterEndSessionActions() throws AutomatorException {
    log.debug("Executing after end session actions for execution UUID - " + executionUuid);
    new RuntimeDataProvider().clearRunTimeData(executionUuid);
    getDriver().setRemoteWebDriver(null);
    setDriver(null);
    sessionEndInstant = Instant.now();
    log.info("Total session time - " + TimeUtil.getFormattedDuration(sessionStartInstant, sessionEndInstant));
}
Also used : RuntimeDataProvider(com.testsigma.automator.utilities.RuntimeDataProvider)

Aggregations

RuntimeDataProvider (com.testsigma.automator.utilities.RuntimeDataProvider)5 AutomatorException (com.testsigma.automator.exceptions.AutomatorException)3 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)1 NaturalActionException (com.testsigma.automator.actions.exceptions.NaturalActionException)1 ObjectMapperService (com.testsigma.automator.service.ObjectMapperService)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1