Best Testsigma code snippet using com.testsigma.service.AgentExecutionService.processResultEntries
Source:AgentExecutionService.java
...98 try {99 beforeStart();100 populateResultEntries(true);101 saveRunTimeData();102 processResultEntries();103 afterStart();104 } catch (Exception e) {105 log.error(e.getMessage(), e);106 if (testPlanResult != null) {107 testPlanResult.setIsInProgress(Boolean.FALSE);108 testPlanResultService.update(testPlanResult);109 stopQueuedEnvironments(e.getMessage(), Boolean.FALSE);110 } else {111 if (this.isScheduledExecution() && !getIsReRun()) {112 populateResultEntries(false);113 stopQueuedEnvironments(e.getMessage(), Boolean.FALSE);114 }115 }116 throw e;117 }118 }119 // ################################################ BEFORE START ###################################################120 private void beforeStart() throws TestsigmaException {121 checkAlreadyRunning();122 }123 private void checkAlreadyRunning() throws TestsigmaException {124 checkIfAlreadyHasAnotherRun();125 checkIfAlreadyHasReRunParentId();126 }127 public void checkIfAlreadyHasReRunParentId() throws TestsigmaException {128 if (this.getParentTestPlanResultId() != null) {129 boolean ReRunParentIdAlreadyExsists = this.testPlanResultService.findByReRunParentId(this.getParentTestPlanResultId());130 if (ReRunParentIdAlreadyExsists) {131 log.info(String.format("Execution [%s] cannot be executed as its rerun parent id [%d] already exists", this.testPlan.getId(),132 testPlanResult.getReRunParentId()));133 throw new TestsigmaException(AutomatorMessages.RE_RUN_PARENT_ID_ALREADY_EXSISTS);134 }135 }136 }137 private void checkIfAlreadyHasAnotherRun() throws TestsigmaException {138 TestPlanResult testPlanResult = this.testPlanResultService.findByTestPlanIdAndStatusIsNot(this.testPlan.getId(),139 StatusConstant.STATUS_COMPLETED);140 if (testPlanResult != null) {141 log.info(String.format("Execution [%s] is already running and is in status %s ", this.testPlan.getId(),142 testPlanResult.getStatus()));143 throw new TestsigmaException(AutomatorMessages.EXECUTION_ALREADY_RUNNING);144 }145 }146 // ############################################ RESULT ENTRIES CREATION #############################################147 private void populateResultEntries(boolean setLastRunId) throws TestsigmaException {148 TestPlanResult testPlanResult = createTestPlanResult();149 populateLastRunId(testPlanResult, setLastRunId);150 this.setTestPlanResult(testPlanResult);151 populateEnvironmentResults(testPlanResult);152 }153 private void populateLastRunId(TestPlanResult testPlanResult, boolean setLastRunId) {154 AbstractTestPlan testPlan = this.getTestPlan();155 if (setLastRunId) {156 testPlan.setLastRunId(testPlanResult.getId());157 }158 if (testPlan instanceof TestPlan)159 this.setTestPlan(testPlanService.update((TestPlan) testPlan));160 }161 private void populateEnvironmentResults(TestPlanResult testPlanResult) throws TestsigmaException {162 List<TestDevice> testDevices =163 testDeviceService.findByTestPlanIdAndDisable(this.getTestPlan().getId(), Boolean.FALSE);164 for (TestDevice testDevice : testDevices) {165 log.info("Populating Environment result for environment:" + testDevice);166 TestDeviceResult testDeviceResult = createEnvironmentResult(testPlanResult, testDevice);167 if (testDeviceResult != null) {168 populateTestSuiteResults(testDeviceResult, testDevice);169 }170 }171 }172 private void populateTestSuiteResults(TestDeviceResult testDeviceResult, TestDevice testDevice)173 throws TestsigmaException {174 List<AbstractTestSuite> testSuites = this.testSuiteService.findAllByTestDeviceId(testDeviceResult.getTestDeviceId());175 for (AbstractTestSuite testSuite : testSuites) {176 log.info("Populate TestSuite result for suite:" + testSuite.getName());177 TestSuiteResult testSuiteResult = createTestSuiteResult(testSuite, testDeviceResult, testDevice);178 if (testSuiteResult != null) {179 testSuite.setLastRunId(testSuiteResult.getId());180 if (testPlan instanceof TestPlan)181 this.testSuiteService.updateSuite((TestSuite) testSuite);182 populateTestCaseResults(testSuite, testSuiteResult, testDeviceResult);183 }184 }185 }186 private void populateTestCaseResults(AbstractTestSuite testSuite, TestSuiteResult testSuiteResult,187 TestDeviceResult testDeviceResult) throws TestsigmaException {188 List<TestCase> testCases = this.testCaseService.findAllBySuiteId(testSuiteResult.getSuiteId());189 for (TestCase testCase : testCases) {190 TestCaseResult testCaseResult = createTestCaseResult(testSuite, testCase, testDeviceResult, testSuiteResult,191 null);192 if (testCaseResult != null && testPlan instanceof TestPlan) {193 testCase.setLastRunId(testCaseResult.getId());194 testCaseService.update(testCase);195 }196 }197 }198 protected void populateStepGroupTestStepResults(TestStep testStep, TestCaseResult testCaseResult,199 TestDeviceResult testDeviceResult,200 TestStepResult parentTestStepResult) {201 List<TestStep> testSteps = this.testStepService.findAllByTestCaseId(testStep.getStepGroupId());202 for (TestStep step : testSteps) {203 createTestStepResult(step, testDeviceResult, testCaseResult, parentTestStepResult);204 }205 }206 protected void createTestStepResult(TestStep testStep,207 TestDeviceResult testDeviceResult,208 TestCaseResult testCaseResult,209 TestStepResult parentTestStepResult) {210 log.info("Creating TestStepResult for:" + testStep);211 TestStepResult testStepResult = new TestStepResult();212 testStepResult.setEnvRunId(testDeviceResult.getId());213 testStepResult.setResult(ResultConstant.QUEUED);214 testStepResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);215 testStepResult.setStepId(testStep.getId());216 testStepResult.setTestCaseId(testCaseResult.getTestCaseId());217 testStepResult.setStepGroupId(testStep.getStepGroupId());218 testStepResult.setGroupResultId((parentTestStepResult != null) ? parentTestStepResult.getId() : null);219 testStepResult.setTestCaseResultId(testCaseResult.getId());220 testStepResult.setPriority(testStep.getPriority());221 StepDetails stepDetails = new StepDetails();222 stepDetails.setNaturalTextActionId(testStep.getNaturalTextActionId());223 stepDetails.setAction(testStep.getAction());224 stepDetails.setPriority(testStep.getPriority());225 stepDetails.setPreRequisiteStepId(testStep.getPreRequisiteStepId());226 stepDetails.setConditionType(testStep.getConditionType());227 stepDetails.setParentId(testStep.getParentId());228 stepDetails.setType(testStep.getType());229 stepDetails.setStepGroupId(testStep.getStepGroupId());230 stepDetails.setAction(testStep.getAction());231 stepDetails.setPosition(testStep.getPosition());232 stepDetails.setTestDataName(testCaseResult.getTestDataSetName());233 stepDetails.setDataMap(testStep.getDataMapBean());234 testStepResult.setStepDetails(stepDetails);235 if (parentTestStepResult != null) {236 testStepResult.setParentResultId(parentTestStepResult.getId());237 }238 testStepResult = this.testStepResultService.create(testStepResult);239 if (TestStepType.STEP_GROUP.equals(testStep.getType())) {240 populateStepGroupTestStepResults(testStep, testCaseResult, testDeviceResult, testStepResult);241 }242 }243 private void populateDataDrivenTestCaseResults(AbstractTestSuite testSuite,244 TestCase testCase,245 TestDeviceResult testDeviceResult,246 TestSuiteResult testSuiteResult,247 TestCaseResult parentTestCaseResult) throws TestsigmaException {248 log.info("Creating DatadrivenTestcaseResult for testcase:" + testCase.getName());249 TestData testData = testCase.getTestData();250 List<TestDataSet> testDataSets = testData.getData();251 int start = testCase.getTestDataStartIndex() != null ? testCase.getTestDataStartIndex() : 0;252 int end = testCase.getTestDataEndIndex() != null ? testCase.getTestDataEndIndex() : testDataSets.size() - 1;253 for (int i = start; i <= end && i < testDataSets.size(); i++) {254 testCase.setIsDataDriven(false);255 TestDataSet testDataSet = testDataSets.get(i);256 testCase.setIsDataDriven(false);257 testCase.setTestDataStartIndex(testDataSets.indexOf(testDataSet));258 TestCaseResult testCaseResult = createTestCaseResult(testSuite, testCase, testDeviceResult, testSuiteResult,259 parentTestCaseResult);260 if (testCaseResult != null) {261 createTestCaseDataDrivenResult(testDataSet, testCaseResult);262 }263 }264 testCase.setIsDataDriven(true);265 testCase.setTestDataStartIndex(start);266 }267 private TestCaseDataDrivenResult createTestCaseDataDrivenResult(TestDataSet testDataSet, TestCaseResult testCaseResult) {268 TestCaseDataDrivenResult testCaseDataDrivenResult = new TestCaseDataDrivenResult();269 testCaseDataDrivenResult.setEnvRunId(testCaseResult.getEnvironmentResultId());270 testCaseDataDrivenResult.setTestData(new ObjectMapperService().convertToJson(testDataSet));271 testCaseDataDrivenResult.setTestDataName(testDataSet.getName());272 testCaseDataDrivenResult.setTestCaseId(testCaseResult.getTestCaseId());273 testCaseDataDrivenResult.setTestCaseResultId(testCaseResult.getParentId());274 testCaseDataDrivenResult.setIterationResultId(testCaseResult.getId());275 return testCaseDataDrivenResultService.create(testCaseDataDrivenResult);276 }277 private TestCaseResult createTestCaseResult(AbstractTestSuite testSuite,278 TestCase testCase,279 TestDeviceResult testDeviceResult,280 TestSuiteResult testSuiteResult,281 TestCaseResult parentTestCaseResult) throws TestsigmaException {282 log.info("Creating TestcaseResult for:" + testCase);283 checkForDataDrivenIntegrity(testCase);284 TestCaseResult testCaseResult = new TestCaseResult();285 testCaseResult = setReRunParentId(testSuiteResult, testCase, testCaseResult, parentTestCaseResult);286 if (testCaseResult == null)287 return null;288 testCaseResult.setEnvironmentResultId(testDeviceResult.getId());289 testCaseResult.setTestPlanResultId(testDeviceResult.getTestPlanResultId());290 testCaseResult.setTestCaseId(testCase.getId());291 testCaseResult.setSuiteId(testSuiteResult.getSuiteId());292 testCaseResult.setSuiteResultId(testSuiteResult.getId());293 testCaseResult.setResult(ResultConstant.QUEUED);294 testCaseResult.setStatus(StatusConstant.STATUS_CREATED);295 testCaseResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);296 testCaseResult.setIsStepGroup(testCase.getIsStepGroup());297 if (parentTestCaseResult != null) {298 testCaseResult.setParentId(parentTestCaseResult.getId());299 }300 if (!testCase.getIsDataDriven()) {301 TestData testData = testCase.getTestData();302 if (testData != null) {303 TestDataSet testDataSet = testData.getData().get(testCase.getTestDataStartIndex());304 testCaseResult.setTestDataSetName(testDataSet.getName());305 if (parentTestCaseResult != null) {306 testCaseResult.setIteration(testDataSet.getName());307 }308 }309 }310 Optional<SuiteTestCaseMapping> suiteTestCaseMapping =311 suiteTestCaseMappingService.findFirstByTestSuiteAndTestCase(testSuite, testCase);312 TestCaseResult finalTestCaseResult = testCaseResult;313 suiteTestCaseMapping314 .ifPresent(suiteMapping -> finalTestCaseResult.setPosition(suiteMapping.getPosition().longValue()));315 if (suiteTestCaseMapping.isPresent()) {316 testCaseResult.setPosition(suiteTestCaseMapping.get().getPosition().longValue());317 }318 testCaseResult.setTestCaseTypeId(testCase.getType());319 testCaseResult.setTestCaseStatus(testCase.getStatus());320 testCaseResult.setPriorityId(testCase.getPriority());321 testCaseResult.setIsDataDriven(testCase.getIsDataDriven());322 testCaseResult.setTestDataId(testCase.getTestDataId());323 testCaseResult.setTestCaseDetails(testCaseDetails(testCaseResult, testCase));324 testCaseResult = this.testCaseResultService.create(testCaseResult);325 if (testCase.getIsDataDriven()) {326 populateDataDrivenTestCaseResults(testSuite, testCase, testDeviceResult, testSuiteResult, testCaseResult);327 }328 return testCaseResult;329 }330 private TestCaseResult setReRunParentId(TestSuiteResult testSuiteResult, TestCase testCase, TestCaseResult testCaseResult, TestCaseResult parentTestCaseResult) {331 if (getIsReRun() && (testSuiteResult.getReRunParentId() != null)) {332 TestCaseResult reRunParentTestCaseResult = testCaseResultsReRunList.stream().filter(333 er -> er.getTestCaseId().equals(testCase.getId()) && er.getIteration() == null).findAny().orElse(null);334 if (reRunParentTestCaseResult != null) {335 testCaseResult.setReRunParentId(reRunParentTestCaseResult.getId());336 } else {337 log.info("Test Case (" + testCase.getId() + ") is not eligible for Re-run. Skipping...");338 return null;339 }340 }341 if (!testCase.getIsDataDriven() && testCase.getTestData() != null && parentTestCaseResult != null) {342 TestData testData = testCase.getTestData();343 TestDataSet testDataSet = testData.getData().get(testCase.getTestDataStartIndex());344 if (getIsReRun() && (testSuiteResult.getReRunParentId() != null)) {345 TestCaseResult reRunParentTestCaseResult = testCaseResultsReRunList.stream().filter(346 er -> er.getTestCaseId().equals(testCase.getId()) && er.getIteration() != null && er.getIteration().equals(testDataSet.getName())).findAny().orElse(null);347 if (reRunParentTestCaseResult != null) {348 testCaseResult.setReRunParentId(reRunParentTestCaseResult.getId());349 } else {350 log.info("Test Case (" + testCase.getId() + ") is not eligible for Re-run. Skipping...");351 return null;352 }353 }354 }355 return testCaseResult;356 }357 private TestCaseDetails testCaseDetails(TestCaseResult testCaseResult, TestCase testCase) {358 TestCaseDetails testCaseDetails = new TestCaseDetails();359 testCaseDetails.setName(testCase.getName());360 testCaseDetails.setTestData(testCaseResult.getIteration());361 testCaseDetails.setTestDataSetName(testCaseResult.getTestDataSetName());362 testCaseDetails.setPrerequisite(testCase.getPreRequisite());363 return testCaseDetails;364 }365 private TestSuiteResult createTestSuiteResult(AbstractTestSuite testSuite, TestDeviceResult testDeviceResult,366 TestDevice testDevice) {367 TestSuiteResult testSuiteResult = new TestSuiteResult();368 if (getIsReRun() && (testDeviceResult.getReRunParentId() != null)) {369 TestSuiteResult parentTestSuiteResult = testSuiteResultsReRunList.stream().filter(370 er -> er.getSuiteId().equals(testSuite.getId())).findAny().orElse(null);371 if (parentTestSuiteResult != null) {372 testSuiteResult.setReRunParentId(parentTestSuiteResult.getId());373 fetchTestCaseResultsReRunList(parentTestSuiteResult.getId());374 } else {375 log.info("Test Suite (" + testSuite.getId() + ") is not eligible for Re-run. Skipping...");376 return null;377 }378 }379 testSuiteResult.setEnvironmentResultId(testDeviceResult.getId());380 testSuiteResult.setResult(ResultConstant.QUEUED);381 testSuiteResult.setStatus(StatusConstant.STATUS_CREATED);382 testSuiteResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);383 testSuiteResult.setSuiteId(testSuite.getId());384 testSuiteResult.setStartTime(new Timestamp(System.currentTimeMillis()));385 testSuiteResult.setTestPlanResultId(testDeviceResult.getTestPlanResultId());386 Optional<TestDeviceSuite> environmentSuiteMapping =387 testDeviceSuiteService.findFirstByTestDeviceAndTestSuite(testDevice, testSuite);388 environmentSuiteMapping389 .ifPresent(suiteMapping -> testSuiteResult.setPosition(suiteMapping.getPosition().longValue()));390 TestSuiteResultSuiteDetails suiteDetails = new TestSuiteResultSuiteDetails();391 suiteDetails.setName(testSuite.getName());392 suiteDetails.setPreRequisite(testSuite.getPreRequisite());393 testSuiteResult.setSuiteDetails(suiteDetails);394 return this.testSuiteResultService.create(testSuiteResult);395 }396 private TestDeviceResult createEnvironmentResult(TestPlanResult testPlanResult,397 TestDevice testDevice) throws TestsigmaException {398 TestDeviceResult testDeviceResult = new TestDeviceResult();399 if (getIsReRun() && (testPlanResult.getReRunParentId() != null)) {400 TestDeviceResult parentTestDeviceResult = testDeviceResultsReRunList.stream().filter(401 er -> er.getTestDeviceId().equals(testDevice.getId())).findAny().orElse(null);402 if (parentTestDeviceResult != null) {403 testDeviceResult.setReRunParentId(parentTestDeviceResult.getId());404 fetchTestSuitesResultsReRunList(parentTestDeviceResult.getId());405 } else {406 log.info("Execution Environment (" + testDevice.getId() + ") is not eligible for Re-run. Skipping...");407 return null;408 }409 }410 testDeviceResult.setTestPlanResultId(testPlanResult.getId());411 testDeviceResult.setResult(ResultConstant.QUEUED);412 testDeviceResult.setStatus(StatusConstant.STATUS_CREATED);413 testDeviceResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);414 testDeviceResult.setStartTime(new Timestamp(System.currentTimeMillis()));415 testDeviceResult.setTestDeviceId(testDevice.getId());416 testDeviceResult.setAppUploadVersionId(getUploadVersionId(testDevice));417 testDeviceResult.setTestDeviceSettings(getExecutionTestDeviceSettings(testDevice));418 testDeviceResult = testDeviceResultService.create(testDeviceResult);419 testDeviceResult.setTestDevice(testDevice);420 return testDeviceResult;421 }422 private Long getUploadVersionId(TestDevice testDevice) throws ResourceNotFoundException {423 Long uploadVersionId = getUploadVersionIdFromRuntime(testDevice.getId());424 if (uploadVersionId != null) {425 log.debug("Got uploadVersionId from runTimeData ", uploadVersionId, testDevice.getId());426 uploadVersionId = this.uploadVersionService.find(uploadVersionId).getId();427 } else {428 uploadVersionId = testDevice.getAppUploadVersionId();429 if (uploadVersionId == null && testDevice.getAppUploadId() != null)430 uploadVersionId = uploadService.find(testDevice.getAppUploadId()).getLatestVersionId();431 }432 return uploadVersionId;433 }434 private Long getUploadVersionIdFromRuntime(Long environmentId) {435 log.debug("Fetching uploadVersionId from runTimeData for EnvironmentId::"+environmentId);436 if (getRunTimeData() != null) {437 JSONObject uploadVersions = getRunTimeData().optJSONObject("uploadVersions");438 log.debug("Fetching uploadVersionId from runTimeData for uploadVersions::", uploadVersions);439 if (uploadVersions != null) {440 log.debug("Fetching uploadVersionId from runTimeData for uploadVersions::", uploadVersions);441 return uploadVersions.optLong(environmentId+"");442 }443 }444 return null;445 }446 private TestPlanResult createTestPlanResult() throws ResourceNotFoundException {447 TestPlanResult testPlanResult = new TestPlanResult();448 if (getIsReRun()) {449 if (this.getParentTestPlanResultId() != null) {450 testPlanResult.setReRunParentId(this.getParentTestPlanResultId());451 } else {452 testPlanResult.setReRunParentId(testPlan.getLastRunId());453 }454 testPlanResult.setReRunType(getReRunType());455 fetchEnvironmentResultsReRunList();456 }457 if ((this.getRunTimeData() != null) && (this.getRunTimeData().has("build_number"))) {458 testPlanResult.setBuildNo(this.getRunTimeData().getString("build_number"));459 }460 testPlanResult.setResult(ResultConstant.QUEUED);461 testPlanResult.setStatus(StatusConstant.STATUS_CREATED);462 testPlanResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);463 testPlanResult.setTestPlanId(this.getTestPlan().getId());464 testPlanResult.setStartTime(new Timestamp(System.currentTimeMillis()));465 testPlanResult.setTriggeredType(this.triggeredType);466 testPlanResult.setScheduleId(this.scheduleId);467 TestPlanDetails testPlanDetails = new TestPlanDetails();468 testPlanDetails.setElementTimeout(testPlan.getElementTimeOut());469 testPlanDetails.setPageTimeout(testPlan.getPageTimeOut());470 testPlanDetails.setOnAbortedAction(testPlan.getOnAbortedAction());471 testPlanDetails.setRecoveryAction(testPlan.getRecoveryAction());472 testPlanDetails.setGroupPrerequisiteFail(testPlan.getOnSuitePreRequisiteFail());473 testPlanDetails.setTestCasePrerequisiteFail(testPlan.getOnTestcasePreRequisiteFail());474 testPlanDetails.setTestStepPrerequisiteFail(testPlan.getOnStepPreRequisiteFail());475 testPlanDetails.setScreenshotOption(testPlan.getScreenshot());476 if (this.getTestPlan().getEnvironmentId() != null) {477 Environment environment = environmentService.find(this.getTestPlan().getEnvironmentId());478 testPlanResult.setEnvironmentId(environment.getId());479 testPlanDetails.setEnvironmentParamName(environment.getName());480 }481 testPlanResult.setTestPlanDetails(testPlanDetails);482 return testPlanResultService.create(testPlanResult);483 }484 private void checkForDataDrivenIntegrity(TestCase testCase) throws TestsigmaException {485 TestData testData = testCase.getTestData();486 if (testData == null && testCase.getIsDataDriven()) {487 String errorMessage = com.testsigma.constants.MessageConstants.getMessage(488 MessageConstants.MSG_UNKNOWN_TEST_DATA_DATA_DRIVEN_CASE,489 testCase.getName()490 );491 throw new TestsigmaException(errorMessage);492 }493 }494 private TestDeviceSettings getExecutionTestDeviceSettings(TestDevice testDevice) throws TestsigmaException {495 TestDeviceSettings settings = new TestDeviceSettings();496 TestPlanLabType exeLabType = this.getTestPlan().getTestPlanLabType();497 if (testDevice.getPlatformDeviceId() != null) {498 settings.setDeviceName(platformsService.getPlatformDevice(testDevice.getPlatformDeviceId(), exeLabType).getName());499 }500 if (testDevice.getPlatformBrowserVersionId() != null) {501 PlatformBrowserVersion platformBrowserVersion = platformsService.getPlatformBrowserVersion(testDevice.getPlatformBrowserVersionId(), exeLabType);502 settings.setBrowserVersion(platformBrowserVersion.getVersion());503 settings.setBrowser(platformBrowserVersion.getName().name());504 }505 if (testDevice.getPlatformScreenResolutionId() != null) {506 settings.setResolution(platformsService.getPlatformScreenResolution(testDevice.getPlatformScreenResolutionId(), exeLabType).getResolution());507 }508 if (testDevice.getPlatformOsVersionId() != null) {509 PlatformOsVersion platformOsVersion = platformsService.getPlatformOsVersion(testDevice.getPlatformOsVersionId(), exeLabType);510 settings.setPlatform(platformOsVersion.getPlatform());511 settings.setOsVersion(platformOsVersion.getPlatformVersion());512 }513 if (exeLabType == TestPlanLabType.Hybrid) {514 settings.setBrowser(testDevice.getBrowser());515 }516 settings.setAppActivity(testDevice.getAppActivity());517 settings.setAppPackage(testDevice.getAppPackage());518 settings.setAppPathType(testDevice.getAppPathType());519 settings.setAppUrl(testDevice.getAppUrl());520 settings.setAppUploadId(testDevice.getAppUploadId());521 settings.setTitle(testDevice.getTitle());522 settings.setCreateSessionAtCaseLevel(testDevice.getCreateSessionAtCaseLevel());523 return settings;524 }525 private Boolean isScheduledExecution() {526 return this.triggeredType.equals(ExecutionTriggeredType.SCHEDULED);527 }528 // ############################################ RESULT ENTRIES PROCESSING ###########################################529 private void processResultEntries() throws Exception {530 if (canPushToLabAgent()) {531 processResultEntriesForLabAgent();532 } else if (canPushToHybridAgent()) {533 processResultEntriesForHybridAgent();534 }535 }536 private Boolean canPushToLabAgent() throws IntegrationNotFoundException {537 return !this.testPlan.getTestPlanLabType().equals(TestPlanLabType.Hybrid) && this.integrationsService.findByApplication(Integration.TestsigmaLab) != null;538 }539 private Boolean canPushToHybridAgent() {540 return this.testPlan.getTestPlanLabType().equals(TestPlanLabType.Hybrid);541 }542 private void processResultEntriesForLabAgent() throws Exception {543 List<TestDeviceResult> testDeviceResults = testDeviceResultService.findAllByTestPlanResultId(544 this.testPlanResult.getId());545 processResultEntries(testDeviceResults, StatusConstant.STATUS_CREATED);546 }547 private void processResultEntriesForHybridAgent() throws Exception {548 List<TestDeviceResult> testDeviceResults = testDeviceResultService.findAllByTestPlanResultId(549 this.testPlanResult.getId());550 processResultEntries(testDeviceResults, StatusConstant.STATUS_CREATED);551 }552 public void processResultEntries(List<TestDeviceResult> testDeviceResults, StatusConstant inStatus)553 throws Exception {554 for (TestDeviceResult testDeviceResult : testDeviceResults) {555 if (testDeviceResult.getTestDevice().getAgent() == null && this.getTestPlan().getTestPlanLabType().isHybrid()) {556 testDeviceResultService.markEnvironmentResultAsFailed(testDeviceResult, AutomatorMessages.AGENT_HAS_BEEN_REMOVED, StatusConstant.STATUS_CREATED);557 } else if (this.getTestPlan().getTestPlanLabType().isHybrid() && !agentService.isAgentActive(testDeviceResult.getTestDevice().getAgentId())) {558 testDeviceResultService.markEnvironmentResultAsFailed(testDeviceResult,559 AutomatorMessages.AGENT_INACTIVE, StatusConstant.STATUS_CREATED);560 } else if(this.getTestPlan().getTestPlanLabType().isHybrid() && testDeviceResult.getTestDevice().getDeviceId()!=null &&561 agentService.isAgentActive(testDeviceResult.getTestDevice().getAgentId()) && !agentDeviceService.isDeviceOnline(testDeviceResult.getTestDevice().getDeviceId())){562 testDeviceResultService.markEnvironmentResultAsFailed(testDeviceResult,563 agentDeviceService.find(testDeviceResult.getTestDevice().getDeviceId()).getName()+ " "+AutomatorMessages.DEVICE_NOT_ONLINE, StatusConstant.STATUS_CREATED);564 }565 else {566 processEnvironmentResult(testDeviceResult, inStatus);...
Source:TestDeviceResultService.java
...288 try {289 AgentExecutionService agentExecutionService = agentExecutionServiceObjectFactory.getObject();290 agentExecutionService.setTestPlan(testPlan);291 agentExecutionService.setTestPlanResult(testPlanResult);292 agentExecutionService.processResultEntries(envResults, StatusConstant.STATUS_QUEUED);293 } catch (Exception e) {294 log.error(e.getMessage(), e);295 String message = " Error while sending pending test plans for test plan result - " + testPlanResult.getId();296 log.error(message);297 throw e;298 }299 }300 } catch (Exception e) {301 log.error(e.getMessage(), e);302 String environmentIds = testDeviceResults.stream().map(er -> er.getId().toString())303 .collect(Collectors.joining(","));304 String message = "Error while processing environment results [" + environmentIds + "]";305 log.error(message);306 }...
processResultEntries
Using AI Code Generation
1package com.testsigma.service;2import java.io.File;3import java.io.FileInputStream;4import java.io.FileNotFoundException;5import java.io.IOException;6import java.io.InputStream;7import java.util.ArrayList;8import java.util.List;9import org.apache.commons.io.IOUtils;10public class AgentExecutionService {11 public static void main(String[] args) {12 AgentExecutionService agentExecutionService = new AgentExecutionService();13 agentExecutionService.processResultEntries();14 }15 public void processResultEntries() {16 List<String> list = new ArrayList<String>();17 list.add("1");18 list.add("2");19 list.add("3");20 list.add("4");21 list.add("5");22 list.add("6");23 list.add("7");24 list.add("8");25 list.add("9");26 list.add("10");27 list.add("11");28 list.add("12");29 list.add("13");30 list.add("14");31 list.add("15");32 list.add("16");33 list.add("17");34 list.add("18");35 list.add("19");36 list.add("20");37 list.add("21");38 list.add("22");39 list.add("23");40 list.add("24");41 list.add("25");42 list.add("26");43 list.add("27");44 list.add("28");45 list.add("29");46 list.add("30");47 list.add("31");48 list.add("32");49 list.add("33");50 list.add("34");51 list.add("35");52 list.add("36");53 list.add("37");54 list.add("38");55 list.add("39");56 list.add("40");57 list.add("41");58 list.add("42");59 list.add("43");60 list.add("44");61 list.add("45");62 list.add("46");63 list.add("47");64 list.add("48");65 list.add("49");66 list.add("50");67 list.add("51");68 list.add("52");69 list.add("53");70 list.add("54");71 list.add("55");72 list.add("56");73 list.add("57");74 list.add("58");75 list.add("59");76 list.add("60");77 list.add("61");78 list.add("62");79 list.add("63");80 list.add("64");81 list.add("65");
processResultEntries
Using AI Code Generation
1package com.testsigma.service;2import java.io.IOException;3import java.util.ArrayList;4import java.util.HashMap;5import java.util.List;6import java.util.Map;7import org.apache.http.client.ClientProtocolException;8import org.json.JSONException;9import org.json.JSONObject;10import com.testsigma.service.AgentExecutionService;11import com.testsigma.service.ResultEntry;12public class ResultEntryTest {13public static void main(String[] args) throws ClientProtocolException, IOException, JSONException {14List<ResultEntry> resultEntries = new ArrayList<ResultEntry>();15ResultEntry resultEntry = new ResultEntry();16resultEntry.setTestcaseId("12345");17resultEntry.setExecutionId("12345");18resultEntry.setTestcaseName("Testcase1");19resultEntry.setTestcaseDescription("Testcase1 description");20resultEntry.setExecutionStatus("PASS");21resultEntry.setExecutionTime("10");22resultEntry.setExecutionMessage("Testcase1 executed successfully");23resultEntry.setExecutionLog("This is the execution log for Testcase1");24resultEntry.setExecutionScreenshot("screenshot.png");25resultEntry.setExecutionVideo("video.mp4");26resultEntries.add(resultEntry);27Map<String, String> customFields = new HashMap<String, String>();28customFields.put("customField1", "customValue1");29customFields.put("customField2", "customValue2");30resultEntry.setCustomFields(customFields);31JSONObject response = agentExecutionService.processResultEntries(resultEntries);32System.out.println(response);33}34}35package com.testsigma.service;36import java.io.IOException;37import java.util.HashMap;38import java.util.Map;39import org.apache.http.client.ClientProtocolException;40import org.json.JSONException;41import org.json.JSONObject;42import com.testsigma.service.AgentExecutionService;43import com.testsigma.service.ResultEntry;44public class ResultEntryTest {45public static void main(String[] args) throws ClientProtocolException, IOException, JSONException {46ResultEntry resultEntry = new ResultEntry();47resultEntry.setTestcaseId("12345");48resultEntry.setExecutionId("12345");49resultEntry.setTestcaseName("Testcase1");
processResultEntries
Using AI Code Generation
1package com.testsigma.service;2import java.util.ArrayList;3import java.util.HashMap;4import java.util.List;5import java.util.Map;6import com.testsigma.sdk.AgentExecutionService;7import com.testsigma.sdk.ResultEntry;8public class AgentExecutionServiceTest {9 public static void main(String[] args) {10 List<ResultEntry> resultEntries = new ArrayList<ResultEntry>();11 ResultEntry resultEntry = new ResultEntry();12 resultEntry.setTestName("testName");13 resultEntry.setTestSuiteName("testSuiteName");14 resultEntry.setTestStatus("testStatus");15 resultEntry.setTestStartTime("testStartTime");16 resultEntry.setTestEndTime("testEndTime");17 resultEntry.setTestExecutionTime("testExecutionTime");18 resultEntry.setTestBrowser("testBrowser");19 resultEntry.setTestPlatform("testPlatform");20 resultEntry.setTestOs("testOs");21 resultEntry.setTestOsVersion("testOsVersion");22 resultEntry.setTestDevice("testDevice");23 resultEntry.setTestDeviceVersion("testDeviceVersion");24 resultEntry.setTestDeviceResolution("testDeviceResolution");25 resultEntry.setTestDeviceOrientation("testDeviceOrientation");26 resultEntry.setTestDeviceBrowser("testDeviceBrowser");27 resultEntry.setTestDeviceBrowserVersion("testDeviceBrowserVersion");28 resultEntry.setTestDeviceBrowserResolution("testDeviceBrowserResolution");29 resultEntry.setTestDeviceBrowserOrientation("testDeviceBrowserOrientation");30 resultEntry.setTestDeviceLocation("testDeviceLocation");31 resultEntry.setTestDeviceLocationLatitude("testDeviceLocationLatitude");32 resultEntry.setTestDeviceLocationLongitude("testDeviceLocationLongitude");33 resultEntry.setTestDeviceLocationAccuracy("testDeviceLocationAccuracy");34 resultEntry.setTestDeviceLocationAltitude("testDeviceLocationAltitude");35 resultEntry.setTestDeviceLocationAltitudeAccuracy("testDeviceLocationAltitudeAccuracy");36 resultEntry.setTestDeviceLocationHeading("testDeviceLocationHeading");37 resultEntry.setTestDeviceLocationSpeed("testDeviceLocationSpeed");38 resultEntry.setTestDeviceLocationTimestamp("testDeviceLocationTimestamp");39 resultEntry.setTestDeviceNetwork("testDeviceNetwork");40 resultEntry.setTestDeviceNetworkType("testDeviceNetworkType");41 resultEntry.setTestDeviceNetworkStrength("testDeviceNetworkStrength");42 resultEntry.setTestDeviceNetworkSignalStrength("testDeviceNetworkSignalStrength");43 resultEntry.setTestDeviceNetworkOperator("testDeviceNetworkOperator");
processResultEntries
Using AI Code Generation
1package com.testsigma.service;2import java.util.HashMap;3import java.util.Map;4import com.testsigma.service.AgentExecutionService;5import com.testsigma.service.AgentExecutionServiceProxy;6import com.testsigma.service.ExecutionResult;7import com.testsigma.service.ExecutionResultEntry;8import com.testsigma.service.ExecutionResultEntryType;9import com.testsigma.service.ExecutionResultEntryType;10import co
processResultEntries
Using AI Code Generation
1import java.util.Map;2import java.util.HashMap;3import java.util.List;4import java.util.ArrayList;5import java.util.Date;6import java.util.Properties;7import com.testsigma.service.AgentExecutionService;8import com.testsigma.service.AgentExecutionServiceService;9public class 2 {10 public static void main(String[] args) {11 try {12 AgentExecutionServiceService service = new AgentExecutionServiceService();13 AgentExecutionService agentExecutionService = service.getAgentExecutionServicePort();14 Map<String, String> resultEntries = new HashMap<String, String>();15 resultEntries.put("key1", "value1");16 resultEntries.put("key2", "value2");17 resultEntries.put("key3", "value3");18 agentExecutionService.processResultEntries(resultEntries);19 } catch (Exception ex) {20 ex.printStackTrace();21 }22 }23}
processResultEntries
Using AI Code Generation
1package com.testsigma.service;2import com.testsigma.service.AgentExecutionService;3import com.testsigma.service.AgentExecutionServiceService;4import com.testsigma.service.ResultEntry;5import java.util.List;6public class TestSigmaClient {7public static void main(String[] args) {8AgentExecutionServiceService service = new AgentExecutionServiceService();9AgentExecutionService port = service.getAgentExecutionServicePort();10List<ResultEntry> resultEntries = port.processResultEntries(null);11System.out.println("Result Entries: " + resultEntries.size());12}13}14package com.testsigma.service;15import com.testsigma.service.AgentExecutionService;16import com.testsigma.service.AgentExecutionServiceService;17import com.testsigma.service.ResultEntry;18import java.util.List;19public class TestSigmaClient {20public static void main(String[] args) {21AgentExecutionServiceService service = new AgentExecutionServiceService();22AgentExecutionService port = service.getAgentExecutionServicePort();23List<ResultEntry> resultEntries = port.processResultEntries(null);24System.out.println("Result Entries: " + resultEntries.size());25}26}27package com.testsigma.service;28import com.testsigma.service.AgentExecutionService;29import com.testsigma.service.AgentExecutionServiceService;30import com.testsigma.service.ResultEntry;31import java.util.List;32public class TestSigmaClient {33public static void main(String[] args) {34AgentExecutionServiceService service = new AgentExecutionServiceService();35AgentExecutionService port = service.getAgentExecutionServicePort();36List<ResultEntry> resultEntries = port.processResultEntries(null);37System.out.println("Result Entries: " + resultEntries.size());38}39}40package com.testsigma.service;41import com.testsigma.service.AgentExecutionService;42import com.testsigma.service.AgentExecutionServiceService;43import com.testsigma.service.ResultEntry;44import java.util.List;45public class TestSigmaClient {46public static void main(String[] args) {47AgentExecutionServiceService service = new AgentExecutionServiceService();48AgentExecutionService port = service.getAgentExecutionServicePort();49List<ResultEntry> resultEntries = port.processResultEntries(null);50System.out.println("Result Entries: " + resultEntries.size());51}52}
processResultEntries
Using AI Code Generation
1package com.testsigma.service;2import java.util.ArrayList;3import java.util.List;4import java.util.Map;5import com.testsigma.service.model.AgentExecutionResultEntry;6import com.testsigma.service.model.AgentExecutionResultEntry.Status;7import com.testsigma.service.model.AgentExecutionResultEntry.Type;8import com.testsigma.service.model.AgentExecutionResultEntryGroup;9import com.testsigma.service.model.AgentExecutionResultEntryGroup.GroupType;10import com.testsigma.service.model.AgentExecutionResultEntryGroup.ResultType;11import com.testsigma.service.model.AgentExecutionResultEntryGroup.StatusType;12import com.testsigma.service.model.AgentExecutionResultEntryGroup.TestStatus;13import com.testsigma.service.model.AgentExecutionResultEntryGroup.TestType;14import com.testsigma.service.model.AgentExecutionResultEntryGroup.TypeType;15import com.testsigma.service.model.AgentExecutionResultEntryGroup.WarningType;16public class Test {17public static void main(String[] args) {18AgentExecutionService service = new AgentExecutionService();19List<AgentExecutionResultEntryGroup> result = new ArrayList<AgentExecutionResultEntryGroup>();20AgentExecutionResultEntryGroup group1 = new AgentExecutionResultEntryGroup();21group1.setGroupType(GroupType.TEST);22group1.setTestType(TestType.FUNCTIONAL);23group1.setTestStatus(TestStatus.PASS);24group1.setTestName("Test1");25group1.setType(TypeType.TEST);26group1.setResult(ResultType.PASS);27group1.setStatus(StatusType.PASS);28group1.setWarning(WarningType.NONE);29group1.setTestDuration(100);30group1.setTestStartTime(1000);31group1.setTestEndTime(1100);32group1.setTestDescription("Test1 description");33group1.setTestTags("Test1 tags");34group1.setTestPriority("Test1 priority");35group1.setTestRequirement("Test1 requirement");36group1.setTestFeature("Test1 feature");37group1.setTestId("Test1 id");38group1.setTestStatusMessage("Test1 status message");39group1.setTestWarningMessage("Test1 warning message");40group1.setTestErrorMessage("Test1 error message");41AgentExecutionResultEntryGroup group2 = new AgentExecutionResultEntryGroup();42group2.setGroupType(GroupType.TEST);43group2.setTestType(TestType.FUNCTIONAL);44group2.setTestStatus(TestStatus.FAIL);45group2.setTestName("Test2");46group2.setType(TypeType.TEST);47group2.setResult(ResultType.FAIL);48group2.setStatus(StatusType.FAIL);49group2.setWarning(WarningType.NONE);
processResultEntries
Using AI Code Generation
1package com.testsigma.service;2import java.util.ArrayList;3import java.util.List;4import com.testsigma.service.model.ExecutionResult;5public class AgentExecutionService {6 public void processResultEntries(List<ExecutionResult> executionResults) {7 System.out.println("Execution results:");8 for (ExecutionResult executionResult : executionResults) {9 System.out.println("Execution result: " + executionResult);10 }11 }12}13package com.testsigma.service;14import java.util.ArrayList;15import java.util.List;16import com.testsigma.service.model.ExecutionResult;17public class AgentExecutionService {18 public void processResultEntries(List<ExecutionResult> executionResults) {19 System.out.println("Execution results:");20 for (ExecutionResult executionResult : executionResults) {21 System.out.println("Execution result: " + executionResult);22 }23 }24}25package com.testsigma.service;26import java.util.ArrayList;27import java.util.List;28import com.testsigma.service.model.ExecutionResult;29public class AgentExecutionService {30 public void processResultEntries(List<ExecutionResult> executionResults) {31 System.out.println("Execution results:");32 for (ExecutionResult executionResult : executionResults) {33 System.out.println("Execution result: " + executionResult);34 }35 }36}37package com.testsigma.service;38import java.util.ArrayList;39import java.util.List;40import com.testsigma.service.model.ExecutionResult;41public class AgentExecutionService {42 public void processResultEntries(List<ExecutionResult> executionResults) {43 System.out.println("Execution results:");44 for (ExecutionResult executionResult : executionResults) {45 System.out.println("Execution result: " + executionResult);46 }47 }48}49package com.testsigma.service;50import java.util.ArrayList;51import java.util.List;52import com.testsigma.service.model.ExecutionResult;53public class AgentExecutionService {54 public void processResultEntries(List<ExecutionResult> executionResults) {55 System.out.println("Execution results:");56 for (ExecutionResult executionResult :
processResultEntries
Using AI Code Generation
1package com.testsigma.service;2import java.util.ArrayList;3import java.util.List;4import com.testsigma.service.AgentExecutionService;5import com.testsigma.service.AgentExecutionServiceService;6import com.testsigma.service.ExecutionResultEntry;7import com.testsigma.service.ExecutionResultEntryList;8import com.testsigma.service.ExecutionResultEntryListResponse;9public class AgentExecutionServiceClient {10public static void main(String[] args) throws Exception {11AgentExecutionServiceService agentExecutionServiceService = new AgentExecutionServiceService();12AgentExecutionService agentExecutionService = agentExecutionServiceService.getAgentExecutionServicePort();13ExecutionResultEntryListResponse executionResultEntryListResponse = agentExecutionService.processResultEntries("testSuiteName");14ExecutionResultEntryList executionResultEntryList = executionResultEntryListResponse.getExecutionResultEntryList();15List<ExecutionResultEntry> executionResultEntry = executionResultEntryList.getExecutionResultEntry();16for(ExecutionResultEntry executionResultEntry1:executionResultEntry){17System.out.println("Test case name: "+executionResultEntry1.getTestCaseName());18System.out.println("Test case status: "+executionResultEntry1.getTestCaseStatus());19System.out.println("Test case execution start time: "+executionResultEntry1.getTestCaseStartTime());20System.out.println("Test case execution end time: "+executionResultEntry1.getTestCaseEndTime());21System.out.println("Test case execution time: "+executionResultEntry1.getTestCaseExecutionTime());22System.out.println("Test case execution error message: "+executionResultEntry1.getTestCaseErrorMessage());23System.out.println("Test case execution error stack trace: "+executionResultEntry1.getTestCaseErrorStac
processResultEntries
Using AI Code Generation
1import java.util.List;2import java.util.Map;3import java.util.Set;4import com.testsigma.service.AgentExecutionService;5import com.testsigma.service.AgentExecutionServiceFactory;6import com.testsigma.service.AgentExecutionServiceFactoryException;7import com.testsigma.service.ExecutionResultEntry;8import com.testsigma.service.ExecutionResultEntryStatus;9import com.testsigma.service.ExecutionResultEntryType;10import com.testsigma.service.ExecutionResultSummary;11import com.testsigma.service.ExecutionResultSummaryStatus;12import com.testsigma.service.ExecutionResultSummaryType;13import com.testsigma.service.TestExecutionService;14public class 2 {15 public static void main(String[] args) {16 TestExecutionService testExecutionService = TestExecutionService.getInstance();17 AgentExecutionServiceFactory agentExecutionServiceFactory = testExecutionService.getAgentExecutionServiceFactory();18 AgentExecutionService agentExecutionService = null;19 try {20 } catch (AgentExecutionServiceFactoryException e) {21 e.printStackTrace();22 }23 String testRunId = "1";24 List<ExecutionResultEntry> executionResultEntryList = agentExecutionService.processResultEntries(testRunId);25 for (ExecutionResultEntry executionResultEntry : executionResultEntryList) {26 System.out.println("Test Case Name = " + executionResultEntry.getName());27 System.out.println("Test Case Status = " + executionResultEntry.getResultStatus());28 System.out.println("Test Case Type = " + executionResultEntry.getResultType());29 System.out.println("Test Case Duration = " + executionResultEntry.getDuration());30 System.out.println("Test Case Start Time = " + executionResultEntry.getStartTime());31 System.out.println("Test Case End Time = " + executionResultEntry.getEndTime());32 System.out.println("Test Case Labels = " + executionResultEntry.getLabels());33 System.out.println("Test Case Parent = " + execution
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!!