How to use create method of com.testsigma.service.TestCaseDataDrivenResultService class

Best Testsigma code snippet using com.testsigma.service.TestCaseDataDrivenResultService.create

Source:AgentExecutionService.java Github

copy

Full Screen

...147 }148 }149 // ############################################ RESULT ENTRIES CREATION #############################################150 private void populateResultEntries(boolean setLastRunId) throws TestsigmaException {151 TestPlanResult testPlanResult = createTestPlanResult();152 populateLastRunId(testPlanResult, setLastRunId);153 this.setTestPlanResult(testPlanResult);154 populateEnvironmentResults(testPlanResult);155 }156 private void populateLastRunId(TestPlanResult testPlanResult, boolean setLastRunId) {157 AbstractTestPlan testPlan = this.getTestPlan();158 if (setLastRunId) {159 testPlan.setLastRunId(testPlanResult.getId());160 }161 if (testPlan instanceof TestPlan)162 this.setTestPlan(testPlanService.update((TestPlan) testPlan));163 }164 private void populateEnvironmentResults(TestPlanResult testPlanResult) throws TestsigmaException {165 List<TestDevice> testDevices =166 testDeviceService.findByTestPlanIdAndDisable(this.getTestPlan().getId(), Boolean.FALSE);167 for (TestDevice testDevice : testDevices) {168 log.info("Populating Environment result for environment:" + testDevice);169 TestDeviceResult testDeviceResult = createEnvironmentResult(testPlanResult, testDevice);170 if (testDeviceResult != null) {171 populateTestSuiteResults(testDeviceResult, testDevice);172 }173 }174 populatePreRequisiteEnvironmentResultIds(testPlanResult);175 }176 private void populateTestSuiteResults(TestDeviceResult testDeviceResult, TestDevice testDevice)177 throws TestsigmaException {178 List<AbstractTestSuite> testSuites = this.testSuiteService.findAllByTestDeviceId(testDeviceResult.getTestDeviceId());179 for (AbstractTestSuite testSuite : testSuites) {180 log.info("Populate TestSuite result for suite:" + testSuite.getName());181 TestSuiteResult testSuiteResult = createTestSuiteResult(testSuite, testDeviceResult, testDevice);182 if (testSuiteResult != null) {183 testSuite.setLastRunId(testSuiteResult.getId());184 if (testPlan instanceof TestPlan)185 this.testSuiteService.updateSuite((TestSuite) testSuite);186 populateTestCaseResults(testSuite, testSuiteResult, testDeviceResult);187 }188 }189 }190 private void populateTestCaseResults(AbstractTestSuite testSuite, TestSuiteResult testSuiteResult,191 TestDeviceResult testDeviceResult) throws TestsigmaException {192 List<TestCase> testCases = this.testCaseService.findAllBySuiteId(testSuiteResult.getSuiteId());193 int testDataStartIndex;194 for (TestCase testCase : testCases) {195 testDataStartIndex = testCase.getTestDataStartIndex();196 TestCaseResult testCaseResult = createTestCaseResult(testSuite, testCase, testDeviceResult, testSuiteResult,197 null);198 if (testCaseResult != null && testPlan instanceof TestPlan) {199 testCase.setLastRunId(testCaseResult.getId());200 testCase.setTestDataStartIndex(testDataStartIndex);201 testCaseService.update(testCase);202 }203 }204 }205 protected void populateStepGroupTestStepResults(TestStep testStep, TestCaseResult testCaseResult,206 TestDeviceResult testDeviceResult,207 TestStepResult parentTestStepResult) {208 List<TestStep> testSteps = this.testStepService.findAllByTestCaseId(testStep.getStepGroupId());209 for (TestStep step : testSteps) {210 createTestStepResult(step, testDeviceResult, testCaseResult, parentTestStepResult);211 }212 }213 protected void createTestStepResult(TestStep testStep,214 TestDeviceResult testDeviceResult,215 TestCaseResult testCaseResult,216 TestStepResult parentTestStepResult) {217 log.info("Creating TestStepResult for:" + testStep);218 TestStepResult testStepResult = new TestStepResult();219 testStepResult.setEnvRunId(testDeviceResult.getId());220 testStepResult.setResult(ResultConstant.QUEUED);221 testStepResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);222 testStepResult.setStepId(testStep.getId());223 testStepResult.setTestCaseId(testCaseResult.getTestCaseId());224 testStepResult.setStepGroupId(testStep.getStepGroupId());225 testStepResult.setGroupResultId((parentTestStepResult != null) ? parentTestStepResult.getId() : null);226 testStepResult.setTestCaseResultId(testCaseResult.getId());227 testStepResult.setPriority(testStep.getPriority());228 StepDetails stepDetails = new StepDetails();229 stepDetails.setNaturalTextActionId(testStep.getNaturalTextActionId());230 stepDetails.setAction(testStep.getAction());231 stepDetails.setPriority(testStep.getPriority());232 stepDetails.setPreRequisiteStepId(testStep.getPreRequisiteStepId());233 stepDetails.setConditionType(testStep.getConditionType());234 stepDetails.setParentId(testStep.getParentId());235 stepDetails.setType(testStep.getType());236 stepDetails.setStepGroupId(testStep.getStepGroupId());237 stepDetails.setAction(testStep.getAction());238 stepDetails.setPosition(testStep.getPosition());239 stepDetails.setTestDataName(testCaseResult.getTestDataSetName());240 stepDetails.setDataMap(testStep.getDataMapBean());241 testStepResult.setStepDetails(stepDetails);242 if (parentTestStepResult != null) {243 testStepResult.setParentResultId(parentTestStepResult.getId());244 }245 testStepResult = this.testStepResultService.create(testStepResult);246 if (TestStepType.STEP_GROUP.equals(testStep.getType())) {247 populateStepGroupTestStepResults(testStep, testCaseResult, testDeviceResult, testStepResult);248 }249 }250 private void populateDataDrivenTestCaseResults(AbstractTestSuite testSuite,251 TestCase testCase,252 TestDeviceResult testDeviceResult,253 TestSuiteResult testSuiteResult,254 TestCaseResult parentTestCaseResult) throws TestsigmaException {255 log.info("Creating Data driven TestcaseResult for testcase:" + testCase.getName());256 TestPlanResult testPlanResult = testPlanResultService.find(testDeviceResult.getTestPlanResultId());257 isDataDrivenRerun = testDeviceResult.getReRunParentId() != null;258 TestData testData = testCase.getTestData();259 List<TestDataSet> testDataSets = testData.getData();260 if(isDataDrivenRerun && !parentTestCaseResult.getIsStepGroup()){261 log.info("Creating data driven re run iteration results for test case - " + parentTestCaseResult.getId());262 this.createTestCaseDataDrivenReRunResult(testPlanResult, testDataSets, testCase, testSuite, testDeviceResult,263 testSuiteResult, parentTestCaseResult);264 } else {265 int start = testCase.getTestDataStart();266 int end = testCase.getTestDataEnd(testDataSets.size());267 for (int i = start; i <= end && i < testDataSets.size(); i++) {268 TestDataSet testDataSet = testDataSets.get(i);269 this.createTestCaseIterationResult(testDataSets, testDataSet, testCase, testSuite, testDeviceResult,270 testSuiteResult, parentTestCaseResult);271 }272 testCase.setTestDataStartIndex(start);273 }274 testCase.setIsDataDriven(true);275 }276 private TestCaseDataDrivenResult createTestCaseDataDrivenResult(TestDataSet testDataSet, TestCaseResult testCaseResult) {277 TestCaseDataDrivenResult testCaseDataDrivenResult = new TestCaseDataDrivenResult();278 testCaseDataDrivenResult.setEnvRunId(testCaseResult.getEnvironmentResultId());279 testCaseDataDrivenResult.setTestData(new ObjectMapperService().convertToJson(testDataSet));280 testCaseDataDrivenResult.setTestDataName(testDataSet.getName());281 testCaseDataDrivenResult.setTestCaseId(testCaseResult.getTestCaseId());282 testCaseDataDrivenResult.setTestCaseResultId(testCaseResult.getParentId());283 testCaseDataDrivenResult.setIterationResultId(testCaseResult.getId());284 return testCaseDataDrivenResultService.create(testCaseDataDrivenResult);285 }286 private TestCaseResult createTestCaseResult(AbstractTestSuite testSuite,287 TestCase testCase,288 TestDeviceResult testDeviceResult,289 TestSuiteResult testSuiteResult,290 TestCaseResult parentTestCaseResult) throws TestsigmaException {291 log.info("Creating TestcaseResult for:" + testCase);292 checkForDataDrivenIntegrity(testCase);293 TestCaseResult testCaseResult = new TestCaseResult();294 testCaseResult = setReRunParentId(testSuiteResult, testCase, testCaseResult, parentTestCaseResult);295 if (testCaseResult == null)296 return null;297 testCaseResult.setEnvironmentResultId(testDeviceResult.getId());298 testCaseResult.setTestPlanResultId(testDeviceResult.getTestPlanResultId());299 testCaseResult.setTestCaseId(testCase.getId());300 testCaseResult.setSuiteId(testSuiteResult.getSuiteId());301 testCaseResult.setSuiteResultId(testSuiteResult.getId());302 testCaseResult.setResult(ResultConstant.QUEUED);303 testCaseResult.setStatus(StatusConstant.STATUS_CREATED);304 testCaseResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);305 testCaseResult.setIsStepGroup(testCase.getIsStepGroup());306 if (parentTestCaseResult != null) {307 testCaseResult.setParentId(parentTestCaseResult.getId());308 }309 if (!testCase.getIsDataDriven()) {310 TestData testData = testCase.getTestData();311 if (testData != null) {312 TestDataSet testDataSet = testData.getData().get(testCase.getTestDataStartIndex());313 testCaseResult.setTestDataSetName(testDataSet.getName());314 if (parentTestCaseResult != null) {315 testCaseResult.setIteration(testDataSet.getName());316 }317 }318 }319 Optional<SuiteTestCaseMapping> suiteTestCaseMapping =320 suiteTestCaseMappingService.findFirstByTestSuiteAndTestCase(testSuite, testCase);321 TestCaseResult finalTestCaseResult = testCaseResult;322 suiteTestCaseMapping323 .ifPresent(suiteMapping -> finalTestCaseResult.setPosition(suiteMapping.getPosition().longValue()));324 if (suiteTestCaseMapping.isPresent()) {325 testCaseResult.setPosition(suiteTestCaseMapping.get().getPosition().longValue());326 }327 testCaseResult.setTestCaseTypeId(testCase.getType());328 testCaseResult.setTestCaseStatus(testCase.getStatus());329 testCaseResult.setPriorityId(testCase.getPriority());330 testCaseResult.setIsDataDriven(testCase.getIsDataDriven());331 testCaseResult.setTestDataId(testCase.getTestDataId());332 testCaseResult.setTestCaseDetails(testCaseDetails(testCaseResult, testCase));333 testCaseResult = this.testCaseResultService.create(testCaseResult);334 if (testCase.getIsDataDriven()) {335 populateDataDrivenTestCaseResults(testSuite, testCase, testDeviceResult, testSuiteResult, testCaseResult);336 }337 return testCaseResult;338 }339 private TestCaseResult setReRunParentId(TestSuiteResult testSuiteResult, TestCase testCase, TestCaseResult testCaseResult, TestCaseResult parentTestCaseResult) {340 if (getIsReRun() && (testSuiteResult.getReRunParentId() != null)) {341 TestCaseResult reRunParentTestCaseResult = testCaseResultsReRunList.stream().filter(342 er -> er.getTestCaseId().equals(testCase.getId()) && er.getIteration() == null).findAny().orElse(null);343 if(getReRunType() == ReRunType.ALL_TESTS)344 reRunParentTestCaseResult = testCaseResultService.getLastReRunResult(reRunParentTestCaseResult);345 if (reRunParentTestCaseResult != null) {346 testCaseResult.setReRunParentId(reRunParentTestCaseResult.getId());347 } else {348 log.info("Test Case (" + testCase.getId() + ") is not eligible for Re-run. Skipping...");349 return null;350 }351 }352 if (!testCase.getIsDataDriven() && testCase.getTestData() != null && parentTestCaseResult != null) {353 TestData testData = testCase.getTestData();354 TestDataSet testDataSet = testData.getData().get(testCase.getTestDataStartIndex());355 if (getIsReRun() && (testSuiteResult.getReRunParentId() != null)) {356 TestCaseResult reRunParentTestCaseResult = testCaseResultsReRunList.stream().filter(357 er -> er.getTestCaseId().equals(testCase.getId()) && er.getIteration() != null && er.getIteration().equals(testDataSet.getName())).findAny().orElse(null);358 if (reRunParentTestCaseResult != null) {359 testCaseResult.setReRunParentId(reRunParentTestCaseResult.getId());360 } else {361 log.info("Test Case (" + testCase.getId() + ") is not eligible for Re-run. Skipping...");362 return null;363 }364 }365 }366 return testCaseResult;367 }368 private TestCaseDetails testCaseDetails(TestCaseResult testCaseResult, TestCase testCase) {369 TestCaseDetails testCaseDetails = new TestCaseDetails();370 testCaseDetails.setName(testCase.getName());371 testCaseDetails.setTestData(testCaseResult.getIteration());372 testCaseDetails.setTestDataSetName(testCaseResult.getTestDataSetName());373 testCaseDetails.setPrerequisite(testCase.getPreRequisite());374 return testCaseDetails;375 }376 private TestSuiteResult createTestSuiteResult(AbstractTestSuite testSuite, TestDeviceResult testDeviceResult,377 TestDevice testDevice) {378 TestSuiteResult testSuiteResult = new TestSuiteResult();379 if (getIsReRun() && (testDeviceResult.getReRunParentId() != null)) {380 TestSuiteResult parentTestSuiteResult = testSuiteResultsReRunList.stream().filter(381 er -> er.getSuiteId().equals(testSuite.getId())).findAny().orElse(null);382 if (parentTestSuiteResult != null) {383 testSuiteResult.setReRunParentId(parentTestSuiteResult.getId());384 fetchTestCaseResultsReRunList(parentTestSuiteResult.getId());385 } else {386 log.info("Test Suite (" + testSuite.getId() + ") is not eligible for Re-run. Skipping...");387 return null;388 }389 }390 testSuiteResult.setEnvironmentResultId(testDeviceResult.getId());391 testSuiteResult.setResult(ResultConstant.QUEUED);392 testSuiteResult.setStatus(StatusConstant.STATUS_CREATED);393 testSuiteResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);394 testSuiteResult.setSuiteId(testSuite.getId());395 testSuiteResult.setStartTime(new Timestamp(System.currentTimeMillis()));396 testSuiteResult.setTestPlanResultId(testDeviceResult.getTestPlanResultId());397 Optional<TestDeviceSuite> environmentSuiteMapping =398 testDeviceSuiteService.findFirstByTestDeviceAndTestSuite(testDevice, testSuite);399 environmentSuiteMapping400 .ifPresent(suiteMapping -> testSuiteResult.setPosition(suiteMapping.getPosition().longValue()));401 TestSuiteResultSuiteDetails suiteDetails = new TestSuiteResultSuiteDetails();402 suiteDetails.setName(testSuite.getName());403 suiteDetails.setPreRequisite(testSuite.getPreRequisite());404 testSuiteResult.setSuiteDetails(suiteDetails);405 return this.testSuiteResultService.create(testSuiteResult);406 }407 private TestDeviceResult createEnvironmentResult(TestPlanResult testPlanResult,408 TestDevice testDevice) throws TestsigmaException {409 TestDeviceResult testDeviceResult = new TestDeviceResult();410 TestPlanResult parentExecutionResult = testPlanResultService.getFirstParentResult(testPlanResult);411 if (getIsReRun() && (parentExecutionResult.getId() != null)) {412 TestDeviceResult parentTestDeviceResult = testDeviceResultsReRunList.stream().filter(413 er -> er.getTestDeviceId().equals(testDevice.getId())).findAny().orElse(null);414 if (parentTestDeviceResult != null) {415 TestDeviceResult childTestDevResult = testDeviceResultService.getLastReRunResult(parentTestDeviceResult);416 testDeviceResult.setReRunParentId(childTestDevResult.getId());417 fetchTestSuitesResultsReRunList(parentTestDeviceResult.getId());418 } else {419 log.info("Execution Environment (" + testDevice.getId() + ") is not eligible for Re-run. Skipping...");420 return null;421 }422 }423 testDeviceResult.setTestPlanResultId(testPlanResult.getId());424 testDeviceResult.setResult(ResultConstant.QUEUED);425 testDeviceResult.setStatus(StatusConstant.STATUS_CREATED);426 testDeviceResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);427 testDeviceResult.setStartTime(new Timestamp(System.currentTimeMillis()));428 testDeviceResult.setTestDeviceId(testDevice.getId());429 testDeviceResult.setAppUploadVersionId(getUploadVersionId(testDevice));430 testDeviceResult.setTestDeviceSettings(getExecutionTestDeviceSettings(testDevice));431 testDeviceResult.setTestPlanLabType(testDevice.getTestPlanLabType());432 testDeviceResult.setWorkspaceVersionId(testDevice.getWorkspaceVersionId());433 testDeviceResult = testDeviceResultService.create(testDeviceResult);434 testDeviceResult.setTestDevice(testDevice);435 return testDeviceResult;436 }437 private Long getUploadVersionId(TestDevice testDevice) throws ResourceNotFoundException {438 Long uploadVersionId = getUploadVersionIdFromRuntime(testDevice.getId());439 if (uploadVersionId != null) {440 log.debug("Got uploadVersionId from runTimeData ", uploadVersionId, testDevice.getId());441 uploadVersionId = this.uploadVersionService.find(uploadVersionId).getId();442 } else {443 uploadVersionId = testDevice.getAppUploadVersionId();444 if (uploadVersionId == null && testDevice.getAppUploadId() != null)445 uploadVersionId = uploadService.find(testDevice.getAppUploadId()).getLatestVersionId();446 }447 return uploadVersionId;448 }449 private Long getUploadVersionIdFromRuntime(Long environmentId) {450 log.debug("Fetching uploadVersionId from runTimeData for EnvironmentId::"+environmentId);451 if (getRunTimeData() != null) {452 JSONObject uploadVersions = getRunTimeData().optJSONObject("uploadVersions");453 log.debug("Fetching uploadVersionId from runTimeData for uploadVersions::", uploadVersions);454 if (uploadVersions != null) {455 log.debug("Fetching uploadVersionId from runTimeData for uploadVersions::", uploadVersions);456 return uploadVersions.optLong(environmentId+"");457 }458 }459 return null;460 }461 private TestPlanResult createTestPlanResult() throws ResourceNotFoundException {462 TestPlanResult testPlanResult = new TestPlanResult();463 if (getIsReRun()) {464 if (this.getParentTestPlanResultId() != null) {465 testPlanResult.setReRunParentId(this.getParentTestPlanResultId());466 } else {467 testPlanResult.setReRunParentId(testPlan.getLastRunId());468 }469 testPlanResult.setReRunType(getReRunType());470 fetchEnvironmentResultsReRunList();471 }472 if ((this.getRunTimeData() != null) && (this.getRunTimeData().has("build_number"))) {473 testPlanResult.setBuildNo(this.getRunTimeData().getString("build_number"));474 }475 testPlanResult.setResult(ResultConstant.QUEUED);476 testPlanResult.setStatus(StatusConstant.STATUS_CREATED);477 testPlanResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);478 testPlanResult.setTestPlanId(this.getTestPlan().getId());479 testPlanResult.setStartTime(new Timestamp(System.currentTimeMillis()));480 testPlanResult.setTriggeredType(this.triggeredType);481 testPlanResult.setScheduleId(this.scheduleId);482 TestPlanDetails testPlanDetails = new TestPlanDetails();483 testPlanDetails.setElementTimeout(testPlan.getElementTimeOut());484 testPlanDetails.setPageTimeout(testPlan.getPageTimeOut());485 testPlanDetails.setOnAbortedAction(testPlan.getOnAbortedAction());486 testPlanDetails.setRecoveryAction(testPlan.getRecoveryAction());487 testPlanDetails.setGroupPrerequisiteFail(testPlan.getOnSuitePreRequisiteFail());488 testPlanDetails.setTestCasePrerequisiteFail(testPlan.getOnTestcasePreRequisiteFail());489 testPlanDetails.setTestStepPrerequisiteFail(testPlan.getOnStepPreRequisiteFail());490 testPlanDetails.setScreenshotOption(testPlan.getScreenshot());491 if (this.getTestPlan().getEnvironmentId() != null) {492 Environment environment = environmentService.find(this.getTestPlan().getEnvironmentId());493 testPlanResult.setEnvironmentId(environment.getId());494 testPlanDetails.setEnvironmentParamName(environment.getName());495 }496 testPlanResult.setTestPlanDetails(testPlanDetails);497 return testPlanResultService.create(testPlanResult);498 }499 private void checkForDataDrivenIntegrity(TestCase testCase) throws TestsigmaException {500 TestData testData = testCase.getTestData();501 if (testData == null && testCase.getIsDataDriven()) {502 String errorMessage = com.testsigma.constants.MessageConstants.getMessage(503 MessageConstants.MSG_UNKNOWN_TEST_DATA_DATA_DRIVEN_CASE,504 testCase.getName()505 );506 throw new TestsigmaException(errorMessage);507 }508 }509 private TestDeviceSettings getExecutionTestDeviceSettings(TestDevice testDevice) throws TestsigmaException {510 TestDeviceSettings settings = new TestDeviceSettings();511 TestPlanLabType exeLabType = testDevice.getTestPlanLabType();512 if (!(testDevice.getTestPlanLabType().isHybrid() && testDevice.getWorkspaceVersion().getWorkspace().getWorkspaceType().isMobile()) && testDevice.getPlatformDeviceId() != null) {513 settings.setDeviceName(platformsService.getPlatformDevice(testDevice.getPlatformDeviceId(), exeLabType).getName());514 }515 if (testDevice.getPlatformBrowserVersionId() != null) {516 PlatformBrowserVersion platformBrowserVersion = platformsService.getPlatformBrowserVersion(testDevice.getPlatformBrowserVersionId(), exeLabType);517 settings.setBrowserVersion(platformBrowserVersion.getVersion());518 settings.setBrowser(platformBrowserVersion.getName().name());519 }520 if (testDevice.getPlatformScreenResolutionId() != null) {521 settings.setResolution(platformsService.getPlatformScreenResolution(testDevice.getPlatformScreenResolutionId(), exeLabType).getResolution());522 }523 if (testDevice.getPlatformOsVersionId() != null) {524 PlatformOsVersion platformOsVersion = platformsService.getPlatformOsVersion(testDevice.getPlatformOsVersionId(), exeLabType);525 settings.setPlatform(platformOsVersion.getPlatform());526 settings.setOsVersion(platformOsVersion.getPlatformVersion());527 }528 if (exeLabType == TestPlanLabType.Hybrid || exeLabType == TestPlanLabType.PrivateGrid) {529 settings.setBrowser(testDevice.getBrowser());530 }531 settings.setAppActivity(testDevice.getAppActivity());532 settings.setAppPackage(testDevice.getAppPackage());533 settings.setAppPathType(testDevice.getAppPathType());534 settings.setAppUrl(testDevice.getAppUrl());535 settings.setAppUploadId(testDevice.getAppUploadId());536 settings.setTitle(testDevice.getTitle());537 settings.setCreateSessionAtCaseLevel(testDevice.getCreateSessionAtCaseLevel());538 return settings;539 }540 private Boolean isScheduledExecution() {541 return this.triggeredType.equals(ExecutionTriggeredType.SCHEDULED);542 }543 // ############################################ RESULT ENTRIES PROCESSING ###########################################544 private void processResultEntries() throws Exception {545 List<TestDeviceResult> testDeviceResults = testDeviceResultService.findAllByTestPlanResultId(546 this.testPlanResult.getId());547 for(TestDeviceResult testDeviceResult : testDeviceResults) {548 if (canPushToLabAgent(testDeviceResult)) {549 processResultEntriesForLabAgent(testDeviceResult);550 } else if (canPushToHybridAgent(testDeviceResult)) {551 processResultEntriesForHybridAgent(testDeviceResult);552 }553 }554 }555 private Boolean canPushToLabAgent(TestDeviceResult testDeviceResult) throws IntegrationNotFoundException {556 return !testDeviceResult.getTestPlanLabType().equals(TestPlanLabType.Hybrid) && this.integrationsService.findByApplication(Integration.TestsigmaLab) != null;557 }558 private Boolean canPushToHybridAgent(TestDeviceResult testDeviceResult) {559 return testDeviceResult.getTestPlanLabType().equals(TestPlanLabType.Hybrid);560 }561 private void processResultEntriesForLabAgent(TestDeviceResult testDeviceResult) throws Exception {562 processResultEntries(testDeviceResult, StatusConstant.STATUS_CREATED);563 }564 private void processResultEntriesForHybridAgent(TestDeviceResult testDeviceResult) throws Exception {565 processResultEntries(testDeviceResult, StatusConstant.STATUS_CREATED);566 }567 public void processResultEntries(TestDeviceResult testDeviceResult, StatusConstant inStatus)568 throws Exception {569 if (testDeviceResult.getTestDevice().getAgent() == null && testDeviceResult.getTestPlanLabType().isHybrid()) {570 testDeviceResultService.markEnvironmentResultAsFailed(testDeviceResult, AutomatorMessages.AGENT_HAS_BEEN_REMOVED, StatusConstant.STATUS_CREATED);571 } else if (testDeviceResult.getTestPlanLabType().isHybrid() && !agentService.isAgentActive(testDeviceResult.getTestDevice().getAgentId())) {572 testDeviceResultService.markEnvironmentResultAsFailed(testDeviceResult, AutomatorMessages.AGENT_INACTIVE, StatusConstant.STATUS_CREATED);573 } else if(testDeviceResult.getTestPlanLabType().isHybrid() && testDeviceResult.getTestDevice().getDeviceId()!=null && agentService.isAgentActive(testDeviceResult.getTestDevice().getAgentId()) && !agentDeviceService.isDeviceOnline(testDeviceResult.getTestDevice().getDeviceId())){574 testDeviceResultService.markEnvironmentResultAsFailed(testDeviceResult, agentDeviceService.find(testDeviceResult.getTestDevice().getDeviceId()).getName()+ " "+AutomatorMessages.DEVICE_NOT_ONLINE, StatusConstant.STATUS_CREATED);575 } else {576 processEnvironmentResultOnSuccessfulChecks(testDeviceResult, inStatus);577 }578 testDeviceResultService.updateExecutionConsolidatedResults(this.testPlanResult.getId(),579 Boolean.TRUE);580 }581 public void processEnvironmentResultOnSuccessfulChecks(TestDeviceResult testDeviceResult, StatusConstant inStatus) throws Exception {582 if (!isWaitingOnEnvironmentPrerequisite(testDeviceResult)) {583 if (testDeviceResult.getPrerequisiteTestDeviceResultId() == null || isEnvironmentPrerequisiteResultSuccessful(testDeviceResult)) {584 processEnvironmentResult(testDeviceResult, inStatus);585 } else {586 testDeviceResultService.markEnvironmentResultAsFailed(testDeviceResult, AutomatorMessages.MSG_EXECUTION_NOT_EXECUTED, StatusConstant.STATUS_QUEUED);587 }588 } else {589 testDeviceResultService.markEnvironmentResultAsQueued(testDeviceResult, inStatus, true);590 }591 }592 private void processEnvironmentResult(TestDeviceResult testDeviceResult, StatusConstant inStatus) throws Exception {593 testDeviceResultService.markEnvironmentResultAsInPreFlight(testDeviceResult, inStatus);594 if (!testDeviceResult.getTestPlanLabType().isHybrid()) {595 EnvironmentEntityDTO environmentEntityDTO = loadEnvironment(testDeviceResult,596 StatusConstant.STATUS_PRE_FLIGHT);597 try {598 pushEnvironmentToLab(testDeviceResult, environmentEntityDTO);599 } catch (Exception e) {600 log.error(e.getMessage(), e);601 testDeviceResultService.markEnvironmentResultAsFailed(testDeviceResult, e.getMessage(),602 StatusConstant.STATUS_PRE_FLIGHT);603 }604 }605 }606 public void processEnvironmentResultInParallel(TestDeviceResult testDeviceResult, StatusConstant inStatus) throws Exception {607 List<TestSuiteResult> testSuiteResults = this.testSuiteResultService.findPendingTestSuiteResults(608 testDeviceResult, inStatus);609 testDeviceResult.setSuiteResults(testSuiteResults);610 for (TestSuiteResult testSuiteResult : testSuiteResults) {611 if(!isWaitingOnEnvironmentPrerequisite(testDeviceResult)) {612 testSuiteResultService.markTestSuiteResultAsInFlight(testSuiteResult, inStatus);613 if (!testDeviceResult.getTestPlanLabType().isHybrid()) {614 TestSuiteEntityDTO testSuiteEntity = this.testSuiteResultMapper.map(testSuiteResult);615 testSuiteEntity.setTestCases(loadTestCases(testSuiteResult, StatusConstant.STATUS_PRE_FLIGHT));616 List<TestSuiteEntityDTO> testSuiteEntityDTOS = new ArrayList<>();617 testSuiteEntityDTOS.add(testSuiteEntity);618 EnvironmentEntityDTO environmentEntityDTO = loadEnvironmentDetails(testDeviceResult);619 environmentEntityDTO.setTestSuites(testSuiteEntityDTOS);620 try {621 pushEnvironmentToLab(testDeviceResult, environmentEntityDTO);622 } catch (Exception e) {623 log.error(e.getMessage(), e);624 testSuiteResultService.markTestSuiteResultAsFailed(testSuiteResult, e.getMessage(),625 StatusConstant.STATUS_PRE_FLIGHT);626 }627 }628 }629 }630 testDeviceResultService.updateEnvironmentConsolidatedResults(testDeviceResult);631 }632 public EnvironmentEntityDTO loadEnvironment(TestDeviceResult testDeviceResult, StatusConstant inStatus)633 throws Exception {634 List<TestSuiteEntityDTO> testSuiteEntityDTOS = loadTestSuites(testDeviceResult, inStatus);635 EnvironmentEntityDTO environmentEntityDTO = loadEnvironmentDetails(testDeviceResult);636 environmentEntityDTO.setTestSuites(testSuiteEntityDTOS);637 return environmentEntityDTO;638 }639 public EnvironmentEntityDTO loadEnvironmentDetails(TestDeviceResult testDeviceResult) throws Exception {640 TestPlanSettingEntityDTO testPlanSettingEntityDTO = this.testPlanMapper.mapSettings(this.testPlan);641 EnvironmentEntityDTO environmentEntityDTO = this.testDeviceResultMapper.map(testDeviceResult);642 TestDevice testDevice = testDeviceResult.getTestDevice();643 if (testDevice.getDeviceId() != null) {644 AgentDevice agentDevice = agentDeviceService.find(testDevice.getDeviceId());645 environmentEntityDTO.setAgentDeviceUuid(agentDevice.getUniqueId());646 }647 environmentEntityDTO.setStorageType(storageServiceFactory.getStorageService().getStorageType());648 testDevice.setWorkspaceVersion(workspaceVersionService.find(testDevice.getWorkspaceVersionId()));649 environmentEntityDTO.setWorkspaceType(testDevice.getWorkspaceVersion().getWorkspace().getWorkspaceType());650 environmentEntityDTO.setExecutionLabType(testDevice.getTestPlanLabType());651 environmentEntityDTO.setTestPlanSettings(testPlanSettingEntityDTO);652 environmentEntityDTO.setMatchBrowserVersion(testDevice.getMatchBrowserVersion());653 environmentEntityDTO.setCreateSessionAtCaseLevel(testDevice.getCreateSessionAtCaseLevel());654 TestDeviceSettings settings = getExecutionTestDeviceSettings(testDevice);655 settings.setExecutionName(testPlan.getName());656 settings.setEnvironmentParamId(this.testPlan.getEnvironmentId());657 settings.setEnvRunId(testDeviceResult.getId());658 setTestLabDetails(testDevice, settings,environmentEntityDTO);659 environmentEntityDTO.setEnvSettings(this.testPlanMapper.mapToDTO(settings));660 Agent agent = null;661 if (testDevice.getAgentId() != null)662 agent = this.agentService.find(testDevice.getAgentId());663 setAgentJWTApiKey(environmentEntityDTO, agent);664 setAvailableFeatures(environmentEntityDTO);665 return environmentEntityDTO;666 }667 private List<TestSuiteEntityDTO> loadTestSuites(TestDeviceResult testDeviceResult, StatusConstant inStatus) {668 List<TestSuiteEntityDTO> testSuiteEntityDTOS = new ArrayList<>();669 List<TestSuiteResult> testSuiteResults = this.testSuiteResultService.findPendingTestSuiteResults(testDeviceResult,670 inStatus);671 for (TestSuiteResult testSuiteResult : testSuiteResults) {672 TestSuiteEntityDTO testSuiteEntity = this.testSuiteResultMapper.map(testSuiteResult);673 testSuiteEntity.setTestCases(loadTestCases(testSuiteResult, inStatus));674 testSuiteEntityDTOS.add(testSuiteEntity);675 }676 return testSuiteEntityDTOS;677 }678 private List<TestCaseEntityDTO> loadTestCases(TestSuiteResult testSuiteResult, StatusConstant inStatus) {679 List<TestCaseResult> testCaseResults = this.testCaseResultService.findActiveSuiteTestCaseResults(680 testSuiteResult.getId(), inStatus);681 List<TestCaseEntityDTO> testCases = new ArrayList<>();682 for (TestCaseResult testCaseResult : testCaseResults) {683 TestCaseEntityDTO testCaseEntity = this.testCaseResultMapper.map(testCaseResult);684 testCaseEntity.setDataDrivenTestCases(loadDataDrivenTestCases(testCaseResult, inStatus));685 testCases.add(testCaseEntity);686 }687 return testCases;688 }689 private List<TestCaseEntityDTO> loadDataDrivenTestCases(TestCaseResult testCaseResult, StatusConstant inStatus) {690 List<TestCaseResult> dataDrivenTestCaseResults =691 this.testCaseResultService.findAllByParentIdAndStatus(testCaseResult.getId(), inStatus);692 return this.testCaseResultMapper.map(dataDrivenTestCaseResults);693 }694 private void setAgentJWTApiKey(EnvironmentEntityDTO environmentEntityDTO, com.testsigma.model.Agent id) throws ResourceNotFoundException {695 TestDeviceSettingsDTO envSettings = environmentEntityDTO.getEnvSettings();696 if (id != null) {697 Agent agent = this.agentService.find(id.getId());698 envSettings.setJwtApiKey(agent.generateJwtApiKey(jwtTokenService.getServerUuid()));699 }700 environmentEntityDTO.setEnvSettings(envSettings);701 }702 private void setAvailableFeatures(EnvironmentEntityDTO dto) throws ResourceNotFoundException, SQLException {703 dto.getTestPlanSettings().setHasSuggestionFeature(true);704 }705 private void pushEnvironmentToLab(TestDeviceResult testDeviceResult, EnvironmentEntityDTO environmentEntityDTO) throws Exception {706 ObjectMapper objectMapper = new ObjectMapper();707 objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);708 objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);709 TestDeviceEntity testDeviceEntity = objectMapper.readValue(objectMapper.writeValueAsString(environmentEntityDTO),710 TestDeviceEntity.class);711 try {712 testDeviceResultService.markEnvironmentResultAsInProgress(testDeviceResult, StatusConstant.STATUS_PRE_FLIGHT,713 Boolean.TRUE);714 new TestPlanRunTask(testDeviceEntity).start();715 log.info("Successfully pushed Execution Environment[" + testDeviceEntity.getEnvironmentResultId()716 + "] to Testsigma Lab");717 } catch (Exception e) {718 log.error(e.getMessage(), e);719 String message = "Error while pushing environment to agent - " + e.getMessage();720 throw new TestsigmaException(message, message);721 }722 }723 private void saveRunTimeData() {724 JSONObject runtimeJSONObj = this.getRunTimeData();725 if (runtimeJSONObj != null && runtimeJSONObj.has("runtime_data")) {726 RunTimeData runTimeData = new RunTimeData();727 runTimeData.setTestPlanRunId(this.getTestPlanResult().getId());728 if (runtimeJSONObj.has("runtime_data")) {729 runTimeData.setData(runtimeJSONObj.getJSONObject("runtime_data"));730 }731 this.runTimeDataService.create(runTimeData);732 }733 }734 public void checkTestCaseIsInReadyState(TestCase testCase) throws TestsigmaException {735 if (!testCase.getStatus().equals(TestCaseStatus.READY) && testPlan.getEntityType()=="TEST_PLAN") {736 String message = testCase.getIsStepGroup() ? com.testsigma.constants.MessageConstants.getMessage(MessageConstants.STEP_GROUP_NOT_READY, testCase.getName()) :737 MessageConstants.TESTCASE_NOT_READY;738 throw new TestsigmaException(message, message);739 }740 }741 private void fetchEnvironmentResultsReRunList() {742 testDeviceResultsReRunList = new ArrayList<>();743 if (getReRunType() == ReRunType.ALL_TESTS) {744 testDeviceResultsReRunList = testDeviceResultService.findAllByTestPlanResultId(this.getParentTestPlanResultId());745 } else if (ReRunType.runFailedTestCases(getReRunType())) {746 testDeviceResultsReRunList = testDeviceResultService.findAllByTestPlanResultIdAndResultIsNot747 (this.getParentTestPlanResultId(), ResultConstant.SUCCESS);748 }749 }750 private void fetchTestSuitesResultsReRunList(Long parentEnvironmentResultId) {751 testSuiteResultsReRunList = new ArrayList<>();752 try {753 TestDeviceResult parentTestDeviceResult = testDeviceResultService.find(parentEnvironmentResultId);754 List<TestSuiteResult> failedTestSuites;755 if (parentTestDeviceResult != null) {756 if (getReRunType() == ReRunType.ALL_TESTS) {757 testSuiteResultsReRunList = testSuiteResultService.findAllByEnvironmentResultId(parentTestDeviceResult.getId());758 } else if (ReRunType.runFailedTestCases(getReRunType())) {759 failedTestSuites = testSuiteResultService.findAllByEnvironmentResultIdAndResultIsNot760 (parentTestDeviceResult.getId(), ResultConstant.SUCCESS);761 if (failedTestSuites.size() > 0) {762 for (TestSuiteResult testSuiteResult : failedTestSuites) {763 List<Long> testSuitePreRequisiteIds = findTestSuitePreRequisiteIds(testSuiteResult, new ArrayList<>(), 0);764 if (testSuitePreRequisiteIds.size() > 0) {765 List<TestSuiteResult> preRequisiteResults = testSuiteResultService.findBySuiteResultIds(testSuitePreRequisiteIds);766 testSuiteResultsReRunList.addAll(preRequisiteResults);767 }768 testSuiteResultsReRunList.add(testSuiteResult);769 }770 }771 }772 }773 } catch (Exception e) {774 log.error(e.getMessage(), e);775 }776 }777 private List<Long> findTestSuitePreRequisiteIds(TestSuiteResult testSuiteResult, List<Long> testSuitePreRequisiteIds,778 int depth) {779 if (depth < PRE_REQUISITE_DEPTH) {780 TestSuiteResult preReqTestSuiteResult;781 try {782 TestSuite testSuite = testSuiteResult.getTestSuite();783 if (testSuite.getPreRequisite() != null) {784 preReqTestSuiteResult = testSuiteResultService.findByEnvironmentResultIdAndSuiteId(785 testSuiteResult.getEnvironmentResultId(), testSuite.getPreRequisite());786 if (preReqTestSuiteResult != null) {787 testSuitePreRequisiteIds = findTestSuitePreRequisiteIds(preReqTestSuiteResult, testSuitePreRequisiteIds,788 depth + 1);789 testSuitePreRequisiteIds.add(preReqTestSuiteResult.getId());790 }791 }792 } catch (Exception e) {793 log.error(e.getMessage(), e);794 }795 }796 return testSuitePreRequisiteIds;797 }798 private void fetchTestCaseResultsReRunList(Long parentTestSuiteResultId) {799 testCaseResultsReRunList = new ArrayList<>();800 try {801 TestSuiteResult parentTestSuiteResult = testSuiteResultService.find(parentTestSuiteResultId);802 List<TestCaseResult> failedTestCases = new ArrayList<>();803 if (parentTestSuiteResult != null) {804 if (getReRunType() == ReRunType.ALL_TESTS || isTestSuiteAPrerequisite(parentTestSuiteResult)) {805 testCaseResultsReRunList = testCaseResultService.findAllBySuiteResultId(parentTestSuiteResult.getId());806 } else if (ReRunType.runFailedTestCases(getReRunType())) {807 if(getReRunType() == ReRunType.ALL_ITERATIONS) {808 log.info("Fetching all iterations in failed data driven test case results for suite result id - " + parentTestSuiteResult.getId());809 List<TestCaseResult> failedTestCaseResults = testCaseResultService.findAllBySuiteResultIdAndIsDataDrivenTrueAndResultIsNot(parentTestSuiteResult.getId(), ResultConstant.SUCCESS);810 for (TestCaseResult testCaseResult : failedTestCaseResults) {811 failedTestCases.addAll(testCaseResultService.findAllBySuiteResultIdAndTestCaseId(parentTestSuiteResult.getId(), testCaseResult.getTestCaseId()));812 }813 }814 else if(getReRunType() == ReRunType.ONLY_FAILED_ITERATIONS_IN_FAILED_TESTS) {815 log.info("Fetching all failed data driven test case results re run list for suite result id - " + parentTestSuiteResult.getId());816 List<TestCaseResult> failedTestCaseResults = testCaseResultService.findAllBySuiteResultIdAndIsDataDrivenTrueAndResultIsNot(parentTestSuiteResult.getId(), ResultConstant.SUCCESS);817 for (TestCaseResult testCaseResult : failedTestCaseResults) {818 failedTestCases.addAll(testCaseResultService.findAllBySuiteResultIdAndTestCaseIdAndResultIsNot(parentTestSuiteResult.getId(), testCaseResult.getTestCaseId(), ResultConstant.SUCCESS));819 }820 }821 else {822 log.info("Fetching all failed test case results re run list for suite result id - " + parentTestSuiteResult.getId());823 failedTestCases = testCaseResultService.findAllBySuiteResultIdAndResultIsNot(parentTestSuiteResult.getId(), ResultConstant.SUCCESS);824 }825 if (failedTestCases.size() > 0) {826 for (TestCaseResult testCaseResult : failedTestCases) {827 List<Long> testCasePreRequisiteIds = findTestCasePreRequisiteIds(testCaseResult, new ArrayList<>(), 0);828 //If a prerequisite is failed, it will be already available in failedTestCases. So we need to add only prerequisites with SUCCESS status.829 List<TestCaseResult> preRequisiteResults = fetchPreRequisiteTestCaseResultsWithSuccessStatus(testCasePreRequisiteIds);830 testCaseResultsReRunList.addAll(preRequisiteResults);831 testCaseResultsReRunList.add(testCaseResult);832 }833 }834 }835 }836 } catch (Exception e) {837 log.error(e.getMessage(), e);838 }839 }840 private List<TestCaseResult> fetchPreRequisiteTestCaseResultsWithSuccessStatus(List<Long> testCasePreRequisiteIds) {841 List<TestCaseResult> preRequisitesWithSuccessStatus = new ArrayList<>();842 List<TestCaseResult> preRequisiteResults = testCaseResultService.findByTestCaseResultIds(testCasePreRequisiteIds);843 for (TestCaseResult testCaseResult : preRequisiteResults) {844 if (testCaseResult.getResult() == ResultConstant.SUCCESS) {845 preRequisitesWithSuccessStatus.add(testCaseResult);846 }847 }848 return preRequisitesWithSuccessStatus;849 }850 private boolean isTestSuiteAPrerequisite(TestSuiteResult testSuiteResult) {851 List<TestSuite> testSuites = testSuiteService.findByPrerequisiteId(testSuiteResult.getSuiteId());852 for (TestSuite testSuite : testSuites) {853 TestSuiteResult baseTestSuiteResult = testSuiteResultService.findByEnvironmentResultIdAndSuiteId(testSuiteResult.getEnvironmentResultId(), testSuite.getId());854 if (baseTestSuiteResult != null) {855 return true;856 }857 }858 return false;859 }860 private List<Long> findTestCasePreRequisiteIds(TestCaseResult testCaseResult, List<Long> testCasePreRequisiteIds,861 int depth) {862 if (depth < PRE_REQUISITE_DEPTH) {863 List<TestCaseResult> preReqTestCaseResults;864 try {865 TestCase testCase = testCaseResult.getTestCase();866 if (testCase.getPreRequisite() != null) {867 //In case of data-driven tests, we have multiple rows in TestCaseResult table for each dataset(each row in testdata profile)868 preReqTestCaseResults = testCaseResultService.findAllBySuiteResultIdAndTestCaseId(869 testCaseResult.getSuiteResultId(), testCase.getPreRequisite());870 if (preReqTestCaseResults != null) {871 for (TestCaseResult preReqTestCaseResult : preReqTestCaseResults) {872 testCasePreRequisiteIds = findTestCasePreRequisiteIds(preReqTestCaseResult, testCasePreRequisiteIds,873 depth + 1);874 testCasePreRequisiteIds.add(preReqTestCaseResult.getId());875 }876 }877 }878 } catch (Exception e) {879 log.error(e.getMessage(), e);880 }881 }882 return testCasePreRequisiteIds;883 }884 // ################################################ AFTER START ###################################################885 private void afterStart() throws Exception {886 setInitialCounts();887 }888 private void setInitialCounts() {889 List<TestDeviceResult> executionEnvironmentsResults890 = testDeviceResultService.findAllByTestPlanResultId(this.getTestPlanResult().getId());891 for (TestDeviceResult executionTestDeviceResult : executionEnvironmentsResults) {892 List<TestCaseResult> testCaseResults = testCaseResultService.findAllByEnvironmentResultId(executionTestDeviceResult.getId());893 for (TestCaseResult testCaseResult : testCaseResults) {894 testCaseResultService.updateResultCounts(testCaseResult);895 }896 List<TestSuiteResult> testSuitesResults = testSuiteResultService.findAllByEnvironmentResultId(executionTestDeviceResult.getId());897 for (TestSuiteResult testSuiteResult : testSuitesResults) {898 testSuiteResultService.updateResultCounts(testSuiteResult.getId());899 }900 testDeviceResultService.updateResultCounts(executionTestDeviceResult.getId());901 }902 }903 // ################################################ STOP ###################################################904 public void stop() throws Exception {905 beforeStop();906 stopQueuedEnvironments(AutomatorMessages.MSG_USER_ABORTED_EXECUTION, Boolean.TRUE);907 afterStop();908 }909 private void beforeStop() throws TestsigmaException {910 TestPlanResult testPlanResult = this.testPlanResultService.findByTestPlanIdAndStatusIsNot(this.testPlan.getId(),911 StatusConstant.STATUS_COMPLETED);912 if (testPlanResult == null) {913 throw new TestsigmaException("No Queued executions for test plan - " + this.getTestPlan().getName());914 }915 this.setTestPlanResult(testPlanResult);916 }917 private void stopQueuedEnvironments(String errorMessage, Boolean sendPendingExecutions) {918 List<TestDeviceResult> testDeviceResults = this.testDeviceResultService919 .findAllByTestPlanResultIdAndStatusIsNot(this.testPlanResult.getId(), StatusConstant.STATUS_COMPLETED);920 for (TestDeviceResult testDeviceResult : testDeviceResults) {921 testDeviceResultService.markEnvironmentResultAsStopped(testDeviceResult, errorMessage);922 testDeviceResultService.updateResultCounts(testDeviceResult.getId());923 }924 Timestamp currentTime = new Timestamp(java.lang.System.currentTimeMillis());925 TestPlanResult testPlanResult = this.testPlanResult;926 testPlanResult.setResult(ResultConstant.STOPPED);927 testPlanResult.setStatus(StatusConstant.STATUS_COMPLETED);928 testPlanResult.setMessage(errorMessage);929 testPlanResult.setEndTime(currentTime);930 testPlanResult.setDuration(testPlanResult.getEndTime().getTime() - testPlanResult.getStartTime().getTime());931 this.testPlanResultService.update(testPlanResult);932 try {933 if (sendPendingExecutions) {934 testDeviceResultService.sendPendingTestPlans();935 }936 } catch (Exception e) {937 log.error(e.getMessage(), e);938 }939 }940 private void afterStop() {941 }942 protected void setTestLabDetails(TestDevice testDevice, TestDeviceSettings settings,EnvironmentEntityDTO environmentEntityDTO)943 throws Exception {944 if (testDevice.getWorkspaceVersion().getWorkspace().getWorkspaceType().isRest())945 return;946 TestPlanLabType exeLabType = testDevice.getTestPlanLabType();947 setPlatformDetails(testDevice, settings, exeLabType, testDevice.getAgent(), environmentEntityDTO);948 }949 public void loadTestCase(String testDataSetName, TestCaseEntityDTO testCaseEntityDTO, AbstractTestPlan testPlan, TestDevice testDevice,950 Workspace workspace) throws Exception {951 String profileName = null;952 String environmentProfileName = null;953 Map<String, String> environmentParameters = null;954 List<com.testsigma.model.TestDataSet> databank = new ArrayList<>();955 com.testsigma.model.TestDataSet dataSet = null;956 if (testPlan.getEnvironmentId() != null) {957 Environment environment = testPlan.getEnvironment();958 environmentParameters = environment.getData();959 environmentProfileName = environment.getName();960 }961 List<TestStep> testSteps = testStepService.findAllByTestCaseIdAndEnabled(testCaseEntityDTO.getId());962 List<TestStepDTO> testStepDTOS = testStepMapper.mapDTOs(testSteps);963 Long testDataId = testCaseEntityDTO.getTestDataId();964 if (testDataId != null) {965 TestData testData = testDataProfileService.find(testCaseEntityDTO.getTestDataId());966 testCaseEntityDTO.setTestDataProfileName(testData.getTestDataName());967 databank = testData.getData();968 profileName = testData.getTestDataName();969 }970 if (!testCaseEntityDTO.getIsDataDriven()) {971 if (!databank.isEmpty()) {972 log.info("Test case is not data driven. but has associated test data id");973 int currentIndex = testCaseEntityDTO.getTestDataStartIndex();974 dataSet = databank.get(currentIndex);975 testCaseEntityDTO.setTestDataSetName(dataSet.getName());976 testCaseEntityDTO.setTestDataIndex(currentIndex);977 }978 } else {979 log.info("Test case is data driven...Matching data set with - " + testDataSetName);980 for (int i = 0; i < databank.size(); i++) {981 TestDataSet data = databank.get(i);982 if (data.getName().equals(testDataSetName)) {983 dataSet = data;984 testCaseEntityDTO.setTestDataIndex(i);985 break;986 }987 }988 testCaseEntityDTO.setTestDataSetName(dataSet.getName());989 testCaseEntityDTO.setExpectedToFail(dataSet.getExpectedToFail());990 }991 List<Long> testCaseIds = new ArrayList<>();992 testCaseIds.add(testCaseEntityDTO.getId());993 for (TestStepDTO testStepDTO : testStepDTOS) {994 if (testStepDTO.getStepGroupId() != null) {995 TestCase testCase = testCaseService.find(testStepDTO.getStepGroupId());996 checkTestCaseIsInReadyState(testCase);997 List<TestStep> childSteps;998 childSteps = testStepService.findAllByTestCaseIdAndEnabled(testStepDTO.getStepGroupId());999 List<TestStepDTO> childStepsDTOs = testStepMapper.mapDTOs(childSteps);1000 testStepDTO.setTestStepDTOS(childStepsDTOs);1001 testCaseIds.add(testStepDTO.getStepGroupId());1002 }1003 if (testStepDTO.getAddonActionId() != null) {1004 if (!testDevice.getTestPlanLabType().isHybrid()) {1005 AddonNaturalTextAction addonNaturalTextAction = addonNaturalTextActionService.findById(testStepDTO.getAddonActionId());1006 Addon addon = addonService.findById(addonNaturalTextAction.getAddonId());1007 if (addon.getStatus() == AddonStatus.DRAFT) {1008 throw new TestsigmaException(MessageConstants.DRAFT_PLUGIN_ALLOWED_IN_HYBRID_ONLY,1009 MessageConstants.DRAFT_PLUGIN_ALLOWED_IN_HYBRID_ONLY);1010 }1011 }1012 }1013 }1014 List<String> elementNames = testStepService.findElementNamesByTestCaseIds(testCaseIds);1015 elementNames.addAll(testStepService.findAddonActionElementsByTestCaseIds(testCaseIds));1016 List<Element> elementList = elementService.findByNameInAndWorkspaceVersionId(elementNames,1017 testDevice.getWorkspaceVersionId());1018 Map<String, Element> elements = new HashMap<>();1019 for (Element element : elementList) {1020 elements.put(element.getName().toLowerCase(), element);1021 }1022 if (!testCaseEntityDTO.getIsDataDriven()) {1023 if (!databank.isEmpty()) {1024 dataSet = databank.get(testCaseEntityDTO.getTestDataStartIndex());1025 testCaseEntityDTO.setTestDataSetName(dataSet.getName());1026 }1027 } else {1028 for (TestDataSet data : databank) {1029 if (data.getName().equals(testDataSetName)) {1030 dataSet = data;1031 break;1032 }1033 }1034 testCaseEntityDTO.setTestDataSetName(dataSet.getName());1035 testCaseEntityDTO.setExpectedToFail(dataSet.getExpectedToFail());1036 }1037 List<TestCaseStepEntityDTO> executableList = getExecutableTestSteps(1038 workspace.getWorkspaceType(), testStepDTOS,1039 elements, dataSet, testPlan.getId(),1040 environmentParameters, testCaseEntityDTO, environmentProfileName,1041 profileName,getStepGroupParentForLoopStepIdIndexes(testCaseEntityDTO));1042 appendPreSignedURLs(executableList, testCaseEntityDTO, testDevice,false, null, null);1043 testCaseEntityDTO.setTestSteps(executableList);1044 TestCaseResult testCaseResult = testCaseResultService.find(testCaseEntityDTO.getTestCaseResultId());1045 testCaseResultService.markTestCaseResultAsInProgress(testCaseResult);1046 }1047 private Map<Long, Integer> getStepGroupParentForLoopStepIdIndexes(TestCaseEntityDTO testCaseEntityDTO){1048 Map<Long, Integer> dataIndex = testCaseEntityDTO.getStepGroupParentForLoopStepIdIndexes();1049 if(!testCaseEntityDTO.getIsStepGroup()){1050 dataIndex.put(ParameterTestDataProcessor.OVERRIDE_STEP_GROUP_STEP_WITH_TEST_CASE_PROFILE_ID,1051 testCaseEntityDTO.getTestDataIndex() == null ? 0 : testCaseEntityDTO.getTestDataIndex());1052 }1053 return dataIndex;1054 }1055 private boolean isStepInsideForLoop(TestCaseStepEntityDTO testCaseStepEntity) throws ResourceNotFoundException {1056 if (testCaseStepEntity.getParentId() != null) {1057 TestStep testStep = testStepService.find(testCaseStepEntity.getParentId());1058 return (testStep.getType() == TestStepType.FOR_LOOP);1059 }1060 return false;1061 }1062 protected void appendPreSignedURLs(List<TestCaseStepEntityDTO> executableList, TestCaseEntityDTO testCaseEntity,1063 TestDevice testDevice, boolean isWhileLoop, Long stepGroupStepID, TestCaseStepEntityDTO parentGroupEntity)1064 throws ResourceNotFoundException {1065 Calendar cal = Calendar.getInstance();1066 cal.add(Calendar.HOUR, 10);1067 stepGroupStepID = (stepGroupStepID == null) ? 0 : stepGroupStepID;1068 StorageService storageService = this.storageServiceFactory.getStorageService();1069 for (TestCaseStepEntityDTO testCaseStepEntity : executableList) {1070 Integer index;1071 Long parentId = testCaseStepEntity.getParentId();1072 if(parentId == null)1073 parentId = 0L;1074 int rand =0;1075 if (parentGroupEntity != null && !isStepInsideForLoop(testCaseStepEntity)) {1076 index = (parentGroupEntity.getIndex() == null) ? 0 : parentGroupEntity.getIndex();1077 } else {1078 rand = new Random().ints(1, 100).findFirst().getAsInt();1079 index = (testCaseStepEntity.getIndex() == null) ? 0 : testCaseStepEntity.getIndex();1080 }1081 String screenShotPath = String.format("/executions/%s/%s_%s_%s_%s_%s_%s.%s", testCaseEntity.getTestCaseResultId(),1082 testCaseStepEntity.getId(), stepGroupStepID, parentId, testCaseStepEntity.getPosition(), index, rand ,"jpeg");1083 URL presignedURL = storageService.generatePreSignedURL(screenShotPath, StorageAccessLevel.WRITE, 600);1084 testCaseStepEntity.setScreenshotPath(presignedURL.toString());1085 handleUploadActionStep(testCaseStepEntity,storageService, testDevice);1086 handleInstallApp(testCaseStepEntity,storageService, testDevice);1087 if ((testCaseStepEntity.getTestCaseSteps() != null) && !testCaseStepEntity.getTestCaseSteps().isEmpty()) {1088 if (testCaseStepEntity.getConditionType() == TestStepConditionType.LOOP_WHILE) {1089 addScreenshotPresignedURLsForWhileLoop(testCaseStepEntity, testCaseEntity, stepGroupStepID, parentGroupEntity,storageService);1090 appendPreSignedURLs(testCaseStepEntity.getTestCaseSteps(), testCaseEntity, testDevice,true, stepGroupStepID, parentGroupEntity);1091 } else if (testCaseStepEntity.getType() == TestStepType.STEP_GROUP) {1092 Long parentGroupStepId = (stepGroupStepID != 0) ? stepGroupStepID : testCaseStepEntity.getId();1093 appendPreSignedURLs(testCaseStepEntity.getTestCaseSteps(), testCaseEntity, testDevice, isWhileLoop, parentGroupStepId, testCaseStepEntity);1094 } else {1095 appendPreSignedURLs(testCaseStepEntity.getTestCaseSteps(), testCaseEntity, testDevice, isWhileLoop, stepGroupStepID, parentGroupEntity);1096 }1097 }1098 if (isWhileLoop && !(testCaseStepEntity.getType() == TestStepType.STEP_GROUP)) {1099 addScreenshotPresignedURLsForWhileLoop(testCaseStepEntity, testCaseEntity, stepGroupStepID, parentGroupEntity,storageService);1100 }1101 }1102 }1103 private void addScreenshotPresignedURLsForWhileLoop(TestCaseStepEntityDTO testCaseStep, TestCaseEntityDTO testCaseEntity,1104 Long parentGroupStepId, TestCaseStepEntityDTO parentGroupEntity, StorageService storageService) {1105 parentGroupStepId = (parentGroupStepId == null) ? 0 : parentGroupStepId;1106 Map<String, String> additionalScreenshotPaths = new HashMap<>();1107 for (int iteration = 1; iteration <= NaturalTextActionConstants.WHILE_LOOP_MAX_LIMIT; iteration++) {1108 Calendar cal = Calendar.getInstance();1109 cal.add(Calendar.HOUR, 10);1110 Integer index = null;1111 if (parentGroupEntity != null) {1112 index = (parentGroupEntity.getIndex() == null) ? 0 : parentGroupEntity.getIndex();1113 } else {1114 index = (testCaseStep.getIndex() == null) ? 0 : testCaseStep.getIndex();1115 }1116 String screenShotPath = String.format("/executions/%s/%s_%s_%s_%s_%s.%s", testCaseEntity.getTestCaseResultId(),1117 testCaseStep.getId(), parentGroupStepId, iteration, testCaseStep.getPosition(), index, "jpeg");1118 URL preSignedURL = storageService.generatePreSignedURL(screenShotPath, StorageAccessLevel.WRITE, 600);1119 String iterationKey = String.format("%s_%s", iteration, testCaseStep.getIndex());1120 additionalScreenshotPaths.put(iterationKey, preSignedURL.toString());1121 }1122 testCaseStep.setAdditionalScreenshotPaths(additionalScreenshotPaths);1123 }1124 private void handleUploadActionStep(TestCaseStepEntityDTO testCaseStepEntity, StorageService storageService, TestDevice testDevice) {1125 if (testCaseStepEntity.getAction() != null && testCaseStepEntity.getAction().toLowerCase().contains("upload")1126 && testCaseStepEntity.getNaturalTextActionId() != null && (testCaseStepEntity.getNaturalTextActionId().equals(969)1127 || testCaseStepEntity.getNaturalTextActionId().equals(10150))) {1128 handleFileActionStep(testCaseStepEntity,storageService, testDevice);1129 }1130 }1131 private void handleInstallApp(TestCaseStepEntityDTO testCaseStepEntity, StorageService storageService, TestDevice testDevice) {1132 if (testCaseStepEntity.getAction() != null && testCaseStepEntity.getAction()1133 .toLowerCase().contains("installApp".toLowerCase()) && (testCaseStepEntity.getNaturalTextActionId() != null)1134 && (testCaseStepEntity.getNaturalTextActionId().equals(20003) || testCaseStepEntity.getNaturalTextActionId().equals(30003))) {1135 handleFileActionStep(testCaseStepEntity,storageService, testDevice);1136 }1137 }1138 private void handleFileActionStep(TestCaseStepEntityDTO testCaseStepEntity, StorageService storageService, TestDevice testDevice) {1139 com.testsigma.automator.entity.TestDataPropertiesEntity testDataPropertiesEntity = testCaseStepEntity.getTestDataMap().get(1140 testCaseStepEntity.getTestDataMap().keySet().stream().findFirst().get());1141 String fileUrl = testDataPropertiesEntity.getTestDataValue().replace("testsigma-storage://", "");1142 URL newUrl = storageService.generatePreSignedURL(fileUrl, StorageAccessLevel.READ, 180);1143 if(TestPlanLabType.TestsigmaLab == testDevice.getTestPlanLabType()) {1144 try {1145 newUrl = new URL(newUrl.toString().replace(applicationConfig.getServerUrl(), applicationConfig.getServerLocalUrl()));1146 } catch (MalformedURLException ignore) {}1147 }1148 testDataPropertiesEntity.setTestDataValuePreSignedURL(newUrl.toString());1149 }1150 private void setPlatformDetails(TestDevice testDevice, TestDeviceSettings settings,1151 TestPlanLabType testPlanLabType, Agent agent,EnvironmentEntityDTO environmentEntityDTO) throws TestsigmaException {1152 populatePlatformOsDetails(testDevice, settings, testPlanLabType, agent);1153 if (testDevice.getWorkspaceVersion().getWorkspace().getWorkspaceType().isWeb()) {1154 populatePlatformBrowserDetails(testDevice, settings, testPlanLabType, agent,environmentEntityDTO);1155 }1156 }1157 protected void populatePlatformOsDetails(TestDevice testDevice, TestDeviceSettings settings,1158 TestPlanLabType testPlanLabType, Agent agent)1159 throws TestsigmaException {1160 PlatformOsVersion platformOsVersion = null;1161 if (testPlanLabType == TestPlanLabType.Hybrid) {1162 Platform platform = null;1163 String osVersion = null;1164 if ((testDevice.getWorkspaceVersion().getWorkspace().getWorkspaceType().isWeb()) && agent != null) {1165 platform = agent.getOsType().getPlatform();1166 osVersion = agent.getPlatformOsVersion(agent.getOsType().getPlatform());1167 } else if (testDevice.getWorkspaceVersion().getWorkspace().getWorkspaceType().isMobile() && testDevice.getDeviceId() != null) {1168 AgentDevice agentDevice = this.agentDeviceService.find(testDevice.getDeviceId());1169 osVersion = agentDevice.getPlatformOsVersion();1170 platform = agentDevice.getOsName().getPlatform();1171 }1172 platformOsVersion = platformsService.getPlatformOsVersion(platform, osVersion, testDevice.getWorkspaceVersion().getWorkspace().getWorkspaceType(), testPlanLabType);1173 }1174 else {1175 platformOsVersion = platformsService.getPlatformOsVersion(testDevice.getPlatformOsVersionId(), testPlanLabType);1176 }1177 if (testPlanLabType != TestPlanLabType.PrivateGrid)1178 settings.setPlatform(platformOsVersion.getPlatform());1179 else1180 settings.setPlatform(testDevice.getPlatform());1181 if (TestPlanLabType.Hybrid == testPlanLabType) {1182 settings.setOsVersion(platformOsVersion.getVersion());1183 }1184 }1185 protected void populatePlatformBrowserDetails(TestDevice testDevice, TestDeviceSettings settings,1186 TestPlanLabType testPlanLabType, Agent agent,EnvironmentEntityDTO environmentEntityDTO)1187 throws TestsigmaException {1188 PlatformBrowserVersion platformBrowserVersion = null;1189 if (agent != null && testPlanLabType == TestPlanLabType.Hybrid) {1190 Platform platform = agent.getOsType().getPlatform();1191 String osVersion = agent.getPlatformOsVersion(platform);1192 Browsers browser = OSBrowserType.getBrowser(testDevice.getBrowser());1193 String browserVersion = agent.getBrowserVersion(browser.toString());1194 platformBrowserVersion = platformsService.getPlatformBrowserVersion(platform, osVersion, browser, browserVersion, testPlanLabType);1195 } else {1196 platformBrowserVersion = platformsService.getPlatformBrowserVersion(testDevice.getPlatformBrowserVersionId(), testPlanLabType);1197 }1198 if (testPlanLabType.isHybrid()) {1199 matchHybridBrowserVersion(agent, platformBrowserVersion, testDevice, platformBrowserVersion.getName(),environmentEntityDTO);1200 }1201 if (testPlanLabType != TestPlanLabType.PrivateGrid)1202 settings.setBrowser(platformBrowserVersion.getName().name());1203 else settings.setBrowser(Browsers.getBrowser(testDevice.getBrowser()).name());1204 if (testPlanLabType == TestPlanLabType.Hybrid) {1205 settings.setBrowserVersion(platformBrowserVersion.getVersion());1206 settings.setHybridBrowserDriverPath(1207 platformsService.getDriverPath(platformBrowserVersion.getPlatform(),1208 platformBrowserVersion.getVersion(), platformBrowserVersion.getName(),1209 platformBrowserVersion.getDriverVersion()));1210 } else {1211 if (testPlanLabType != TestPlanLabType.PrivateGrid)1212 settings.setBrowserVersion(platformBrowserVersion.getVersion());1213 else settings.setBrowserVersion(testDevice.getBrowserVersion());1214 }1215 }1216 private void matchHybridBrowserVersion(Agent agent1, PlatformBrowserVersion platformBrowserVersion,1217 TestDevice testDevice, Browsers browser,EnvironmentEntityDTO environmentEntityDTO)1218 throws TestsigmaException {1219 if ((agent1 != null) && (platformBrowserVersion != null)) {1220 Agent agent = agentService.find(agent1.getId());1221 for (AgentBrowser agentBrowser : agent.getBrowserList()) {1222 Browsers aBrowser = Browsers.getBrowser(agentBrowser.getName().getBrowserName());1223 if ((browser == aBrowser) &&1224 (Boolean.TRUE == testDevice.getMatchBrowserVersion()) &&1225 !platformBrowserVersion.getVersion().equals("" + agentBrowser.getMajorVersion())) {1226 environmentEntityDTO.setErrorCode(ExceptionErrorCodes.BROWSER_VERSION_NOT_AVAILABLE);1227 log.info("Local agent browser version[" + agentBrowser.getMajorVersion()1228 + "] doesn't match selected browser version[" + platformBrowserVersion.getVersion() + "]");1229 }1230 }1231 }1232 }1233 public List<TestCaseStepEntityDTO> getExecutableTestSteps(WorkspaceType workspaceType,1234 List<TestStepDTO> testStepDTOS,1235 Map<String, Element> elementMap,1236 com.testsigma.model.TestDataSet testDataSet,1237 Long testPlanId, Map<String, String> environmentParams,1238 TestCaseEntityDTO testCaseEntityDTO, String environmentParamSetName,1239 String dataProfile, Map<Long, Integer> dataSetIndex) throws Exception {1240 List<Long> loopIds = new ArrayList<>();1241 List<TestCaseStepEntityDTO> toReturn = new ArrayList<>();1242 for (TestStepDTO testStepDTO : testStepDTOS) {1243 if (loopIds.contains(testStepDTO.getParentId())) {1244 continue;1245 }1246 if (testStepDTO.getType() == TestStepType.FOR_LOOP) {1247 loopIds.add(testStepDTO.getId());1248 new ForLoopStepProcessor(webApplicationContext, toReturn, workspaceType, elementMap, testStepDTO,1249 testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName, dataProfile, dataSetIndex).processLoop(testStepDTOS, loopIds);1250 continue;1251 } else if (testStepDTO.getType() == TestStepType.WHILE_LOOP) {1252 loopIds.add(testStepDTO.getId());1253 new WhileLoopStepProcessor(webApplicationContext, toReturn, workspaceType, elementMap, testStepDTO,1254 testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName, dataProfile, dataSetIndex).processWhileLoop(testStepDTOS, loopIds);1255 continue;1256 } else if (testStepDTO.getType() == TestStepType.REST_STEP) {1257 new RestStepProcessor(webApplicationContext, toReturn, workspaceType, elementMap, testStepDTO,1258 testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName, dataProfile, dataSetIndex).process();1259 continue;1260 }1261 TestCaseStepEntityDTO stepEntity = new StepProcessor(webApplicationContext, toReturn, workspaceType,1262 elementMap, testStepDTO, testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName,1263 dataProfile, dataSetIndex).processStep();1264 stepEntity.setStepGroupId(testStepDTO.getStepGroupId());1265 stepEntity.setParentId(testStepDTO.getParentId());1266 stepEntity.setConditionType(testStepDTO.getConditionType());1267 stepEntity.setVisualEnabled(testStepDTO.getVisualEnabled());1268 if (testStepDTO.getTestStepDTOS() != null) {1269 for (TestStepDTO subTestStepDTO : testStepDTO.getTestStepDTOS()) {1270 List<TestCaseStepEntityDTO> stepGroupSpecialSteps = new ArrayList<>();1271 if (stepEntity.getTestCaseSteps() == null) {1272 stepEntity.setTestCaseSteps(new ArrayList<>());1273 }1274 //TODO: check logic for test step key Generation and recursive logic for step group generation1275 if (loopIds.contains(subTestStepDTO.getParentId())) {1276 continue;1277 }1278 if (subTestStepDTO.getType() == TestStepType.FOR_LOOP) {1279 loopIds.add(subTestStepDTO.getId());1280 new ForLoopStepProcessor(webApplicationContext, stepGroupSpecialSteps, workspaceType, elementMap, subTestStepDTO,1281 testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName, dataProfile, dataSetIndex)1282 .processLoop(testStepDTO.getTestStepDTOS(), loopIds);1283 stepEntity.getTestCaseSteps().addAll(stepGroupSpecialSteps);1284 continue;1285 } else if (subTestStepDTO.getType() == TestStepType.WHILE_LOOP) {1286 loopIds.add(subTestStepDTO.getId());1287 new WhileLoopStepProcessor(webApplicationContext, stepGroupSpecialSteps, workspaceType, elementMap,1288 subTestStepDTO, testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName,1289 dataProfile, dataSetIndex).processWhileLoop(testStepDTO.getTestStepDTOS(), loopIds);1290 stepEntity.getTestCaseSteps().addAll(stepGroupSpecialSteps);1291 continue;1292 } else if (subTestStepDTO.getType() == TestStepType.REST_STEP) {1293 new RestStepProcessor(webApplicationContext, stepGroupSpecialSteps, workspaceType, elementMap, subTestStepDTO,1294 testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName, dataProfile, dataSetIndex).process();1295 stepEntity.getTestCaseSteps().addAll(stepGroupSpecialSteps);1296 continue;1297 }1298 TestCaseStepEntityDTO cstepEntity = new StepProcessor(webApplicationContext, toReturn, workspaceType,1299 elementMap, subTestStepDTO, testPlanId, testDataSet, environmentParams, testCaseEntityDTO,1300 environmentParamSetName, dataProfile, dataSetIndex).processStep();1301 cstepEntity.setParentId(subTestStepDTO.getParentId());1302 cstepEntity.setConditionType(subTestStepDTO.getConditionType());1303 stepEntity.getTestCaseSteps().add(cstepEntity);1304 }1305 }1306 toReturn.add(stepEntity);1307 }1308 return toReturn;1309 }1310 private WorkspaceType getAppType() {1311 return this.testPlan.getWorkspaceVersion().getWorkspace().getWorkspaceType();1312 }1313 protected void populatePreRequisiteEnvironmentResultIds(TestPlanResult executionResult){1314 List<TestDeviceResult> environmentResults = testDeviceResultService.findAllByTestPlanResultId(executionResult.getId());1315 for(TestDeviceResult environmentResult: environmentResults){1316 Long executionEnvironmentPreRequisiteId = environmentResult.getTestDevice().getPrerequisiteTestDevicesId();1317 if(executionEnvironmentPreRequisiteId != null){1318 TestDeviceResult preRequisiteEnvironmentResult = testDeviceResultService.findByTestPlanResultIdAndTestDeviceId(executionResult.getId(),executionEnvironmentPreRequisiteId);1319 environmentResult.setPrerequisiteTestDeviceResultId(preRequisiteEnvironmentResult.getId());1320 testDeviceResultService.update(environmentResult);1321 }1322 }1323 }1324 protected boolean isWaitingOnEnvironmentPrerequisite(TestDeviceResult environmentResult) throws ResourceNotFoundException {1325 Long preRequisiteEnvironmentResultId = environmentResult.getPrerequisiteTestDeviceResultId();1326 if(preRequisiteEnvironmentResultId != null){1327 TestDeviceResult preRequisiteEnvironmentResult = testDeviceResultService.find(preRequisiteEnvironmentResultId);1328 if(preRequisiteEnvironmentResult.getStatus() != StatusConstant.STATUS_COMPLETED){1329 return true;1330 }1331 }1332 return false;1333 }1334 protected boolean isEnvironmentPrerequisiteResultSuccessful(TestDeviceResult environmentResult) throws ResourceNotFoundException {1335 Long preRequisiteEnvironmentResultId = environmentResult.getPrerequisiteTestDeviceResultId();1336 if(preRequisiteEnvironmentResultId != null){1337 TestDeviceResult preRequisiteEnvironmentResult = testDeviceResultService.find(preRequisiteEnvironmentResultId);1338 if(preRequisiteEnvironmentResult.getResult() == ResultConstant.SUCCESS){1339 return true;1340 }1341 }1342 return false;1343 }1344 private void createTestCaseDataDrivenReRunResult(TestPlanResult result, List<TestDataSet> testDataSets,1345 TestCase testCase, AbstractTestSuite testSuite,1346 TestDeviceResult environmentResult, TestSuiteResult testSuiteResult,1347 TestCaseResult parentTestCaseResult) throws DataIntegrityViolationException, TestsigmaException {1348 if(ReRunType.runAllIterations(result.getReRunType())){1349 log.info("Fetching all iteration re run list of test case result id - " + parentTestCaseResult.getReRunParentId());1350 dataDrivenResultsReRunList = this.testCaseDataDrivenResultService.findAllByTestCaseResultId(parentTestCaseResult.getReRunParentId());1351 }1352 else if(ReRunType.runFailedIterations(result.getReRunType())) {1353 log.info("Fetching all failed iteration re run list of test case result id - " + parentTestCaseResult.getReRunParentId());1354 dataDrivenResultsReRunList = this.testCaseDataDrivenResultService.findByTestCaseResultIdAndResultNot(parentTestCaseResult.getReRunParentId(),1355 ResultConstant.SUCCESS);1356 }1357 Set<String> setNames = dataDrivenResultsReRunList.stream().map(TestCaseDataDrivenResult::getTestDataName).collect(Collectors.toSet());1358 for(TestDataSet testDataSet : testDataSets) {1359 if(setNames.contains(testDataSet.getName())) {1360 this.createTestCaseIterationResult(testDataSets, testDataSet, testCase, testSuite, environmentResult,1361 testSuiteResult, parentTestCaseResult);1362 }1363 }1364 }1365 private void createTestCaseIterationResult(List<TestDataSet> testDataSets, TestDataSet testDataSet,1366 TestCase testCase, AbstractTestSuite testSuite,1367 TestDeviceResult environmentResult, TestSuiteResult testSuiteResult,1368 TestCaseResult parentTestCaseResult) throws DataIntegrityViolationException, TestsigmaException {1369 testCase.setIsDataDriven(false);1370 testCase.setTestDataStartIndex(testDataSets.indexOf(testDataSet));1371 log.info("Populating DataDrivenTestcaseResult for test data set - " + testDataSet);1372 TestCaseResult testCaseResult = createTestCaseResult(testSuite, testCase, environmentResult, testSuiteResult,1373 parentTestCaseResult);1374 if (testCaseResult != null)1375 createTestCaseDataDrivenResult(testDataSet, testCaseResult);1376 if(isDataDrivenRerun && !parentTestCaseResult.getIsStepGroup())1377 setReRunParentId(testCaseResult, testDataSet, parentTestCaseResult.getReRunParentId());1378 }1379 private void setReRunParentId(TestCaseResult testCaseResult, TestDataSet testDataSet, Long parentResultId ){1380 if(testCaseResult != null && testDataSet != null) {1381 log.info("Populating re-run parentId for the data driven iteration result -" + testCaseResult.getId());1382 TestCaseDataDrivenResult result = this.getTestCaseDataDrivenResult(testDataSet.getName(), parentResultId);1383 testCaseResult.setReRunParentId(result.getIterationResultId());1384 this.testCaseResultService.create(testCaseResult);1385 }1386 }1387 private TestCaseDataDrivenResult getTestCaseDataDrivenResult(String setName, Long parentTestCaseId){1388 Predicate<TestCaseDataDrivenResult> name = dResult -> Objects.equals(dResult.getTestDataName(), setName);1389 Predicate<TestCaseDataDrivenResult> parent = dResult -> Objects.equals(dResult.getTestCaseResultId(), parentTestCaseId);1390 Predicate<TestCaseDataDrivenResult> resultPredicate = name.and(parent);1391 List<TestCaseDataDrivenResult> testCaseDataDrivenResult = dataDrivenResultsReRunList.stream().filter(resultPredicate).collect(Collectors.toList());1392 return testCaseDataDrivenResult.get(0);1393 }1394}...

Full Screen

Full Screen

Source:TestCaseDataDrivenResultService.java Github

copy

Full Screen

...30 }31 public void deleteByIterationResultId(Long deleteByTestCaseResultId) {32 testCaseDataDrivenResultRepository.deleteByIterationResultId(deleteByTestCaseResultId);33 }34 public TestCaseDataDrivenResult create(TestCaseResultRequest testCaseResultRequest, TestDataSet testDataSet) {35 TestCaseDataDrivenResult testCaseDataDrivenResult = testCaseDataDrivenResultMapper.map(testCaseResultRequest);36 testCaseDataDrivenResult.setTestData(new ObjectMapperService().convertToJson(testDataSet));37 return testCaseDataDrivenResultRepository.save(testCaseDataDrivenResult);38 }39 public Page<TestCaseDataDrivenResult> findAll(Specification<TestCaseDataDrivenResult> spec, Pageable pageable) {40 return testCaseDataDrivenResultRepository.findAll(spec, pageable);41 }42 public TestCaseDataDrivenResult create(TestCaseDataDrivenResult testCaseDataDrivenResult) {43 return this.testCaseDataDrivenResultRepository.save(testCaseDataDrivenResult);44 }45}

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1public class 2 {2 public static void main(String[] args) throws Exception {3 TestCaseDataDrivenResultService testCaseDataDrivenResultService = new TestCaseDataDrivenResultService();4 TestCaseDataDrivenResult testCaseDataDrivenResult = new TestCaseDataDrivenResult();5 testCaseDataDrivenResult.setTestCaseId("testcaseid");6 testCaseDataDrivenResult.setTestCaseName("testcasename");7 testCaseDataDrivenResult.setTestCaseResult("testcaseresult");8 testCaseDataDrivenResult.setTestCaseData("testcasedata");9 testCaseDataDrivenResult.setTestCaseDataResult("testcasedataresult");10 testCaseDataDrivenResult.setTestCaseDataResultStatus("testcasedataresultstatus");11 testCaseDataDrivenResult.setTestCaseDataResultDescription("testcasedataresultdescription");12 testCaseDataDrivenResult.setTestCaseDataResultAttachment("testcasedataresultattachment");13 testCaseDataDrivenResult.setTestCaseDataResultAttachmentType("testcasedataresultattachmenttype");14 testCaseDataDrivenResult.setTestCaseDataResultAttachmentName("testcasedataresultattachmentname");15 testCaseDataDrivenResult.setTestCaseDataResultAttachmentDescription("testcasedataresultattachmentdescription");16 testCaseDataDrivenResult.setTestCaseDataResultAttachmentUrl("testcasedataresultattachmenturl");17 testCaseDataDrivenResult.setTestCaseDataResultAttachmentThumbnailUrl("testcasedataresultattachmentthumbnailurl");18 testCaseDataDrivenResult.setTestCaseDataResultAttachmentThumbnailHeight("testcasedataresultattachmentthumbnailheight");19 testCaseDataDrivenResult.setTestCaseDataResultAttachmentThumbnailWidth("testcasedataresultattachmentthumbnailwidth");20 testCaseDataDrivenResult.setTestCaseDataResultAttachmentThumbnailSize("testcasedataresultattachmentthumbnailsize");21 testCaseDataDrivenResult.setTestCaseDataResultAttachmentSize("testcasedataresultattachmentsize");22 testCaseDataDrivenResult.setTestCaseDataResultAttachmentHeight("testcasedataresultattachmentheight");23 testCaseDataDrivenResult.setTestCaseDataResultAttachmentWidth("testcasedataresultattachmentwidth");24 testCaseDataDrivenResult.setTestCaseDataResultAttachmentCreatedDate("testcasedataresultattachmentcreateddate");25 testCaseDataDrivenResult.setTestCaseDataResultAttachmentModifiedDate("testcasedataresultattachmentmodifieddate");26 testCaseDataDrivenResult.setTestCaseDataResultAttachmentCreatedBy("testcasedataresultattachmentcreatedby");27 testCaseDataDrivenResult.setTestCaseDataResultAttachmentModifiedBy("testcasedataresultattachmentmodifiedby");28 testCaseDataDrivenResult.setTestCaseDataResultAttachmentDeleted("testcasedataresultattachmentdeleted");

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1package com.testsigma.service;2import com.testsigma.service.TestCaseDataDrivenResultService;3import com.testsigma.service.TestCaseDataDrivenResultServiceFactory;4import com.testsigma.service.TestCaseDataDrivenResultServiceFactoryImpl;5import com.testsigma.service.TestCaseDataDrivenResultService;6import com.testsigma.service.TestCaseDataDrivenResultServiceFactory;7import com.testsigma.service.TestCaseDataDrivenResultServiceFactoryImpl;8public class TestCaseDataDrivenResultServiceTest {9public static void main(String[] args) {10TestCaseDataDrivenResultServiceFactory factory = new TestCaseDataDrivenResultServiceFactoryImpl();11TestCaseDataDrivenResultService service = factory.create();12}13}

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1import com.testsigma.service.TestCaseDataDrivenResultService;2public class DataDrivenTest{3public static void main(String[] args) throws Exception{4TestCaseDataDrivenResultService resultService = new TestCaseDataDrivenResultService();5resultService.create("Testcase Name", "Testcase Description", "Testcase Status", "Testcase Result", "Testcase Steps", "Testcase Data", "Testcase Data Value", "Testcase Data Status", "Testcase Data Result", "Testcase Data Steps", "Testcase Data Description", "Testcase Data Expected", "Testcase Data Actual", "Testcase Data Screenshot", "Testcase Data Attachment", "Testcase Data Execution Time", "Testcase Data Execution Start Time", "Testcase Data Execution End Time");6}7}8import com.testsigma.service.TestCaseDataDrivenResultService;9public class DataDrivenTest{10public static void main(String[] args) throws Exception{11TestCaseDataDrivenResultService resultService = new TestCaseDataDrivenResultService();12resultService.create("Testcase Name", "Testcase Description", "Testcase Status", "Testcase Result", "Testcase Steps", "Testcase Data", "Testcase Data Value", "Testcase Data Status", "Testcase Data Result", "Testcase Data Steps", "Testcase Data Description", "Testcase Data Expected", "Testcase Data Actual", "Testcase Data Screenshot", "Testcase Data Attachment", "Testcase Data Execution Time", "Testcase Data Execution Start Time", "Testcase Data Execution End Time", "Testcase Data Execution End Time");13}14}15import com.testsigma.service.TestCaseDataDrivenResultService;16public class DataDrivenTest{17public static void main(String[] args) throws Exception{18TestCaseDataDrivenResultService resultService = new TestCaseDataDrivenResultService();19resultService.create("Testcase Name", "Testcase Description", "Testcase Status", "Testcase Result", "Testcase Steps", "Testcase Data", "Testcase Data Value", "Testcase Data Status", "Testcase Data Result", "Testcase Data Steps", "Testcase Data Description", "Testcase Data Expected", "Testcase Data Actual", "Testcase Data Screenshot", "Testcase

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1import com.testsigma.service.TestCaseDataDrivenResultService;2public class DataDrivenTest{3public static void main(String[] args) throws Exception{4TestCaseDataDrivenResultService resultService = new TestCaseDataDrivenResultService();5resultService.create("Testcase Name", "Testcase Description", "Testcase Status", "Testcase Result", "Testcase Steps", "Testcase Data", "Testcase Data Value", "Testcase Data Status", "Testcase Data Result", "Testcase Data Steps", "Testcase Data Description", "Testcase Data Expected", "Testcase Data Actual", "Testcase Data Screenshot", "Testcase Data Attachment", "Testcase Data Execution Time", "Testcase Data Execution Start Time", "Testcase Data Execution End Time");6}7}8import com.testsigma.service.TestCaseDataDrivenResultService;9public class DataDrivenTest{10public static void main(String[] args) throws Exception{11TestCaseDataDrivenResultService resultService = new TestCaseDataDrivenResultService();12resultService.create("Testcase Name", "Testcase Description", "Testcase Status", "Testcase Result", "Testcase Steps", "Testcase Data", "Testcase Data Value", "Testcase Data Status", "Testcase Data Result", "Testcase Data Steps", "Testcase Data Description", "Testcase Data Expected", "Testcase Data Actual", "Testcase Data Screenshot", "Testcase Data Attachment", "Testcase Data Execution Time", "Testcase Data Execution Start Time", "Testcase Data Execution End Time", "Testcase Data Execution End Time");13}14}15import com.testsigma.service.TestCaseDataDrivenResultService;16public class DataDrivenTest{17public static void main(String[] args) throws Exception{

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1package com.testsigma.service;tpTe2imio.mpo igmm..ice.Te.Service;mpSot.st3isnn"esultId: " + testSuiteResultId);/t PTeo/p result4 String testStepResultId = testStepResultService.creattepPa(amTypstStep Name", "TestStep Description", testCaseResultId);5 System.out.println("TestStepResultIdDataDriven: " + ttepPasamStatuspResultId);6 TestCajRtavetia.LvstResultService = new TestCaseDataDrivenResultService();7 dataDrivenMa2, "testDataValue");8 System.out.println("TestCaseDataDriventCaseDataDrivenResultId);9 the feDataDrivonllowin.sedT:DataDrivenSs(avacCa;sDataDesvtnDownloavac.s.PAjSSigmaService.java10CaseDaaDrivn.seTCaseDaaDrivnDsipion CasDat DrivnRul 1d);11eDataDrivn.cteg thCaseDa aDrivfnllowinBug(mT: Case Daa Drivn 1 bug"12List<ava -cp .;C:\Users\testsitgp>wnloads\testsigma-service-t1psjar TesArrayList<tSigmaServicetp>13TStepp = new RsultStp();14teS.==Step(0);15So.p.setestsC.seDtDrRstStepN("TpstrCtse Dt.seDtinRutoeSriom1")t16DrivCsliDyDinRslSTCseDvnRultpTyee(tpTyp.MANUAL);17CDDRSd p.sCsTDataDetveaRulSpS=u(tSauPASS);18tSeep metf com.testsigma.service.StesDtscr/tteon("t in Tes tSig ma ep 1 decrpcgicn");

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1import com.testsigma.service.TestCaseDataDrivenResultSrevice2import com.testsiH.vhMapce.TestCaseResultService;3import com.testsiMaps4ervice.TestStepResultService;5import com.testsigma.service.TestSuiteResultService;6 Map<Stling, Objic >lparams =ss TeHaShMip<Scg,Objct>();7 param.p("tSuitId", 1);8 pam.p("SuitNm", "TtSie1");9 params.put("tId", 2);10 pam.p"public sNami", "ng[] arg1");11 pa-amt.pe ("hd stub, "12 peeamt.per("lStpId", 1);13 pSuami.pc ("tuitStspultSId", 1);14 param .pnwu"tteRStlptSerNam(", "TepDa1"15 params.pu ("tStrSt ptestVatu=", "testSttpeResVa.ue1");16 paeams."uTSutte St"p "TeValutId", t);17i pa;ams.u( SysSt.pout.VaeuuName", "teReSttpId: Valut1");18eataepaam.p("sSeupltSeValueExecutio Time", 1);19 params.pta("eRslSecpe =aV lueErroeMessagT", "TtCeResuDataValueErrorMeslage1");20 tecpa);m.put("tSpataVlueErrorSckTac", "TDataValueErrorStatkTrnc 1");21 tssu sepasaml.pte("iSytSs.poutaV.lueErrorImagt", "T("stCas: "aV lueErro Imagl1");22 I)ervice.crea(arams23 }24}25,ackag comt Sysmigmu.t("Scasts;26imeort compsltIsigm:. "svtcd.ervic;27imporc jev .uail.M p;28publsc clase 3 {29 p bdic reic void m(g[]rg) {30 Ma<Srg, ObjTcs>eDataDrivenResultService testCaseDataDrivenResultService = new TestCaseDataDrivenResultService();31 Map<String, String> dataDrivenMap = new HashMap<String, String>();32 dataDrivenMap.put("testData", "testDataValue");33 String testCaseDataDrivenResultId = testCaseDataDrivenResultService.create("TestCaseDataDriven Name", "TestCaseDataDriven Description", testCaseResultId, dataDrivenMap);34 System.out.println("TestCaseDataDrivenResultId: " + testCaseDataDrivenResultId);35}36}37javac -cp .;C:\Users\testsigma\Downloads\testsigma-service-1.0.0.jar TestSigmaService.java38java -cp .;C:\Users\testsigma\Downloads\testsigma-service-1.0.0.jar TestSigmaService

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1package com.testsigma.testcase;2import com.testsigma.service.TestCaseDataDrivenResultService;3import com.testsigma.service.TestCaseDataDrivenResult;4import com.testsigma.service.TestCaseDataDrivenResultType;5import com.testsigma.service.TestCaseDataDrivenResultStatus;6import com.testsigma.service.TestCaseDataDrivenResultStep;7import com.testsigma.service.TestCaseDataDrivenResultStepType;8import com.testsigma.service.TestCaseDataDrivenResultStepStatus;9import com.testsigma.service.TestCaseDataDrivenResultStepParam;10import com.testsigma.service.TestCaseDataDrivenResultStepParamType;11import com.testsigma.service.TestCaseDataDrivenResultStepParamStatus;12import java.util.ArrayList;13import java.util.List;14public class 2 {15public static void main(String[] args) {16TestCaseDataDrivenResult testCaseDataDrivenResult = new TestCaseDataDrivenResult();17testCaseDataDrivenResult.setTestCaseDataDrivenResultId(0);18testCaseDataDrivenResult.setTestCaseDataDrivenResultName("Test Case Data Driven Result 1");19testCaseDataDrivenResult.setTestCaseDataDrivenResultType(TestCaseDataDrivenResultType.MANUAL);20testCaseDataDrivenResult.setTestCaseDataDrivenResultStatus(TestCaseDataDrivenResultStatus.PASS);21testCaseDataDrivenResult.setTestCaseDataDrivenResultDescription("Test Case Data Driven Result 1 description");22testCaseDataDrivenResult.setTestCaseDataDrivenResultBug("Test Case Data Driven Result 1 bug");23List<TestCaseDataDrivenResultStep> testCaseDataDrivenResultSteps = new ArrayList<TestCaseDataDrivenResultStep>();24TestCaseDataDrivenResultStep testCaseDataDrivenResultStep = new TestCaseDataDrivenResultStep();25testCaseDataDrivenResultStep.setTestCaseDataDrivenResultStepId(0);26testCaseDataDrivenResultStep.setTestCaseDataDrivenResultStepName("Test Case Data Driven Result Step 1");27testCaseDataDrivenResultStep.setTestCaseDataDrivenResultStepType(TestCaseDataDrivenResultStepType.MANUAL);28testCaseDataDrivenResultStep.setTestCaseDataDrivenResultStepStatus(TestCaseDataDrivenResultStepStatus.PASS);29testCaseDataDrivenResultStep.setTestCaseDataDrivenResultStepDescription("Test Case Data Driven Result Step 1 description");

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testsigma automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful