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));
}
}
}
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());
}
}
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;
}
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();
}
}
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));
}
Aggregations