Best Testsigma code snippet using com.testsigma.service.AgentExecutionService.getAppType
Source:AgentExecutionService.java
...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) {732 if (getReRunType() == ReRunType.ALL_TESTS) {733 testSuiteResultsReRunList = testSuiteResultService.findAllByEnvironmentResultId(parentTestDeviceResult.getId());734 } else if (getReRunType() == ReRunType.ONLY_FAILED_TESTS) {735 failedTestSuites = testSuiteResultService.findAllByEnvironmentResultIdAndResultIsNot736 (parentTestDeviceResult.getId(), ResultConstant.SUCCESS);737 if (failedTestSuites.size() > 0) {738 for (TestSuiteResult testSuiteResult : failedTestSuites) {739 List<Long> testSuitePreRequisiteIds = findTestSuitePreRequisiteIds(testSuiteResult, new ArrayList<>(), 0);740 if (testSuitePreRequisiteIds.size() > 0) {741 List<TestSuiteResult> preRequisiteResults = testSuiteResultService.findBySuiteResultIds(testSuitePreRequisiteIds);742 testSuiteResultsReRunList.addAll(preRequisiteResults);743 }744 testSuiteResultsReRunList.add(testSuiteResult);745 }746 }747 }748 }749 } catch (Exception e) {750 log.error(e.getMessage(), e);751 }752 }753 private List<Long> findTestSuitePreRequisiteIds(TestSuiteResult testSuiteResult, List<Long> testSuitePreRequisiteIds,754 int depth) {755 if (depth < PRE_REQUISITE_DEPTH) {756 TestSuiteResult preReqTestSuiteResult;757 try {758 TestSuite testSuite = testSuiteResult.getTestSuite();759 if (testSuite.getPreRequisite() != null) {760 preReqTestSuiteResult = testSuiteResultService.findByEnvironmentResultIdAndSuiteId(761 testSuiteResult.getEnvironmentResultId(), testSuite.getPreRequisite());762 if (preReqTestSuiteResult != null) {763 testSuitePreRequisiteIds = findTestSuitePreRequisiteIds(preReqTestSuiteResult, testSuitePreRequisiteIds,764 depth + 1);765 testSuitePreRequisiteIds.add(preReqTestSuiteResult.getId());766 }767 }768 } catch (Exception e) {769 log.error(e.getMessage(), e);770 }771 }772 return testSuitePreRequisiteIds;773 }774 private void fetchTestCaseResultsReRunList(Long parentTestSuiteResultId) {775 testCaseResultsReRunList = new ArrayList<>();776 try {777 TestSuiteResult parentTestSuiteResult = testSuiteResultService.find(parentTestSuiteResultId);778 List<TestCaseResult> failedTestCases;779 if (parentTestSuiteResult != null) {780 if (getReRunType() == ReRunType.ALL_TESTS || isTestSuiteAPrerequisite(parentTestSuiteResult)) {781 testCaseResultsReRunList = testCaseResultService.findAllBySuiteResultId(parentTestSuiteResult.getId());782 } else if (getReRunType() == ReRunType.ONLY_FAILED_TESTS) {783 failedTestCases = testCaseResultService.findAllBySuiteResultIdAndResultIsNot784 (parentTestSuiteResult.getId(), ResultConstant.SUCCESS);785 if (failedTestCases.size() > 0) {786 for (TestCaseResult testCaseResult : failedTestCases) {787 List<Long> testCasePreRequisiteIds = findTestCasePreRequisiteIds(testCaseResult, new ArrayList<>(), 0);788 //If a prerequisite is failed, it will be already available in failedTestCases. So we need to add only prerequisites with SUCCESS status.789 List<TestCaseResult> preRequisiteResults = fetchPreRequisiteTestCaseResultsWithSuccessStatus(testCasePreRequisiteIds);790 testCaseResultsReRunList.addAll(preRequisiteResults);791 testCaseResultsReRunList.add(testCaseResult);792 }793 }794 }795 }796 } catch (Exception e) {797 log.error(e.getMessage(), e);798 }799 }800 private List<TestCaseResult> fetchPreRequisiteTestCaseResultsWithSuccessStatus(List<Long> testCasePreRequisiteIds) {801 List<TestCaseResult> preRequisitesWithSuccessStatus = new ArrayList<>();802 List<TestCaseResult> preRequisiteResults = testCaseResultService.findByTestCaseResultIds(testCasePreRequisiteIds);803 for (TestCaseResult testCaseResult : preRequisiteResults) {804 if (testCaseResult.getResult() == ResultConstant.SUCCESS) {805 preRequisitesWithSuccessStatus.add(testCaseResult);806 }807 }808 return preRequisitesWithSuccessStatus;809 }810 private boolean isTestSuiteAPrerequisite(TestSuiteResult testSuiteResult) {811 List<TestSuite> testSuites = testSuiteService.findByPrerequisiteId(testSuiteResult.getSuiteId());812 for (TestSuite testSuite : testSuites) {813 TestSuiteResult baseTestSuiteResult = testSuiteResultService.findByEnvironmentResultIdAndSuiteId(testSuiteResult.getEnvironmentResultId(), testSuite.getId());814 if (baseTestSuiteResult != null) {815 return true;816 }817 }818 return false;819 }820 private List<Long> findTestCasePreRequisiteIds(TestCaseResult testCaseResult, List<Long> testCasePreRequisiteIds,821 int depth) {822 if (depth < PRE_REQUISITE_DEPTH) {823 List<TestCaseResult> preReqTestCaseResults;824 try {825 TestCase testCase = testCaseResult.getTestCase();826 if (testCase.getPreRequisite() != null) {827 //In case of data-driven tests, we have multiple rows in TestCaseResult table for each dataset(each row in testdata profile)828 preReqTestCaseResults = testCaseResultService.findAllBySuiteResultIdAndTestCaseId(829 testCaseResult.getSuiteResultId(), testCase.getPreRequisite());830 if (preReqTestCaseResults != null) {831 for (TestCaseResult preReqTestCaseResult : preReqTestCaseResults) {832 testCasePreRequisiteIds = findTestCasePreRequisiteIds(preReqTestCaseResult, testCasePreRequisiteIds,833 depth + 1);834 testCasePreRequisiteIds.add(preReqTestCaseResult.getId());835 }836 }837 }838 } catch (Exception e) {839 log.error(e.getMessage(), e);840 }841 }842 return testCasePreRequisiteIds;843 }844 // ################################################ AFTER START ###################################################845 private void afterStart() throws Exception {846 setInitialCounts();847 }848 private void setInitialCounts() {849 List<TestDeviceResult> executionEnvironmentsResults850 = testDeviceResultService.findAllByTestPlanResultId(this.getTestPlanResult().getId());851 for (TestDeviceResult executionTestDeviceResult : executionEnvironmentsResults) {852 List<TestCaseResult> testCaseResults = testCaseResultService.findAllByEnvironmentResultId(executionTestDeviceResult.getId());853 for (TestCaseResult testCaseResult : testCaseResults) {854 testCaseResultService.updateResultCounts(testCaseResult);855 }856 List<TestSuiteResult> testSuitesResults = testSuiteResultService.findAllByEnvironmentResultId(executionTestDeviceResult.getId());857 for (TestSuiteResult testSuiteResult : testSuitesResults) {858 testSuiteResultService.updateResultCounts(testSuiteResult.getId());859 }860 testDeviceResultService.updateResultCounts(executionTestDeviceResult.getId());861 }862 }863 // ################################################ STOP ###################################################864 public void stop() throws Exception {865 beforeStop();866 stopQueuedEnvironments(AutomatorMessages.MSG_USER_ABORTED_EXECUTION, Boolean.TRUE);867 afterStop();868 }869 private void beforeStop() throws TestsigmaException {870 TestPlanResult testPlanResult = this.testPlanResultService.findByTestPlanIdAndStatusIsNot(this.testPlan.getId(),871 StatusConstant.STATUS_COMPLETED);872 if (testPlanResult == null) {873 throw new TestsigmaException("No Queued executions for test plan - " + this.getTestPlan().getName());874 }875 this.setTestPlanResult(testPlanResult);876 }877 private void stopQueuedEnvironments(String errorMessage, Boolean sendPendingExecutions) {878 List<TestDeviceResult> testDeviceResults = this.testDeviceResultService879 .findAllByTestPlanResultIdAndStatusIsNot(this.testPlanResult.getId(), StatusConstant.STATUS_COMPLETED);880 for (TestDeviceResult testDeviceResult : testDeviceResults) {881 testDeviceResultService.markEnvironmentResultAsStopped(testDeviceResult, errorMessage);882 testDeviceResultService.updateResultCounts(testDeviceResult.getId());883 }884 Timestamp currentTime = new Timestamp(java.lang.System.currentTimeMillis());885 TestPlanResult testPlanResult = this.testPlanResult;886 testPlanResult.setResult(ResultConstant.STOPPED);887 testPlanResult.setStatus(StatusConstant.STATUS_COMPLETED);888 testPlanResult.setMessage(errorMessage);889 testPlanResult.setEndTime(currentTime);890 testPlanResult.setDuration(testPlanResult.getEndTime().getTime() - testPlanResult.getStartTime().getTime());891 this.testPlanResultService.update(testPlanResult);892 try {893 if (sendPendingExecutions) {894 testDeviceResultService.sendPendingTestPlans();895 }896 } catch (Exception e) {897 log.error(e.getMessage(), e);898 }899 }900 private void afterStop() {901 }902 protected void setTestLabDetails(TestDevice testDevice, TestDeviceSettings settings,EnvironmentEntityDTO environmentEntityDTO)903 throws Exception {904 if (this.testPlan.getWorkspaceVersion().getWorkspace().getWorkspaceType().isRest())905 return;906 TestPlanLabType exeLabType = this.getTestPlan().getTestPlanLabType();907 setPlatformDetails(testDevice, settings, exeLabType, testDevice.getAgent(), environmentEntityDTO);908 }909 public void loadTestCase(String testDataSetName, TestCaseEntityDTO testCaseEntityDTO, AbstractTestPlan testPlan,910 Workspace workspace) throws Exception {911 String profileName = null;912 String environmentProfileName = null;913 Map<String, String> environmentParameters = null;914 List<com.testsigma.model.TestDataSet> databank = new ArrayList<>();915 com.testsigma.model.TestDataSet dataSet = null;916 if (testPlan.getEnvironmentId() != null) {917 Environment environment = testPlan.getEnvironment();918 environmentParameters = environment.getData();919 environmentProfileName = environment.getName();920 }921 List<TestStep> testSteps = testStepService.findAllByTestCaseIdAndEnabled(testCaseEntityDTO.getId());922 List<TestStepDTO> testStepDTOS = testStepMapper.mapDTOs(testSteps);923 Long testDataId = testCaseEntityDTO.getTestDataId();924 if (testDataId != null) {925 TestData testData = testDataProfileService.find(testCaseEntityDTO.getTestDataId());926 databank = testData.getData();927 profileName = testData.getTestDataName();928 }929 List<Long> testCaseIds = new ArrayList<>();930 testCaseIds.add(testCaseEntityDTO.getId());931 for (TestStepDTO testStepDTO : testStepDTOS) {932 if (testStepDTO.getStepGroupId() != null) {933 TestCase testCase = testCaseService.find(testStepDTO.getStepGroupId());934 checkTestCaseIsInReadyState(testCase);935 List<TestStep> childSteps;936 childSteps = testStepService.findAllByTestCaseIdAndEnabled(testStepDTO.getStepGroupId());937 List<TestStepDTO> childStepsDTOs = testStepMapper.mapDTOs(childSteps);938 testStepDTO.setTestStepDTOS(childStepsDTOs);939 testCaseIds.add(testStepDTO.getStepGroupId());940 }941 if (testStepDTO.getAddonActionId() != null) {942 if (!this.getTestPlan().getTestPlanLabType().isHybrid()) {943 AddonNaturalTextAction addonNaturalTextAction = addonNaturalTextActionService.findById(testStepDTO.getAddonActionId());944 Addon addon = addonService.findById(addonNaturalTextAction.getAddonId());945 if (addon.getStatus() == AddonStatus.DRAFT) {946 throw new TestsigmaException(MessageConstants.DRAFT_PLUGIN_ALLOWED_IN_HYBRID_ONLY,947 MessageConstants.DRAFT_PLUGIN_ALLOWED_IN_HYBRID_ONLY);948 }949 }950 }951 }952 List<String> elementNames = testStepService.findElementNamesByTestCaseIds(testCaseIds);953 elementNames.addAll(testStepService.findAddonActionElementsByTestCaseIds(testCaseIds));954 List<Element> elementList = elementService.findByNameInAndWorkspaceVersionId(elementNames,955 testPlan.getWorkspaceVersionId());956 Map<String, Element> elements = new HashMap<>();957 for (Element element : elementList) {958 elements.put(element.getName().toLowerCase(), element);959 }960 if (!testCaseEntityDTO.getIsDataDriven()) {961 if (!databank.isEmpty()) {962 dataSet = databank.get(testCaseEntityDTO.getTestDataStartIndex());963 testCaseEntityDTO.setTestDataSetName(dataSet.getName());964 }965 } else {966 for (TestDataSet data : databank) {967 if (data.getName().equals(testDataSetName)) {968 dataSet = data;969 break;970 }971 }972 testCaseEntityDTO.setTestDataSetName(dataSet.getName());973 testCaseEntityDTO.setExpectedToFail(dataSet.getExpectedToFail());974 }975 List<TestCaseStepEntityDTO> executableList = getExecutableTestSteps(976 workspace.getWorkspaceType(), testStepDTOS,977 elements, dataSet, testPlan.getId(),978 environmentParameters, testCaseEntityDTO, environmentProfileName,979 profileName);980 appendPreSignedURLs(executableList, testCaseEntityDTO, false, null, null);981 testCaseEntityDTO.setTestSteps(executableList);982 TestCaseResult testCaseResult = testCaseResultService.find(testCaseEntityDTO.getTestCaseResultId());983 testCaseResultService.markTestCaseResultAsInProgress(testCaseResult);984 }985 private boolean isStepInsideForLoop(TestCaseStepEntityDTO testCaseStepEntity) throws ResourceNotFoundException {986 if (testCaseStepEntity.getParentId() != null) {987 TestStep testStep = testStepService.find(testCaseStepEntity.getParentId());988 return (testStep.getType() == TestStepType.FOR_LOOP);989 }990 return false;991 }992 protected void appendPreSignedURLs(List<TestCaseStepEntityDTO> executableList, TestCaseEntityDTO testCaseEntity,993 boolean isWhileLoop, Long stepGroupStepID, TestCaseStepEntityDTO parentGroupEntity)994 throws ResourceNotFoundException {995 Calendar cal = Calendar.getInstance();996 cal.add(Calendar.HOUR, 10);997 stepGroupStepID = (stepGroupStepID == null) ? 0 : stepGroupStepID;998 StorageService storageService = this.storageServiceFactory.getStorageService();999 for (TestCaseStepEntityDTO testCaseStepEntity : executableList) {1000 Integer index;1001 if (parentGroupEntity != null && !isStepInsideForLoop(testCaseStepEntity)) {1002 index = (parentGroupEntity.getIndex() == null) ? 0 : parentGroupEntity.getIndex();1003 } else {1004 index = (testCaseStepEntity.getIndex() == null) ? 0 : testCaseStepEntity.getIndex();1005 }1006 String screenShotPath = String.format("/executions/%s/%s_%s_%s_%s.%s", testCaseEntity.getTestCaseResultId(),1007 testCaseStepEntity.getId(), stepGroupStepID, testCaseStepEntity.getPosition(), index, "jpeg");1008 URL presignedURL = storageService.generatePreSignedURL(screenShotPath, StorageAccessLevel.WRITE, 600);1009 testCaseStepEntity.setScreenshotPath(presignedURL.toString());1010 handleUploadActionStep(testCaseStepEntity,storageService);1011 handleInstallApp(testCaseStepEntity,storageService);1012 if ((testCaseStepEntity.getTestCaseSteps() != null) && !testCaseStepEntity.getTestCaseSteps().isEmpty()) {1013 if (testCaseStepEntity.getConditionType() == TestStepConditionType.LOOP_WHILE) {1014 addScreenshotPresignedURLsForWhileLoop(testCaseStepEntity, testCaseEntity, stepGroupStepID, parentGroupEntity,storageService);1015 appendPreSignedURLs(testCaseStepEntity.getTestCaseSteps(), testCaseEntity, true, stepGroupStepID, parentGroupEntity);1016 } else if (testCaseStepEntity.getType() == TestStepType.STEP_GROUP) {1017 Long parentGroupStepId = (stepGroupStepID != 0) ? stepGroupStepID : testCaseStepEntity.getId();1018 appendPreSignedURLs(testCaseStepEntity.getTestCaseSteps(), testCaseEntity, isWhileLoop, parentGroupStepId, testCaseStepEntity);1019 } else {1020 appendPreSignedURLs(testCaseStepEntity.getTestCaseSteps(), testCaseEntity, isWhileLoop, stepGroupStepID, parentGroupEntity);1021 }1022 }1023 if (isWhileLoop && !(testCaseStepEntity.getType() == TestStepType.STEP_GROUP)) {1024 addScreenshotPresignedURLsForWhileLoop(testCaseStepEntity, testCaseEntity, stepGroupStepID, parentGroupEntity,storageService);1025 }1026 }1027 }1028 private void addScreenshotPresignedURLsForWhileLoop(TestCaseStepEntityDTO testCaseStep, TestCaseEntityDTO testCaseEntity,1029 Long parentGroupStepId, TestCaseStepEntityDTO parentGroupEntity, StorageService storageService) {1030 parentGroupStepId = (parentGroupStepId == null) ? 0 : parentGroupStepId;1031 Map<String, String> additionalScreenshotPaths = new HashMap<>();1032 for (int iteration = 1; iteration <= NaturalTextActionConstants.WHILE_LOOP_MAX_LIMIT; iteration++) {1033 Calendar cal = Calendar.getInstance();1034 cal.add(Calendar.HOUR, 10);1035 Integer index = null;1036 if (parentGroupEntity != null) {1037 index = (parentGroupEntity.getIndex() == null) ? 0 : parentGroupEntity.getIndex();1038 } else {1039 index = (testCaseStep.getIndex() == null) ? 0 : testCaseStep.getIndex();1040 }1041 String screenShotPath = String.format("/executions/%s/%s_%s_%s_%s_%s.%s", testCaseEntity.getTestCaseResultId(),1042 testCaseStep.getId(), parentGroupStepId, iteration, testCaseStep.getPosition(), index, "jpeg");1043 URL preSignedURL = storageService.generatePreSignedURL(screenShotPath, StorageAccessLevel.WRITE, 600);1044 String iterationKey = String.format("%s_%s", iteration, testCaseStep.getIndex());1045 additionalScreenshotPaths.put(iterationKey, preSignedURL.toString());1046 }1047 testCaseStep.setAdditionalScreenshotPaths(additionalScreenshotPaths);1048 }1049 private void handleUploadActionStep(TestCaseStepEntityDTO testCaseStepEntity, StorageService storageService) {1050 if (testCaseStepEntity.getAction() != null && testCaseStepEntity.getAction().toLowerCase().contains("upload")1051 && testCaseStepEntity.getNaturalTextActionId() != null && (testCaseStepEntity.getNaturalTextActionId().equals(969)1052 || testCaseStepEntity.getNaturalTextActionId().equals(10150))) {1053 handleFileActionStep(testCaseStepEntity,storageService);1054 }1055 }1056 private void handleInstallApp(TestCaseStepEntityDTO testCaseStepEntity, StorageService storageService) {1057 if (testCaseStepEntity.getAction() != null && testCaseStepEntity.getAction()1058 .toLowerCase().contains("installApp".toLowerCase()) && (testCaseStepEntity.getNaturalTextActionId() != null)1059 && (testCaseStepEntity.getNaturalTextActionId().equals(20003) || testCaseStepEntity.getNaturalTextActionId().equals(30003))) {1060 handleFileActionStep(testCaseStepEntity,storageService);1061 }1062 }1063 private void handleFileActionStep(TestCaseStepEntityDTO testCaseStepEntity, StorageService storageService) {1064 com.testsigma.automator.entity.TestDataPropertiesEntity testDataPropertiesEntity = testCaseStepEntity.getTestDataMap().get(1065 testCaseStepEntity.getTestDataMap().keySet().stream().findFirst().get());1066 String fileUrl = testDataPropertiesEntity.getTestDataValue().replace("testsigma-storage://", "");1067 URL newUrl = storageService.generatePreSignedURL(fileUrl, StorageAccessLevel.READ, 180);1068 if(TestPlanLabType.TestsigmaLab == this.getTestPlan().getTestPlanLabType()) {1069 try {1070 newUrl = new URL(newUrl.toString().replace(applicationConfig.getServerUrl(), applicationConfig.getServerLocalUrl()));1071 } catch (MalformedURLException ignore) {}1072 }1073 testDataPropertiesEntity.setTestDataValuePreSignedURL(newUrl.toString());1074 }1075 private void setPlatformDetails(TestDevice testDevice, TestDeviceSettings settings,1076 TestPlanLabType testPlanLabType, Agent agent,EnvironmentEntityDTO environmentEntityDTO) throws TestsigmaException {1077 populatePlatformOsDetails(testDevice, settings, testPlanLabType, agent);1078 if (this.getAppType().isWeb()) {1079 populatePlatformBrowserDetails(testDevice, settings, testPlanLabType, agent,environmentEntityDTO);1080 }1081 }1082 protected void populatePlatformOsDetails(TestDevice testDevice, TestDeviceSettings settings,1083 TestPlanLabType testPlanLabType, Agent agent)1084 throws TestsigmaException {1085 PlatformOsVersion platformOsVersion = null;1086 if (testPlanLabType == TestPlanLabType.Hybrid) {1087 Platform platform = null;1088 String osVersion = null;1089 if ((this.getAppType().isWeb()) && agent != null) {1090 platform = agent.getOsType().getPlatform();1091 osVersion = agent.getPlatformOsVersion(agent.getOsType().getPlatform());1092 } else if (this.getAppType().isMobile() && testDevice.getDeviceId() != null) {1093 AgentDevice agentDevice = this.agentDeviceService.find(testDevice.getDeviceId());1094 osVersion = agentDevice.getPlatformOsVersion();1095 platform = agentDevice.getOsName().getPlatform();1096 }1097 platformOsVersion = platformsService.getPlatformOsVersion(platform, osVersion, this.getAppType(), testPlanLabType);1098 } else {1099 platformOsVersion = platformsService.getPlatformOsVersion(testDevice.getPlatformOsVersionId(), testPlanLabType);1100 }1101 settings.setPlatform(platformOsVersion.getPlatform());1102 if (TestPlanLabType.Hybrid == testPlanLabType) {1103 settings.setOsVersion(platformOsVersion.getVersion());1104 }1105 }1106 protected void populatePlatformBrowserDetails(TestDevice testDevice, TestDeviceSettings settings,1107 TestPlanLabType testPlanLabType, Agent agent,EnvironmentEntityDTO environmentEntityDTO)1108 throws TestsigmaException {1109 PlatformBrowserVersion platformBrowserVersion = null;1110 if (agent != null && testPlanLabType == TestPlanLabType.Hybrid) {1111 Platform platform = agent.getOsType().getPlatform();1112 String osVersion = agent.getPlatformOsVersion(platform);1113 Browsers browser = OSBrowserType.getBrowser(testDevice.getBrowser());1114 String browserVersion = agent.getBrowserVersion(browser.toString());1115 platformBrowserVersion = platformsService.getPlatformBrowserVersion(platform, osVersion, browser, browserVersion, testPlanLabType);1116 } else {1117 platformBrowserVersion = platformsService.getPlatformBrowserVersion(testDevice.getPlatformBrowserVersionId(), testPlanLabType);1118 }1119 if (testPlanLabType.isHybrid()) {1120 matchHybridBrowserVersion(agent, platformBrowserVersion, testDevice, platformBrowserVersion.getName(),environmentEntityDTO);1121 }1122 settings.setBrowser(platformBrowserVersion.getName().name());1123 if (testPlanLabType == TestPlanLabType.Hybrid) {1124 settings.setBrowserVersion(platformBrowserVersion.getVersion());1125 settings.setHybridBrowserDriverPath(1126 platformsService.getDriverPath(platformBrowserVersion.getPlatform(),1127 platformBrowserVersion.getVersion(), platformBrowserVersion.getName(),1128 platformBrowserVersion.getDriverVersion()));1129 } else {1130 settings.setBrowserVersion(platformBrowserVersion.getVersion());1131 }1132 }1133 private void matchHybridBrowserVersion(Agent agent1, PlatformBrowserVersion platformBrowserVersion,1134 TestDevice testDevice, Browsers browser,EnvironmentEntityDTO environmentEntityDTO)1135 throws TestsigmaException {1136 if ((agent1 != null) && (platformBrowserVersion != null)) {1137 Agent agent = agentService.find(agent1.getId());1138 for (AgentBrowser agentBrowser : agent.getBrowserList()) {1139 Browsers aBrowser = Browsers.getBrowser(agentBrowser.getName().getBrowserName());1140 if ((browser == aBrowser) &&1141 (Boolean.TRUE == testDevice.getMatchBrowserVersion()) &&1142 !platformBrowserVersion.getVersion().equals("" + agentBrowser.getMajorVersion())) {1143 environmentEntityDTO.setErrorCode(ExceptionErrorCodes.BROWSER_VERSION_NOT_AVAILABLE);1144 log.info("Local agent browser version[" + agentBrowser.getMajorVersion()1145 + "] doesn't match selected browser version[" + platformBrowserVersion.getVersion() + "]");1146 }1147 }1148 }1149 }1150 public List<TestCaseStepEntityDTO> getExecutableTestSteps(WorkspaceType workspaceType,1151 List<TestStepDTO> testStepDTOS,1152 Map<String, Element> elementMap,1153 com.testsigma.model.TestDataSet testDataSet,1154 Long testPlanId, Map<String, String> environmentParams,1155 TestCaseEntityDTO testCaseEntityDTO, String environmentParamSetName,1156 String dataProfile) throws Exception {1157 List<Long> loopIds = new ArrayList<>();1158 List<TestCaseStepEntityDTO> toReturn = new ArrayList<>();1159 for (TestStepDTO testStepDTO : testStepDTOS) {1160 if (loopIds.contains(testStepDTO.getParentId())) {1161 continue;1162 }1163 if (testStepDTO.getType() == TestStepType.FOR_LOOP) {1164 loopIds.add(testStepDTO.getId());1165 new ForLoopStepProcessor(webApplicationContext, toReturn, workspaceType, elementMap, testStepDTO,1166 testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName, dataProfile).processLoop(testStepDTOS, loopIds);1167 continue;1168 } else if (testStepDTO.getType() == TestStepType.WHILE_LOOP) {1169 loopIds.add(testStepDTO.getId());1170 new WhileLoopStepProcessor(webApplicationContext, toReturn, workspaceType, elementMap, testStepDTO,1171 testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName, dataProfile).processWhileLoop(testStepDTOS, loopIds);1172 continue;1173 } else if (testStepDTO.getType() == TestStepType.REST_STEP) {1174 new RestStepProcessor(webApplicationContext, toReturn, workspaceType, elementMap, testStepDTO,1175 testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName, dataProfile).process();1176 continue;1177 }1178 TestCaseStepEntityDTO stepEntity = new StepProcessor(webApplicationContext, toReturn, workspaceType,1179 elementMap, testStepDTO, testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName,1180 dataProfile).processStep();1181 stepEntity.setStepGroupId(testStepDTO.getStepGroupId());1182 stepEntity.setParentId(testStepDTO.getParentId());1183 stepEntity.setConditionType(testStepDTO.getConditionType());1184 if (testStepDTO.getTestStepDTOS() != null) {1185 for (TestStepDTO subTestStepDTO : testStepDTO.getTestStepDTOS()) {1186 List<TestCaseStepEntityDTO> stepGroupSpecialSteps = new ArrayList<>();1187 if (stepEntity.getTestCaseSteps() == null) {1188 stepEntity.setTestCaseSteps(new ArrayList<>());1189 }1190 //TODO: check logic for test step key Generation and recursive logic for step group generation1191 if (loopIds.contains(subTestStepDTO.getParentId())) {1192 continue;1193 }1194 if (subTestStepDTO.getType() == TestStepType.FOR_LOOP) {1195 loopIds.add(subTestStepDTO.getId());1196 new ForLoopStepProcessor(webApplicationContext, stepGroupSpecialSteps, workspaceType, elementMap, subTestStepDTO,1197 testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName, dataProfile)1198 .processLoop(testStepDTO.getTestStepDTOS(), loopIds);1199 stepEntity.getTestCaseSteps().addAll(stepGroupSpecialSteps);1200 continue;1201 } else if (subTestStepDTO.getType() == TestStepType.WHILE_LOOP) {1202 loopIds.add(subTestStepDTO.getId());1203 new WhileLoopStepProcessor(webApplicationContext, stepGroupSpecialSteps, workspaceType, elementMap,1204 subTestStepDTO, testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName, dataProfile)1205 .processWhileLoop(testStepDTO.getTestStepDTOS(), loopIds);1206 stepEntity.getTestCaseSteps().addAll(stepGroupSpecialSteps);1207 continue;1208 } else if (subTestStepDTO.getType() == TestStepType.REST_STEP) {1209 new RestStepProcessor(webApplicationContext, stepGroupSpecialSteps, workspaceType, elementMap, subTestStepDTO,1210 testPlanId, testDataSet, environmentParams, testCaseEntityDTO, environmentParamSetName, dataProfile).process();1211 stepEntity.getTestCaseSteps().addAll(stepGroupSpecialSteps);1212 continue;1213 }1214 TestCaseStepEntityDTO cstepEntity = new StepProcessor(webApplicationContext, toReturn, workspaceType,1215 elementMap, subTestStepDTO, testPlanId, testDataSet, environmentParams, testCaseEntityDTO,1216 environmentParamSetName, dataProfile).processStep();1217 cstepEntity.setParentId(subTestStepDTO.getParentId());1218 cstepEntity.setConditionType(subTestStepDTO.getConditionType());1219 stepEntity.getTestCaseSteps().add(cstepEntity);1220 }1221 }1222 toReturn.add(stepEntity);1223 }1224 return toReturn;1225 }1226 private WorkspaceType getAppType() {1227 return this.testPlan.getWorkspaceVersion().getWorkspace().getWorkspaceType();1228 }1229}...
getAppType
Using AI Code Generation
1import com.testsigma.service.AgentExecutionService;2import com.testsigma.service.AgentExecutionService.AppType;3import com.testsigma.service.AgentExecutionService.AppType;4AppType appType = AgentExecutionService.getAppType();5System.out.println(appType);6import com.testsigma.service.AgentExecutionService;7import com.testsigma.service.AgentExecutionService.AppType;8import com.testsigma.service.AgentExecutionService.AppType;9AppType appType = AgentExecutionService.getAppType();10System.out.println(appType);11[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ testsigma ---12[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ testsigma ---13[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ testsigma ---14[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ testsigma ---
getAppType
Using AI Code Generation
1import com.testsigma.service.AgentExecutionService;2import com.testsigma.service.AgentExecutionServiceFactory;3AgentExecutionService agentExecutionService = AgentExecutionServiceFactory.getAgentExecutionService();4String appType = agentExecutionService.getAppType();5System.out.println("App type is: " + appType);6import com.testsigma.service.AgentExecutionService;7import com.testsigma.service.AgentExecutionServiceFactory;8AgentExecutionService agentExecutionService = AgentExecutionServiceFactory.getAgentExecutionService();9String appType = agentExecutionService.getAppType();10System.out.println("App type is: " + appType);11[highlight language="java"]public String getAppVersion();[/highlight]12import com.testsigma.service.AgentExecutionService;13import com.testsigma.service.AgentExecutionServiceFactory;14AgentExecutionService agentExecutionService = AgentExecutionServiceFactory.getAgentExecutionService();15String appVersion = agentExecutionService.getAppVersion();16System.out.println("App version is: " + appVersion);17import com.testsigma.service.AgentExecutionService;18import com.testsigma.service.AgentExecutionServiceFactory;19AgentExecutionService agentExecutionService = AgentExecutionServiceFactory.getAgentExecutionService();20String appVersion = agentExecutionService.getAppVersion();21System.out.println("App version is: " + appVersion);
getAppType
Using AI Code Generation
1import com.testsigma.service.AgentExecutionService;2import com.testsigma.service.AgentExecutionServiceFactory;3import com.testsigma.service.AgentExecutionServiceFactory.ServiceType;4import com.testsigma.service.AgentExecutionServiceFactory.ServiceType;5import com.testsigma.service.AgentExecutionService;6import com.testsigma.service.AgentExecutionServiceFactory;7AgentExecutionService agentExecutionService = AgentExecutionServiceFactory.getAgentExecutionService(ServiceType.REST);8String appType = agentExecutionService.getAppType("C:\\Users\\user\\AppData\\Local\\Temp\\appium-apps\\com.testsigma.androidsampleapp.apk");9System.out.println("App Type: "+appType);10import com.testsigma.service.AgentExecutionService;11import com.testsigma.service.AgentExecutionServiceFactory;12import com.testsigma.service.AgentExecutionServiceFactory.ServiceType;13import com.testsigma.service.AgentExecutionServiceFactory.ServiceType;14import com.testsigma.service.AgentExecutionService;15import com.testsigma.service.AgentExecutionServiceFactory;16AgentExecutionService agentExecutionService = AgentExecutionServiceFactory.getAgentExecutionService(ServiceType.REST);17String deviceList = agentExecutionService.getDeviceList();18System.out.println("Device List: "+deviceList);
getAppType
Using AI Code Generation
1if (AgentExecutionService.getAppType() == "IOS") {2} else if (AgentExecutionService.getAppType() == "ANDROID") {3} else if (AgentExecutionService.getAppType() == "WEB") {4} else if (AgentExecutionService.getAppType() == "WINDOWS") {5} else if (AgentExecutionService.getAppType() == "MAC") {6} else if (AgentExecutionService.getAppType() == "UNKNOWN") {7} else if (AgentExecutionService.getAppType() == "UNRECOGNIZED") {8}9if (AgentExecutionService.getDeviceType() == "ANDROID_PHONE") {10} else if (AgentExecutionService.getDeviceType() == "ANDROID_TABLET") {11} else if (AgentExecutionService.getDeviceType() == "IOS
getAppType
Using AI Code Generation
1import com.testsigma.service.AgentExecutionService;2import com.testsigma.service.AgentExecutionServiceFactory;3import com.testsigma.service.AgentException;4String appType = AgentExecutionServiceFactory.getAgentExecutionService().getAppType();5String appName = AgentExecutionServiceFactory.getAgentExecutionService().getAppName(appType);6String appVersion = AgentExecutionServiceFactory.getAgentExecutionService().getAppVersion(appName);7String appPackageName = AgentExecutionServiceFactory.getAgentExecutionService().getAppPackageName(appVersion);8String appActivityName = AgentExecutionServiceFactory.getAgentExecutionService().getAppActivityName(appPackageName);9System.out.println("appType : "+appType);10System.out.println("appName : "+appName);11System.out.println("appVersion : "+appVersion);12System.out.println("appPackageName : "+appPackageName);13System.out.println("appActivityName : "+appActivityName);
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!!