How to use fetchEnvironmentResultsReRunList method of com.testsigma.service.AgentExecutionService class

Best Testsigma code snippet using com.testsigma.service.AgentExecutionService.fetchEnvironmentResultsReRunList

Source:AgentExecutionService.java Github

copy

Full Screen

...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);567 }568 }569 testDeviceResultService.updateExecutionConsolidatedResults(this.testPlanResult.getId(),570 Boolean.TRUE);571 }572 public void processEnvironmentResult(TestDeviceResult testDeviceResult, StatusConstant inStatus) throws Exception {573 testDeviceResultService.markEnvironmentResultAsInPreFlight(testDeviceResult, inStatus);574 if (!this.getTestPlan().getTestPlanLabType().isHybrid()) {575 EnvironmentEntityDTO environmentEntityDTO = loadEnvironment(testDeviceResult,576 StatusConstant.STATUS_PRE_FLIGHT);577 try {578 pushEnvironmentToLab(testDeviceResult, environmentEntityDTO);579 } catch (Exception e) {580 log.error(e.getMessage(), e);581 testDeviceResultService.markEnvironmentResultAsFailed(testDeviceResult, e.getMessage(),582 StatusConstant.STATUS_PRE_FLIGHT);583 }584 }585 }586 public void processEnvironmentResultInParallel(TestDeviceResult testDeviceResult, StatusConstant inStatus) throws Exception {587 List<TestSuiteResult> testSuiteResults = this.testSuiteResultService.findPendingTestSuiteResults(588 testDeviceResult, inStatus);589 testDeviceResult.setSuiteResults(testSuiteResults);590 for (TestSuiteResult testSuiteResult : testSuiteResults) {591 testSuiteResultService.markTestSuiteResultAsInFlight(testSuiteResult, inStatus);592 if (!this.getTestPlan().getTestPlanLabType().isHybrid()) {593 TestSuiteEntityDTO testSuiteEntity = this.testSuiteResultMapper.map(testSuiteResult);594 testSuiteEntity.setTestCases(loadTestCases(testSuiteResult, StatusConstant.STATUS_PRE_FLIGHT));595 List<TestSuiteEntityDTO> testSuiteEntityDTOS = new ArrayList<>();596 testSuiteEntityDTOS.add(testSuiteEntity);597 EnvironmentEntityDTO environmentEntityDTO = loadEnvironmentDetails(testDeviceResult);598 environmentEntityDTO.setTestSuites(testSuiteEntityDTOS);599 try {600 pushEnvironmentToLab(testDeviceResult, environmentEntityDTO);601 } catch (Exception e) {602 log.error(e.getMessage(), e);603 testSuiteResultService.markTestSuiteResultAsFailed(testSuiteResult, e.getMessage(),604 StatusConstant.STATUS_PRE_FLIGHT);605 }606 }607 }608 testDeviceResultService.updateEnvironmentConsolidatedResults(testDeviceResult);609 }610 public EnvironmentEntityDTO loadEnvironment(TestDeviceResult testDeviceResult, StatusConstant inStatus)611 throws Exception {612 List<TestSuiteEntityDTO> testSuiteEntityDTOS = loadTestSuites(testDeviceResult, inStatus);613 EnvironmentEntityDTO environmentEntityDTO = loadEnvironmentDetails(testDeviceResult);614 environmentEntityDTO.setTestSuites(testSuiteEntityDTOS);615 return environmentEntityDTO;616 }617 public EnvironmentEntityDTO loadEnvironmentDetails(TestDeviceResult testDeviceResult) throws Exception {618 TestPlanSettingEntityDTO testPlanSettingEntityDTO = this.testPlanMapper.mapSettings(this.testPlan);619 EnvironmentEntityDTO environmentEntityDTO = this.testDeviceResultMapper.map(testDeviceResult);620 TestDevice testDevice = testDeviceResult.getTestDevice();621 if (testDevice.getDeviceId() != null) {622 AgentDevice agentDevice = agentDeviceService.find(testDevice.getDeviceId());623 environmentEntityDTO.setAgentDeviceUuid(agentDevice.getUniqueId());624 }625 environmentEntityDTO.setStorageType(storageServiceFactory.getStorageService().getStorageType());626 environmentEntityDTO.setWorkspaceType(this.getAppType());627 environmentEntityDTO.setTestPlanSettings(testPlanSettingEntityDTO);628 environmentEntityDTO.setMatchBrowserVersion(testDevice.getMatchBrowserVersion());629 environmentEntityDTO.setCreateSessionAtCaseLevel(testDevice.getCreateSessionAtCaseLevel());630 TestDeviceSettings settings = getExecutionTestDeviceSettings(testDevice);631 settings.setExecutionName(testPlan.getName());632 settings.setEnvironmentParamId(this.testPlan.getEnvironmentId());633 settings.setEnvRunId(testDeviceResult.getId());634 setTestLabDetails(testDevice, settings,environmentEntityDTO);635 environmentEntityDTO.setEnvSettings(this.testPlanMapper.mapToDTO(settings));636 Agent agent = null;637 if (testDevice.getAgentId() != null)638 agent = this.agentService.find(testDevice.getAgentId());639 setAgentJWTApiKey(environmentEntityDTO, agent);640 setAvailableFeatures(environmentEntityDTO);641 return environmentEntityDTO;642 }643 private List<TestSuiteEntityDTO> loadTestSuites(TestDeviceResult testDeviceResult, StatusConstant inStatus) {644 List<TestSuiteEntityDTO> testSuiteEntityDTOS = new ArrayList<>();645 List<TestSuiteResult> testSuiteResults = this.testSuiteResultService.findPendingTestSuiteResults(testDeviceResult,646 inStatus);647 for (TestSuiteResult testSuiteResult : testSuiteResults) {648 TestSuiteEntityDTO testSuiteEntity = this.testSuiteResultMapper.map(testSuiteResult);649 testSuiteEntity.setTestCases(loadTestCases(testSuiteResult, inStatus));650 testSuiteEntityDTOS.add(testSuiteEntity);651 }652 return testSuiteEntityDTOS;653 }654 private List<TestCaseEntityDTO> loadTestCases(TestSuiteResult testSuiteResult, StatusConstant inStatus) {655 List<TestCaseResult> testCaseResults = this.testCaseResultService.findActiveSuiteTestCaseResults(656 testSuiteResult.getId(), inStatus);657 List<TestCaseEntityDTO> testCases = new ArrayList<>();658 for (TestCaseResult testCaseResult : testCaseResults) {659 TestCaseEntityDTO testCaseEntity = this.testCaseResultMapper.map(testCaseResult);660 testCaseEntity.setDataDrivenTestCases(loadDataDrivenTestCases(testCaseResult, inStatus));661 testCases.add(testCaseEntity);662 }663 return testCases;664 }665 private List<TestCaseEntityDTO> loadDataDrivenTestCases(TestCaseResult testCaseResult, StatusConstant inStatus) {666 List<TestCaseResult> dataDrivenTestCaseResults =667 this.testCaseResultService.findAllByParentIdAndStatus(testCaseResult.getId(), inStatus);668 return this.testCaseResultMapper.map(dataDrivenTestCaseResults);669 }670 private void setAgentJWTApiKey(EnvironmentEntityDTO environmentEntityDTO, com.testsigma.model.Agent id) throws ResourceNotFoundException {671 TestDeviceSettingsDTO envSettings = environmentEntityDTO.getEnvSettings();672 if (id != null) {673 Agent agent = this.agentService.find(id.getId());674 envSettings.setJwtApiKey(agent.generateJwtApiKey(jwtTokenService.getServerUuid()));675 }676 environmentEntityDTO.setEnvSettings(envSettings);677 }678 private void setAvailableFeatures(EnvironmentEntityDTO dto) throws ResourceNotFoundException, SQLException {679 dto.getTestPlanSettings().setHasSuggestionFeature(true);680 }681 private void pushEnvironmentToLab(TestDeviceResult testDeviceResult, EnvironmentEntityDTO environmentEntityDTO) throws Exception {682 ObjectMapper objectMapper = new ObjectMapper();683 objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);684 objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);685 TestDeviceEntity testDeviceEntity = objectMapper.readValue(objectMapper.writeValueAsString(environmentEntityDTO),686 TestDeviceEntity.class);687 try {688 testDeviceResultService.markEnvironmentResultAsInProgress(testDeviceResult, StatusConstant.STATUS_PRE_FLIGHT,689 Boolean.TRUE);690 new TestPlanRunTask(testDeviceEntity).start();691 log.info("Successfully pushed Execution Environment[" + testDeviceEntity.getEnvironmentResultId()692 + "] to Testsigma Lab");693 } catch (Exception e) {694 log.error(e.getMessage(), e);695 String message = "Error while pushing environment to agent - " + e.getMessage();696 throw new TestsigmaException(message, message);697 }698 }699 private void saveRunTimeData() {700 JSONObject runtimeJSONObj = this.getRunTimeData();701 if (runtimeJSONObj != null && runtimeJSONObj.has("runtime_data")) {702 RunTimeData runTimeData = new RunTimeData();703 runTimeData.setTestPlanRunId(this.getTestPlanResult().getId());704 if (runtimeJSONObj.has("runtime_data")) {705 runTimeData.setData(runtimeJSONObj.getJSONObject("runtime_data"));706 }707 this.runTimeDataService.create(runTimeData);708 }709 }710 public void checkTestCaseIsInReadyState(TestCase testCase) throws TestsigmaException {711 if (!testCase.getStatus().equals(TestCaseStatus.READY) && testPlan.getEntityType()=="TEST_PLAN") {712 String message = testCase.getIsStepGroup() ? com.testsigma.constants.MessageConstants.getMessage(MessageConstants.STEP_GROUP_NOT_READY, testCase.getName()) :713 MessageConstants.TESTCASE_NOT_READY;714 throw new TestsigmaException(message, message);715 }716 }717 private void fetchEnvironmentResultsReRunList() {718 testDeviceResultsReRunList = new ArrayList<>();719 if (getReRunType() == ReRunType.ALL_TESTS) {720 testDeviceResultsReRunList = testDeviceResultService.findAllByTestPlanResultId(this.getParentTestPlanResultId());721 } else if (getReRunType() == ReRunType.ONLY_FAILED_TESTS) {722 testDeviceResultsReRunList = testDeviceResultService.findAllByTestPlanResultIdAndResultIsNot723 (this.getParentTestPlanResultId(), ResultConstant.SUCCESS);724 }725 }726 private void fetchTestSuitesResultsReRunList(Long parentEnvironmentResultId) {727 testSuiteResultsReRunList = new ArrayList<>();728 try {729 TestDeviceResult parentTestDeviceResult = testDeviceResultService.find(parentEnvironmentResultId);730 List<TestSuiteResult> failedTestSuites;731 if (parentTestDeviceResult != null) {...

Full Screen

Full Screen

fetchEnvironmentResultsReRunList

Using AI Code Generation

copy

Full Screen

1import com.testsigma.service.AgentExecutionService;2import com.testsigma.service.AgentExecutionServiceFactory;3import com.testsigma.service.model.Environment;4import com.testsigma.service.model.Execution;5import com.testsigma.service.model.ExecutionExecutionId;6import com.testsigma.service.model.ExecutionExecutionIdGetRequest;7import com.testsigma.service.model.ExecutionExecutionIdGetResponse;8import com.testsigma.service.model.ExecutionExecutionIdReRunGetRequest;9import com.testsigma.service.model.ExecutionExecutionIdReRunGetResponse;10import com.testsigma.service.model.ExecutionExecutionIdReRunPostRequest;11import com.testsigma.service.model.ExecutionExecutionIdReRunPostResponse;12import com.testsigma.service.model.ExecutionExecutionIdReRunPutRequest;13import com.testsigma.service.model.ExecutionExecutionIdReRunPutResponse;14import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdDeleteRequest;15import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdDeleteResponse;16import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdGetRequest;17import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdGetResponse;18import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdPutRequest;19import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdPutResponse;20import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdStopPostRequest;21import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdStopPostResponse;22import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdStopPutRequest;23import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdStopPutResponse;24import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdTestResultsGetRequest;25import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdTestResultsGetResponse;26import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdTestResultsPostRequest;27import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdTestResultsPostResponse;28import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdTestResultsTestResultsIdGetRequest;29import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdTestResultsTestResultsIdGetResponse;30import com.testsigma.service.model.ExecutionExecutionIdReRunReRunIdTestResultsTestResultsIdPutRequest;31import com.testsigma.service.model.ExecutionExecutionIdReRunReRunId

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.

Most used method in AgentExecutionService

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful