Best Testsigma code snippet using com.testsigma.automator.runners.TestcaseStepRunner.execute
Source:TestcaseStepRunner.java
...146 testCaseStepResult.setSkipMessage(AutomatorMessages.MSG_STEP_PRE_REQUISITE_FAILED);147 }148 if (testCaseStepEntity.getType() != null && testCaseStepEntity.getType() == TestStepType.FOR_LOOP) {149 log.debug("For loop execution starts:" + testCaseStepEntity.getId() + " With Iteration:" + testCaseStepEntity.getIteration());150 status = executeForLoop(testCaseStepEntity, testCaseStepResult, testCaseStepResultMap, testCaseResult, parentStatus,151 failedToProcess, screenCaptureUtil, status);152 } else if (testCaseStepEntity.getType() != null && testCaseStepEntity.getType() == TestStepType.WHILE_LOOP) {153 log.debug("While loop execution starts:" + testCaseStepEntity.getId());154 status = executeWhileLoop(testCaseStepEntity, testCaseStepResult,155 testCaseStepResultMap, testCaseResult, parentStatus,156 failedToProcess, screenCaptureUtil, status);157 } else if (isStepGroup) {158 log.debug("Step type is Step Group. Executing Test Component with ID - " + testCaseStepEntity.getStepGroupId());159 status = executeStepGroup(testCaseStepEntity, testCaseStepResult, testCaseStepResultMap, testCaseResult, parentStatus,160 failedToProcess, screenCaptureUtil, status);161 } else if (isRunning && !testCaseStepResult.getSkipExe() && !preReqFailed) {162 setTestDataValue(testCaseStepEntity, envDetails, testCaseResult, testCaseStepResult);163 testCaseStepResult.setElementDetails(testCaseStepEntity.getElementsMap());164 testCaseStepResult.setTestDataDetails(testCaseStepEntity.getTestDataMap());165 log.debug("Step type is normal. Executing normal Action step");166 execute(envDetails, testCaseStepResult, testCaseStepEntity, testCaseResult);167 ObjectMapper mapper = new ObjectMapper();168 mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);169 Map<String, Object> metadata = mapper.convertValue(testCaseStepEntity, Map.class);170 Map<String, Object> oldMetadata = mapper.convertValue(testCaseStepResult.getMetadata(), Map.class);171 oldMetadata.putAll(metadata);172 StepResultMetadataEntity metadataEntity = mapper.convertValue(oldMetadata, StepResultMetadataEntity.class);173 testCaseStepResult.setMetadata(metadataEntity);174 testCaseStepResult.getMetadata().setTestStep(testCaseStepEntity);175 takeScreenshot(workspaceType, testCaseStepEntity, testCaseStepResult,176 testPlanRunSettingEntity.getScreenshot(), screenCaptureUtil);177 if (testCaseStepEntity.getConditionType() != null && (testCaseStepEntity.getConditionType() != ConditionType.NOT_USED)) {178 setConditionResult(testCaseStepEntity, testCaseStepResult, parentStatus);179 status = (testCaseStepResult.getResult() != ResultConstant.SUCCESS) ? testCaseStepResult.getResult() : status;180 } else {181 status = (testCaseStepResult.getResult() != ResultConstant.SUCCESS) ? testCaseStepResult.getResult() : status;182 if ((status == ResultConstant.SUCCESS) && StringUtils.isBlank(testCaseStepResult.getMessage())) {183 testCaseStepResult.setMessage(AutomatorMessages.MSG_STEP_SUCCESS);184 } else if (StringUtils.isBlank(testCaseStepResult.getMessage())) {185 testCaseStepResult.setMessage(AutomatorMessages.MSG_STEP_FAILURE);186 }187 }188 log.debug("Test Step Result - " + status);189 }190 log.debug("Test Step Result [2] - " + status);191 boolean majorFailure = (status != ResultConstant.SUCCESS && status != ResultConstant.ABORTED) &&192 (testCaseStepEntity.getPriority() == TestStepPriority.MAJOR &&193 testPlanRunSettingEntity.getRecoveryAction() == RecoverAction.Run_Next_Testcase);194 boolean hasToAbortTestcase = (majorFailure && !isGroupStep && !isStepGroup);195 if (!testCaseStepResult.getSkipExe() && hasToAbortTestcase) {196 setFailedMessage(testCaseStepResult, testCaseResult, testCaseStepEntity.getStepDetails().getIgnoreStepResult());197 }198 //Add Loop level result199 if (testCaseStepEntity.getType() == TestStepType.BREAK_LOOP && status == ResultConstant.SUCCESS) {200 testCaseStepResult.setIsBreakLoop(true);201 } else if (testCaseStepEntity.getType() == TestStepType.CONTINUE_LOOP && status == ResultConstant.SUCCESS) {202 testCaseStepResult.setIsContinueLoop(true);203 }204 } catch (UnreachableBrowserException e) {205 status = ResultConstant.FAILURE;206 testCaseStepResult.setErrorCode(com.testsigma.automator.constants.ErrorCodes.BROWSER_CLOSED);207 testCaseStepResult.setMessage(String.format(BROWSER_UNREACHABLE));208 } catch (NoSuchSessionException e) {209 status = ResultConstant.FAILURE;210 testCaseStepResult.setMessage(String.format(INVALID_SESSION));211 } catch (Exception e) {212 log.error(e.getMessage(), e);213 status = ResultConstant.FAILURE;214 testCaseStepResult.setErrorCode(com.testsigma.automator.constants.ErrorCodes.UNKNOWN_PROBLEM);215 if(testCaseStepResult.getMessage()==null)216 testCaseStepResult.setMessage(e.getMessage());217 }218 resetThreadContextData();219 testCaseStepResult.setResult(status);220 testCaseStepResult.setEndTime(new Timestamp(System.currentTimeMillis()));221 log.debug("Finished Executing Test Case Step - " + testCaseStepResult.getTestCaseStepId());222 return testCaseStepResult;223 }224 protected ResultConstant executeStepGroup(TestCaseStepEntity testCaseStepEntity, TestCaseStepResult testCaseStepResult,225 Map<Long, TestCaseStepResult> testCaseStepResultMap, TestCaseResult testCaseResult,226 HashMap<Long, TestCaseStepResult> parentStatus, boolean failedToProcess,227 ScreenCaptureUtil screenCaptureUtil, ResultConstant currentStatus) throws Exception {228 executeGroup(testCaseStepEntity, testCaseStepResult, testCaseStepResultMap, testCaseResult, parentStatus, failedToProcess, screenCaptureUtil);229 if (testCaseStepEntity.getConditionType() != null && (testCaseStepEntity.getConditionType() != ConditionType.NOT_USED)) {230 setConditionResult(testCaseStepEntity, testCaseStepResult, parentStatus);231 }232 ResultConstant status = (testCaseStepResult.getResult() != ResultConstant.SUCCESS) ? testCaseStepResult.getResult() : currentStatus;233 if ((status == ResultConstant.SUCCESS)) {234 testCaseStepResult.setMessage(AutomatorMessages.MSG_STEP_GROUP_SUCCESS);235 } else if (StringUtils.isBlank(testCaseStepResult.getMessage())) {236 testCaseStepResult.setMessage(AutomatorMessages.MSG_STEP_GROUP_FAILURE);237 }238 return status;239 }240 protected ResultConstant executeForLoop(TestCaseStepEntity testCaseStepEntity, TestCaseStepResult forLoopResultObj,241 Map<Long, TestCaseStepResult> testCaseStepResultMap, TestCaseResult tresult,242 HashMap<Long, TestCaseStepResult> parentStatus, boolean failedToProcess,243 ScreenCaptureUtil screenCaptureUtil, ResultConstant currentStatus) throws Exception {244 log.debug("Step type is FOR_LOOP. Executing it:" + testCaseStepEntity);245 //In for loop , if there is a continue step encountered in prev iteration, we should not skip execution or loop.246 TestCaseStepResult previousLoopResultIfAny = testCaseStepResultMap.get(testCaseStepEntity.getId());247 if (previousLoopResultIfAny != null && previousLoopResultIfAny.getIsContinueLoop()) {248 forLoopResultObj.setSkipExe(false);249 } else if (previousLoopResultIfAny != null && previousLoopResultIfAny.getIsBreakLoop()) {250 forLoopResultObj.setSkipExe(true);251 }252 executeGroup(testCaseStepEntity, forLoopResultObj, testCaseStepResultMap, tresult, parentStatus, failedToProcess, screenCaptureUtil);253 //previous loop encountered a break ,We need to disable skipExe, else further testcases(After loop) will not be executed.254 if (previousLoopResultIfAny != null && previousLoopResultIfAny.getIsBreakLoop()) {255 forLoopResultObj.setIsBreakLoop(true);256 forLoopResultObj.setSkipExe(false);//If skip is true, execution will not be continued after the loop.257 forLoopResultObj.setResult(ResultConstant.SUCCESS);258 }259 forLoopResultObj.setIndex(testCaseStepEntity.getIndex());260 forLoopResultObj.setIteration(testCaseStepEntity.getIteration());261 forLoopResultObj.setTestDataProfileName(testCaseStepEntity.getTestDataProfileName());262 ResultConstant status = (currentStatus.getId() < forLoopResultObj.getResult().getId()) ? forLoopResultObj.getResult() : currentStatus;263 if ((forLoopResultObj.getResult() == ResultConstant.SUCCESS)) {264 forLoopResultObj.setMessage(AutomatorMessages.getMessage(AutomatorMessages.MSG_ITERATION_SUCCESS, testCaseStepEntity.getIndex()));265 } else if (StringUtils.isBlank(forLoopResultObj.getMessage())) {266 forLoopResultObj.setMessage(AutomatorMessages.getMessage(AutomatorMessages.MSG_ITERATION_FAILURE, testCaseStepEntity.getIndex()));267 }268 return status;269 }270 protected ResultConstant executeWhileLoop(TestCaseStepEntity testcaseStep, TestCaseStepResult whileLoopResultObj, Map<Long, TestCaseStepResult> mapStepResult,271 TestCaseResult tresult, HashMap<Long, TestCaseStepResult> parentStatus,272 boolean failedToProcess, ScreenCaptureUtil screenCaptureUtil, ResultConstant currentStatus) throws Exception {273 Long envRunId = EnvironmentRunner.getRunnerEnvironmentRunResult().getId();274 log.debug("Executing while loop:" + testcaseStep);275 TestCaseStepEntity whileConditionStep = testcaseStep.getTestCaseSteps().get(0);276 List<TestCaseStepResult> whileLoopIterationResults = new ArrayList<>();277 boolean breakLoop = false;278 ResultConstant whileLoopResult = ResultConstant.SUCCESS;279 boolean conditionFailed = false;280 int noOfIterationsCompleted = 0;281 //Iterations loop, we are limiting max loop count to ActionConstants.WHILE_LOOP_MAX_LIMIT282 for (int i = 1; i <= NaturalTextActionConstants.WHILE_LOOP_MAX_LIMIT; i++) {283 if (breakLoop) {284 break;285 }286 TestCaseStepResult whileConditionStepResult = new TestCaseStepResult();287 whileConditionStepResult.setEnvRunId(envRunId);288 whileConditionStepResult.setTestCaseResultId(tresult.getId());289 whileConditionStepResult.setTestCaseStepId(whileConditionStep.getId());290 whileConditionStepResult.setSkipExe(whileLoopResultObj.getSkipExe());291 whileConditionStepResult.setSkipMessage(whileLoopResultObj.getSkipMessage());292 whileConditionStepResult.setParentResultId(whileLoopResultObj.getId());293 whileConditionStepResult.setTestCaseStepType(whileConditionStep.getType());294 whileConditionStepResult.setStepDetails(whileConditionStep.getStepDetails());295 whileConditionStepResult.setIndex(i);296 setScreenshotPathsForIteration(whileConditionStep, i);297 TestStepType type = whileConditionStep.getType();298 TestcaseStepRunner testcaseStepRunner = new TestcaseStepRunnerFactory().getRunner(workspaceType, os, type);299 testcaseStepRunner.run(whileConditionStep, whileConditionStepResult, mapStepResult, tresult, parentStatus, failedToProcess, false, screenCaptureUtil);300 if (whileConditionStepResult.getResult() != ResultConstant.SUCCESS) {301 whileConditionStepResult.setSkipExe(true);302 if (whileConditionStepResult.getResult() == ResultConstant.FAILURE) {303 whileConditionStepResult.setSkipMessage(String.format("%s<br>%s", AutomatorMessages.MSG_WHILE_CONDITION_FAILED, whileConditionStepResult.getMessage()));304 conditionFailed = true;305 }306 }307 mapStepResult.put(whileConditionStep.getId(), whileConditionStepResult);308 log.debug("While condition result :::: " + objectMapperService.convertToJson(whileConditionStepResult));309 executeGroup(whileConditionStep, whileConditionStepResult, mapStepResult, tresult, parentStatus, failedToProcess, screenCaptureUtil);310 //Update Iteration result to SUCCESS if break or continue is executed311 if (whileConditionStepResult.getIsBreakLoop() || whileConditionStepResult.getIsContinueLoop()) {312 whileConditionStepResult.setResult(ResultConstant.SUCCESS);313 }314 //If condition is passed, and while executing the group of steps inside condition, if there is a failure in group, parent status will be skipped315 if (whileConditionStepResult.getResult() == ResultConstant.SUCCESS && whileConditionStepResult.getSkipExe()) {316 whileLoopResult = ResultConstant.FAILURE;317 whileLoopResultObj.setSkipExe(true);318 }319 //While loop break condition.320 if (whileConditionStepResult.getIsBreakLoop() || whileConditionStepResult.getSkipExe()) {321 breakLoop = true;322 }323 whileLoopIterationResults.add(whileConditionStepResult);324 whileLoopResult = (whileLoopResult.getId() < whileConditionStepResult.getResult().getId()) ? whileConditionStepResult.getResult() : whileLoopResult;325 //If condition step is failed, we should not fail while loop status326 if (conditionFailed) {327 whileLoopResult = ResultConstant.SUCCESS;328 }329 noOfIterationsCompleted = i;330 }331 //Add all iteration results to parent LOOP step332 whileLoopResultObj.setStepResults(whileLoopIterationResults);333 if (whileLoopResultObj.getResult() == null) {334 whileLoopResultObj.setResult(whileLoopResult);335 }336 ResultConstant status = (currentStatus.getId() < whileLoopResultObj.getResult().getId()) ? whileLoopResultObj.getResult() : currentStatus;337 if ((whileLoopResultObj.getResult() == ResultConstant.SUCCESS)) {338 if (noOfIterationsCompleted == NaturalTextActionConstants.WHILE_LOOP_MAX_LIMIT) {339 status = ResultConstant.FAILURE;340 whileLoopResultObj.setResult(ResultConstant.FAILURE);341 whileLoopResultObj.setMessage(AutomatorMessages.MSG_WHILE_LOOP_ITERATIONS_EXHAUSTED);342 } else {343 whileLoopResultObj.setMessage(AutomatorMessages.MSG_WHILE_LOOP_SUCCESS);344 }345 } else if (whileLoopResultObj.getResult() == ResultConstant.FAILURE) {346 whileLoopResultObj.setMessage(AutomatorMessages.MSG_WHILE_LOOP_FAILURE);347 }348 return status;349 }350 protected void setScreenshotPathsForIteration(TestCaseStepEntity testStepEntity, int iterationNumber) {351 String key = String.format("%s_%s", iterationNumber, testStepEntity.getIndex());352 Map<String, String> conditionStepScreenshots = testStepEntity.getAdditionalScreenshotPaths();353 testStepEntity.setScreenshotPath(conditionStepScreenshots.get(key));354 if (testStepEntity.getTestCaseSteps() != null && testStepEntity.getTestCaseSteps().size() > 0) {355 for (TestCaseStepEntity childStep : testStepEntity.getTestCaseSteps()) {356 setScreenshotPathsForIteration(childStep, iterationNumber);357 }358 }359 }360 private void executeGroup(TestCaseStepEntity testcaseStep, TestCaseStepResult result, Map<Long, TestCaseStepResult> mapStepResult,361 TestCaseResult tresult, HashMap<Long, TestCaseStepResult> parentStatus,362 boolean failedToProcess, ScreenCaptureUtil ScreenCaptureUtil) throws Exception {363 ExecutionLabType exeType = EnvironmentRunner.getRunnerEnvironmentEntity().getExecutionLabType();364 TestPlanRunSettingEntity settings = EnvironmentRunner.getRunnerEnvironmentEntity().getTestPlanSettings();365 Long envRunId = EnvironmentRunner.getRunnerEnvironmentRunResult().getId();366 List<TestCaseStepResult> stepResults = new ArrayList<>();367 result.setStepResults(stepResults);368 ResultConstant status = ResultConstant.SUCCESS;369 Boolean skipExe = result.getSkipExe();370 String message = result.getSkipMessage();371 boolean isMajorStepGroupFailure =372 (testcaseStep.getPriority().equals(TestStepPriority.MAJOR) &&373 settings.getRecoveryAction() == RecoverAction.Run_Next_Testcase);374 boolean isStepGroup = (testcaseStep.getStepGroupId() != null && testcaseStep.getStepGroupId() > 0);375 boolean breakLoopStepExecuted = false;376 boolean continueLoopStepExecuted = false;377 for (TestCaseStepEntity childStep : testcaseStep.getTestCaseSteps()) {378 populateThreadContextData(childStep);379 log.debug("Executing group step:" + childStep.getId());380 if (breakLoopStepExecuted || continueLoopStepExecuted) {381 log.debug(String.format("Skip execution due to break/continue loop:stepGroupId=%s", childStep.getId()));382 skipExe = true;383 }384 TestCaseStepResult childStepResult = new TestCaseStepResult();385 childStepResult.setEnvRunId(envRunId);386 childStepResult.setTestCaseResultId(tresult.getId());387 childStepResult.setTestCaseStepId(childStep.getId());388 childStepResult.setSkipExe(skipExe);389 childStepResult.setSkipMessage(message);390 TestCaseStepResult parentResult = parentStatus.get(childStep.getParentId());391 childStepResult.setParentResultId(parentResult != null ? parentResult.getId() : null);392 childStepResult.setTestCaseStepType(childStep.getType());393 childStepResult.setStepDetails(childStep.getStepDetails());394 RunnerUtil util = new RunnerUtil();395 TestStepType type = childStep.getType();396 TestcaseStepRunner testcaseStepRunner = new TestcaseStepRunnerFactory().getRunner(workspaceType, os, type);397 boolean isFailure =398 (399 //this check is used to skip loop child steps check.400 //because loop step result is set only after loop is finished401 !util.isLoopSteps(isStepGroup, testcaseStep, childStep)402 && (util.canSkipNormalStep(parentResult, childStep, childStepResult)403 || util.canSkipIfElse(parentResult, childStep, childStepResult)404 || util.nestedConditionalStep(parentResult, childStep, childStepResult)405 || util.canSkipIfElseIf(parentResult, childStep, childStepResult)406 || util.canSkipElseIfElseIf(parentResult, childStep, childStepResult)407 || util.canSkipElseIfElse(parentResult, childStep, childStepResult)408 || util.canSkipIfCondition(parentResult, childStep, childStepResult)409 || util.canSkipForLoop(parentResult, childStep, childStepResult)))410 //This check for updating loop steps if loop parent is failed411 || util.canSkipForLoopTopSteps(isStepGroup, parentResult, testcaseStep, childStep, childStepResult);412 if (!skipExe && !failedToProcess && isFailure) {413 testcaseStepRunner.run(childStep, childStepResult, mapStepResult, tresult, parentStatus, false, isStepGroup, ScreenCaptureUtil);414 mapStepResult.put(childStep.getId(), childStepResult);415 stepResults.add(childStepResult);416 parentStatus.put(childStep.getId(), childStepResult);417 continue;418 }419 testcaseStepRunner.run(childStep, childStepResult, mapStepResult, tresult, parentStatus, failedToProcess, isStepGroup, ScreenCaptureUtil);420 mapStepResult.put(childStep.getId(), childStepResult);421 stepResults.add(childStepResult);422 log.debug("Result in Step Group :::: " + objectMapperService.convertToJson(childStepResult));423 if ((childStep.getConditionType() == null || childStep.getConditionType() == ConditionType.NOT_USED ||424 ConditionType.LOOP_FOR == (childStep.getConditionType()))&& (!childStep.getStepDetails().getIgnoreStepResult())) {425 status = (status.getId() < childStepResult.getResult().getId()) ? childStepResult.getResult() : status;426 }427 boolean isMajorStepFailure = isStepGroup && isStepGroupFailure(testcaseStep, childStep, childStepResult);428 if (!skipExe && isMajorStepFailure && isMajorStepGroupFailure) {429 result.setResult(ResultConstant.FAILURE);430 String majorMessage = new StringBuffer(AutomatorMessages.MSG_STEP_MAJOR_STEP_FAILURE)431 .append((childStepResult.getMessage() != null) ? childStepResult.getMessage() + "." : "")432 .append(AutomatorMessages.MSG_CHECK_FOR_MORE_DETAILS).toString();433 result.setMessage(majorMessage);434 setFailedMessage(childStepResult, tresult, testcaseStep.getStepDetails().getIgnoreStepResult());435 }436 skipExe = childStepResult.getSkipExe();437 message = childStepResult.getSkipMessage();438 //Set break loop and continue loop to group results439 if (childStepResult.getResult() == ResultConstant.SUCCESS440 && (childStepResult.getIsBreakLoop() || childStepResult.getIsContinueLoop())) {441 continueLoopStepExecuted = childStepResult.getIsContinueLoop();442 breakLoopStepExecuted = childStepResult.getIsBreakLoop();443 populateLoopConditionResult(result, childStepResult, testcaseStep);444 log.debug("Is Break loop step executed successfully:" + breakLoopStepExecuted);445 log.debug("Is Continue loop step executed successfully:" + continueLoopStepExecuted);446 }447 result.setSkipExe(skipExe);448 result.setSkipMessage(message);449 }450 if (result.getResult() == null) {451 result.setResult(status);452 }453 //If current loop encounters a continue OR current loop encountered a break.454 // We need to disable skipExe, else further testcases(After loop) will not be executed.455 if (result.getIsContinueLoop() || result.getIsBreakLoop()) {456 result.setSkipExe(false);//If skip is true, execution will not be continued after the loop.457 result.setResult(ResultConstant.SUCCESS);458 }459 resetThreadContextData();460 }461 protected void populateLoopConditionResult(TestCaseStepResult parentLoopResult, TestCaseStepResult childStepResult, TestCaseStepEntity parentLoopStep) {462 if (parentLoopStep.getConditionType() == ConditionType.LOOP_WHILE463 || parentLoopStep.getConditionType() == ConditionType.LOOP_FOR464 || parentLoopStep.getStepGroupId() != null) {465 if (childStepResult.getIsBreakLoop()) {466 parentLoopResult.setIsBreakLoop(childStepResult.getIsBreakLoop());467 } else if (childStepResult.getIsContinueLoop()) {468 parentLoopResult.setIsContinueLoop(childStepResult.getIsContinueLoop());469 }470 }471 }472 private void setFailedMessage(TestCaseStepResult result, TestCaseResult testCaseResult, Boolean ignoreStepResult) throws AutomatorException {473 result.setSkipExe(true);474 result.setSkipMessage(AutomatorMessages.MSG_STEP_MAJOR_STEP_FAILURE);475 if(!ignoreStepResult) {476 String majorMessage = AutomatorMessages.MSG_STEP_MAJOR_STEP_FAILURE +477 ((result.getMessage() != null) ? result.getMessage() : "") + " . " + AutomatorMessages.MSG_CHECK_FOR_MORE_DETAILS;478 testCaseResult.setMessage(majorMessage);479 testCaseResult.setResult(ResultConstant.FAILURE);480 }481 }482 private boolean isStepGroupFailure(TestCaseStepEntity testcaseStep, TestCaseStepEntity childStep,483 TestCaseStepResult childStepResult) {484 return childStep.getPriority() == TestStepPriority.MAJOR &&485 childStepResult.getResult() != null && !childStepResult.getResult().equals(ResultConstant.SUCCESS)486 && (testcaseStep.getConditionType() == null || !testcaseStep.getConditionType().equals(ConditionType.LOOP_FOR))487 && !childStep.getStepDetails().getIgnoreStepResult();488 }489 protected void setTestDataValue(TestCaseStepEntity step, Map<String, String> envDetails, TestCaseResult testCaseResult, TestCaseStepResult testCaseStepResult)490 throws AutomatorException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, IOException, InvocationTargetException {491 if (step.getTestDataMap() == null)492 return;493 int index =0;494 Map<String, TestDataPropertiesEntity> testDataPropertiesEntityMap = step.getTestDataMap();495 for (Map.Entry<String, TestDataPropertiesEntity> entry : testDataPropertiesEntityMap.entrySet()) {496 TestDataPropertiesEntity testDataPropertiesEntity = entry.getValue();497 TestDataType testDataType = TestDataType.getTestDataType(ObjectUtils.defaultIfNull(testDataPropertiesEntity.getTestDataType(), "raw"));498 switch (testDataType) {499 case runtime:500 if (!step.getAction().startsWith("Store ")) {501 RuntimeDataProvider runtimeDataProvider = new RuntimeDataProvider();502 testDataPropertiesEntity.setTestDataValue(503 runtimeDataProvider.getRuntimeData(testDataPropertiesEntity.getTestDataValue()));504 }505 break;506 case random:507 testDataPropertiesEntity.setTestDataValue(RandomStringUtils.randomAlphanumeric(508 Integer.parseInt(testDataPropertiesEntity.getTestDataValue())));509 break;510 case function:511 if (!testDataPropertiesEntity.getDefaultDataGeneratorsEntity().getIsAddonFn()) {512 DefaultDataGeneratorsEntity testDataFunctionEntity = testDataPropertiesEntity.getDefaultDataGeneratorsEntity();513 DefaultDataGeneratorsExecutor testDataFunctionExecutor = new DefaultDataGeneratorsExecutor();514 testDataFunctionExecutor.setTestCaseResult(testCaseResult);515 testDataFunctionExecutor.setSettings(envDetails);516 testDataFunctionExecutor.setDefaultDataGeneratorsEntity(testDataFunctionEntity);517 String testDataValue = testDataFunctionExecutor.generate();518 testDataPropertiesEntity.setTestDataName(testDataPropertiesEntity.getTestDataValue());519 testDataPropertiesEntity.setTestDataValue(testDataValue);520 } else {521 setTestDataValueFromAddonTestDataFunction(step, index, testDataPropertiesEntity, testCaseStepResult);522 index++;523 }524 break;525 }526 step.setTestDataName(testDataPropertiesEntity.getTestDataName());527 step.setTestDataValue(testDataPropertiesEntity.getTestDataValue());528 }529 }530 private void setTestDataValueFromAddonTestDataFunction(TestCaseStepEntity testCaseStepEntity, int index, TestDataPropertiesEntity testDataPropertiesEntity, TestCaseStepResult testCaseStepResult) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {531 try {532 List<AddonPluginTestDataFunctionEntity> addonPluginTDFEntityList = testCaseStepEntity.getAddonPluginTDFEntityList();533 AddonPluginTestDataFunctionEntity entity = addonPluginTDFEntityList.get(index);534 String jarFilePath = addonService.checkAndDownloadJar(entity.getClassPath(), entity.getModifiedHash());535 Class<?> clazz = addonService.loadJarClass(jarFilePath, entity.getFullyQualifiedName(), false);536 Object instance = clazz.getDeclaredConstructor().newInstance();537 setTestDataParameter(instance, addonService, testDataPropertiesEntity);538 Method executeMethod = clazz.getDeclaredMethod("generate");539 executeMethod.setAccessible(true);540 TestData testData = (TestData) executeMethod.invoke(instance);541 testDataPropertiesEntity.setTestDataName(entity.getDisplayName());542 testDataPropertiesEntity.setTestDataValue(testData.getValue().toString());543 } catch (Exception e) {544 String message = StringUtils.isBlank(e.getMessage()) ? e.getCause().getMessage() : e.getMessage();545 if (message == null) {546 testCaseStepResult.setMessage("Teststep execution failed. No Additional message was available.");547 } else {548 testCaseStepResult.setMessage(message);549 }550 throw e;551 }552 }553 public void setTestDataParameter(Object instance, AddonService addonService, TestDataPropertiesEntity testDataPropertiesEntity) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {554 Map<String, String> arguments = testDataPropertiesEntity.getDefaultDataGeneratorsEntity().getArguments();555 for (Map.Entry<String, String> entry : arguments.entrySet()) {556 String key = entry.getKey();557 String value = entry.getValue();558 Object testDataParameterInstance = addonService.getTestDataParameterInstance(value);559 FieldUtils.writeField(instance, key, testDataParameterInstance, true);560 log.info("Setting test data instance - " + testDataParameterInstance);561 }562 }563 private void takeScreenshot(WorkspaceType workspaceType, TestCaseStepEntity testcaseStep,564 TestCaseStepResult result, Screenshot option, ScreenCaptureUtil screenCaptureUtil) {565 TestDeviceSettings envSettings = EnvironmentRunner.getRunnerEnvironmentEntity().getEnvSettings();566 try {567 boolean takeScreenshot = false;568 String screenshotS3URL = testcaseStep.getScreenshotPath();569 if (option == Screenshot.NONE) {570 takeScreenshot = false;571 } else if (option == Screenshot.ALL_TYPES) {572 takeScreenshot = true;573 } else if ((option == Screenshot.FAILED_STEPS) && (result.getResult() != ResultConstant.SUCCESS)) {574 takeScreenshot = true;575 }576 int screenshotType = 0;577 if (testcaseStep.getAction() != null && testcaseStep.getAction().toLowerCase()578 .contains(AutomatorMessages.KEYWORD_SCREENSHOT.toLowerCase())) {579 screenshotType = 1;580 } else if (testcaseStep.getAction() != null && testcaseStep.getAction().toLowerCase()581 .contains(AutomatorMessages.KEYWORD_SCREENSHOT.toLowerCase())) {582 screenshotType = 2;583 }584 if (Arrays.asList(SKIP_SCREENSHOT_KEYWORDS).contains(testcaseStep.getAction())) {585 takeScreenshot = false;586 }587 if (!takeScreenshot && screenshotType == 0) {588 return;589 }590 String screenShotName = FilenameUtils.getName(new java.net.URL(screenshotS3URL).getPath());591 String localFolderPath = envSettings.getScreenshotLocalPath();592 testcaseStep.setScreenshot(option);593 result.setScreenshotName(screenShotName);594 WebDriver driver = DriverManager.getRemoteWebDriver();595 switch (workspaceType) {596 case WebApplication:597 case MobileWeb:598 if (screenshotType == 1) {599 screenCaptureUtil.screenShotWithURL(localFolderPath, screenshotS3URL, driver);600 } else if (screenshotType == 2) {601 screenCaptureUtil.fullPageScreenshotWithURL(localFolderPath, screenshotS3URL, driver);602 } else {603 screenCaptureUtil.takeScreenShot(driver, localFolderPath, screenshotS3URL);604 }605 break;606 case AndroidNative:607 case IOSNative:608 screenCaptureUtil.takeScreenShot(driver, localFolderPath, screenshotS3URL);609 break;610 default:611 break;612 }613 } catch (IOException e) {614 log.error(e.getMessage(), e);615 } catch (Exception e) {616 log.error(e.getMessage(), e);617 }618 }619 public void setConditionResult(TestCaseStepEntity testcaseStep, TestCaseStepResult result,620 HashMap<Long, TestCaseStepResult> parentStatus) {621 ResultConstant[] expectedStatus = testcaseStep.getIfConditionExpectedResults();622 if (testcaseStep.getConditionType() == ConditionType.CONDITION_IF) {623 boolean isSuccess = false;624 if (expectedStatus != null) {625 for (ResultConstant status : expectedStatus) {626 isSuccess = (status == result.getResult());627 if (isSuccess) {628 break;629 }630 }631 }632 result.setIsConditionSuccess(isSuccess);633 parentStatus.put(testcaseStep.getId(), result);634 if (result.getIsConditionSuccess()) {635 result.setResult(ResultConstant.SUCCESS);636 result.setMessage(AutomatorMessages.MSG_CONDITION_IF_SUCCESS);637 } else {638 result.setResult(ResultConstant.FAILURE);639 //result.setMessage(AutomatorMessges.MSG_CONDITION_IF_FAILED);640 }641 } else if (testcaseStep.getConditionType() == ConditionType.CONDITION_ELSE) {642 TestCaseStepResult parentResult = parentStatus.get(testcaseStep.getParentId());643 if (parentResult != null) {644 result.setIsConditionSuccess(!parentResult.getIsConditionSuccess());645 parentStatus.put(testcaseStep.getId(), result);646 }647 if (result.getIsConditionSuccess()) {648 result.setMessage(AutomatorMessages.MSG_CONDITION_ELSE_SUCCESS);649 result.setResult(ResultConstant.SUCCESS);650 } else {651 //result.setMessage(AutomatorMessges.MSG_CONDITION_ELSE_FAILED);652 result.setResult(ResultConstant.FAILURE);653 }654 } else if (testcaseStep.getConditionType() == ConditionType.CONDITION_ELSE_IF) {655 TestCaseStepResult parentResult = parentStatus.get(testcaseStep.getParentId());656 boolean isSuccess = false;657 if (parentResult != null) {658 if (!parentResult.getIsConditionSuccess()) {659 if (expectedStatus != null) {660 for (ResultConstant status : expectedStatus) {661 isSuccess = (status == result.getResult());662 if (isSuccess) {663 break;664 }665 }666 }667 }668 result.setIsConditionSuccess(isSuccess);669 parentStatus.put(testcaseStep.getId(), result);670 if (result.getIsConditionSuccess()) {671 result.setResult(ResultConstant.SUCCESS);672 result.setMessage(AutomatorMessages.MSG_CONDITION_ELSE_IF_SUCCESS);673 } else {674 result.setResult(ResultConstant.FAILURE);675 //result.setMessage(AutomatorMessges.MSG_CONDITION_ELSE_IF_FAILED);676 }677 }678 }679 }680 protected abstract void execute(Map<String, String> envSettings, TestCaseStepResult result,681 TestCaseStepEntity testcaseStep, TestCaseResult testCaseResult) throws AutomatorException;682 protected abstract void onStepFailure(ExecutionLabType exeType, WorkspaceType workspaceType, TestPlanRunSettingEntity settings) throws AutomatorException;683}...
Source:RestTestcaseStepRunner.java
...9 public RestTestcaseStepRunner(WorkspaceType workspaceType, Platform os) {10 super(workspaceType, os);11 }12 @Override13 protected void execute(Map<String, String> envSetting, TestCaseStepResult result, TestCaseStepEntity testcaseStep,14 TestCaseResult testCaseResult) throws AutomatorException {15 log.info("Executing REST step, step:" + testcaseStep);16 if (breakOrContinueLoopStep(testcaseStep, result)) {17 log.info("Its a break or continue step, not executing REST API call");18 return;19 }20 new WebserviceUtil().execute(testcaseStep, result, envSetting, testCaseResult);21 }22 private boolean breakOrContinueLoopStep(TestCaseStepEntity testcaseStep, TestCaseStepResult result) {23 log.info("Validating for Break or Continue step");24 TestStepType stepType = testcaseStep.getType();25 if (stepType != null && (stepType == TestStepType.BREAK_LOOP || stepType == TestStepType.CONTINUE_LOOP)) {26 result.setResult(ResultConstant.SUCCESS);27 return true;28 }29 return false;30 }31 @Override32 protected void onStepFailure(ExecutionLabType exeType, WorkspaceType workspaceType, TestPlanRunSettingEntity settings)33 throws AutomatorException {34 }...
execute
Using AI Code Generation
1import com.testsigma.automator.runners.TestcaseStepRunner;2public class 2 {3 public static void main(String[] args) {4 TestcaseStepRunner runner = new TestcaseStepRunner();5 runner.execute("2");6 }7}8import com.testsigma.automator.runners.TestcaseStepRunner;9public class 3 {10 public static void main(String[] args) {11 TestcaseStepRunner runner = new TestcaseStepRunner();12 runner.execute("3");13 }14}15import com.testsigma.automator.runners.TestcaseStepRunner;16public class 4 {17 public static void main(String[] args) {18 TestcaseStepRunner runner = new TestcaseStepRunner();19 runner.execute("4");20 }21}22import com.testsigma.automator.runners.TestcaseStepRunner;23public class 5 {24 public static void main(String[] args) {25 TestcaseStepRunner runner = new TestcaseStepRunner();26 runner.execute("5");27 }28}29import com.testsigma.automator.runners.TestcaseStepRunner;30public class 6 {31 public static void main(String[] args) {32 TestcaseStepRunner runner = new TestcaseStepRunner();33 runner.execute("6");34 }35}36import com.testsigma.automator.runners.TestcaseStepRunner;37public class 7 {38 public static void main(String[] args) {39 TestcaseStepRunner runner = new TestcaseStepRunner();40 runner.execute("7");41 }42}43import com.testsigma.automator.runners.TestcaseStepRunner;44public class 8 {45 public static void main(String[] args) {
execute
Using AI Code Generation
1import java.util.HashMap;2import java.util.Map;3import com.testsigma.automator.runners.TestcaseStepRunner;4import com.testsigma.automator.runners.TestcaseStepRunnerFactory;5public class Test {6 public static void main(String[] args) {7 TestcaseStepRunnerFactory factory = new TestcaseStepRunnerFactory();8 TestcaseStepRunner runner = factory.getTestcaseStepRunner("TestcaseStepRunner");9 Map<String, String> params = new HashMap<String, String>();10 params.put("step", "step1");11 params.put("element", "id=txt1");12 params.put("value", "Hello");13 runner.execute(params);14 }15}16import java.util.HashMap;17import java.util.Map;18import com.testsigma.automator.runners.TestcaseStepRunner;19import com.testsigma.automator.runners.TestcaseStepRunnerFactory;20public class Test {21 public static void main(String[] args) {22 TestcaseStepRunnerFactory factory = new TestcaseStepRunnerFactory();23 TestcaseStepRunner runner = factory.getTestcaseStepRunner("TestcaseStepRunner");24 Map<String, String> params = new HashMap<String, String>();25 params.put("step", "step1");26 params.put("element", "id=txt1");27 params.put("value", "Hello");28 runner.execute(params);29 }30}31import java.util.HashMap;32import java.util.Map;33import com.testsigma.automator.runners.TestcaseStepRunner;34import com.testsigma.automator.runners.TestcaseStepRunnerFactory;35public class Test {36 public static void main(String[] args) {37 TestcaseStepRunnerFactory factory = new TestcaseStepRunnerFactory();38 TestcaseStepRunner runner = factory.getTestcaseStepRunner("TestcaseStepRunner");39 Map<String, String> params = new HashMap<String, String>();40 params.put("step", "step1");41 params.put("element", "id=txt1");42 params.put("value", "Hello");43 runner.execute(params);44 }45}
execute
Using AI Code Generation
1import java.lang.reflect.Method;2import java.util.HashMap;3import com.testsigma.automator.runners.TestcaseStepRunner;4public class TestcaseStepRunnerTest {5 public static void main(String[] args) throws Exception {6 TestcaseStepRunner runner = new TestcaseStepRunner();7 HashMap<String, String> map = new HashMap<String, String>();8 map.put("stepName", "testStep");9 map.put("stepDescription", "Test Step Description");10 map.put("stepType", "testStepType");11 map.put("stepValue", "testStepValue");12 map.put("stepOptions", "testStepOptions");13 map.put("stepResult", "testStepResult");14 map.put("stepStatus", "testStepStatus");15 map.put("stepDuration", "testStepDuration");16 map.put("stepStartTime", "testStepStartTime");17 map.put("stepEndTime", "testStepEndTime");18 map.put("stepScreenshot", "testStepScreenshot");19 map.put("stepError", "testStepError");20 map.put("stepErrorDetails", "testStepErrorDetails");21 map.put("stepErrorScreenshot", "testStepErrorScreenshot");22 map.put("stepErrorScreenrecording", "testStepErrorScreenrecording");23 map.put("stepLog", "testStepLog");24 map.put("stepLogDetails", "testStepLogDetails");25 map.put("stepLogScreenshot", "testStepLogScreenshot");26 map.put("stepLogScreenrecording", "testStepLogScreenrecording");27 map.put("stepCustom", "testStepCustom");28 map.put("stepCustomDetails", "testStepCustomDetails");29 map.put("stepCustomScreenshot", "testStepCustomScreenshot");30 map.put("stepCustomScreenrecording", "testStepCustomScreenrecording");31 map.put("stepData", "testStepData");32 map.put("stepDataDetails", "testStepDataDetails");33 map.put("stepDataScreenshot", "testStepDataScreenshot");34 map.put("stepDataScreenrecording", "testStepDataScreenrecording");35 map.put("stepExpected", "testStepExpected");36 map.put("stepExpectedDetails", "testStepExpectedDetails");37 map.put("stepExpectedScreenshot", "testStepExpectedScreenshot");38 map.put("stepExpectedScreenrecording", "testStepExpectedScreenrec
execute
Using AI Code Generation
1package com.testsigma.automator.runners;2import java.lang.reflect.Method;3import org.json.JSONObject;4import com.testsigma.automator.common.AutomatorConfig;5import com.testsigma.automator.common.AutomatorConfig.AutomatorConfigBuilder;6import com.testsigma.automator.common.AutomationConstants;7import com.testsigma.automator.common.AutomationConstants.AutomatorExecutionType;8import com.testsigma.automator.common.AutomationConstants.AutomatorType;9import com.testsigma.automator.common.AutomationConstants.ExecutionMode;10import com.testsigma.automator.common.AutomationConstants.ExecutionType;11import com.testsigma.automator.common.AutomationConstants.FrameworkType;12import com.testsigma.automator.common.AutomationConstants.Platform;13import com.testsigma.automator.common.AutomationConstants.PlatformType;14import com.testsigma.automator.common.AutomationConstants.RunType;15import com.testsigma.automator.common.AutomationConstants.TestType;16import com.testsigma.automator.common.AutomationConstants.TestcaseType;17import com.testsigma.automator.common.AutomationConstants.UserType;18import com.testsigma.automator.common.AutomationUtils;19import com.testsigma.automator.common.Logger;20import com.testsigma.automator.common.TestcaseStep;21import com.testsigma.automator.common.TestcaseStepResult;22import com.testsigma.automator.common.TestcaseStepResult.ResultStatus;23import com.testsigma.automator.common.TestcaseStepResult.ResultType;24import com.testsigma.automator.common.TestsigmaException;25import com.testsigma.automator.common.TestsigmaException.ExceptionType;26import com.testsigma.automator.common.TestsigmaException.FrameworkException;27import com.testsigma.automator.common.TestsigmaException.TestcaseStepException;28import com.testsigma.automator.common.TestsigmaException.TestcaseStepResultException;29import com.testsigma.automator.common.TestsigmaException.TestcaseStepRunnerException;30import com.testsigma.automator.common.TestsigmaException.TestcaseStepRunnerException.ExceptionCode;31import com.testsigma.automator.common.TestsigmaException.TestsigmaException;32import com.testsigma.automator.common.TestsigmaException.TestsigmaException.ExceptionCode;33import com.testsigma.automator.common.TestsigmaException.TestsigmaException.ExceptionType;34import com.testsigma.automator.common.TestsigmaException.TestsigmaException.FrameworkException;35import com.testsigma.automator.common.TestsigmaException.TestsigmaException.TestcaseStepException;36import com.testsigma.automator.common.TestsigmaException.TestsigmaException.TestcaseStepResult
execute
Using AI Code Generation
1package com.testsigma.automator.runners;2import com.testsigma.automator.util.TestcaseStepRunner;3public class TestcaseStepRunnerExample {4public static void main(String args[]) throws Exception {5TestcaseStepRunner runner = new TestcaseStepRunner();6runner.execute("C:\\Users\\testsigma\\Desktop\\TestcaseStep", "C:\\Users\\testsigma\\Desktop\\TestcaseStep\\TestcaseStepResult");7}8}9package com.testsigma.automator.runners;10import com.testsigma.automator.util.TestcaseRunner;11public class TestcaseRunnerExample {12public static void main(String args[]) throws Exception {13TestcaseRunner runner = new TestcaseRunner();14runner.execute("C:\\Users\\testsigma\\Desktop\\Testcase", "C:\\Users\\testsigma\\Desktop\\Testcase\\TestcaseResult");15}16}17package com.testsigma.automator.runners;18import com.testsigma.automator.util.TestSuiteRunner;19public class TestSuiteRunnerExample {20public static void main(String args[]) throws Exception {21TestSuiteRunner runner = new TestSuiteRunner();22runner.execute("C:\\Users\\testsigma\\Desktop\\TestSuite", "C:\\Users\\testsigma\\Desktop\\TestSuite\\TestSuiteResult");23}24}25package com.testsigma.automator.runners;26import com.testsigma.automator.util.TestPlanRunner;27public class TestPlanRunnerExample {28public static void main(String args[]) throws Exception {29TestPlanRunner runner = new TestPlanRunner();30runner.execute("C:\\Users\\testsigma\\Desktop\\TestPlan", "C:\\Users\\testsigma\\Desktop\\TestPlan\\TestPlanResult");31}32}33package com.testsigma.automator.runners;34import com.testsigma.automator.util.TestSuiteRunner;
execute
Using AI Code Generation
1package com.testsigma.automator.examples;2import java.util.HashMap;3import com.testsigma.automator.runners.TestcaseStepRunner;4import com.testsigma.automator.runners.TestcaseStepResult;5public class TestcaseStepRunnerExample {6 public static void main(String[] args) {7 TestcaseStepRunner runner = new TestcaseStepRunner();8 HashMap<String, String> params = new HashMap<String, String>();9 params.put("step", "click");10 params.put("timeout", "30");11 TestcaseStepResult result = runner.execute("com.testsigma.automator.steps.ClickStep", params);12 System.out.println("isPassed = " + result.isPassed);13 System.out.println("output = " + result.output);14 System.out.println("errorMessage = " + result.errorMessage);15 System.out.println("exception = " + result.exception);16 System.out.println("stackTrace = " + result.stackTrace);17 System.out.println("errorScreenshot = " + result.errorScreenshot);18 }19}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!