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

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

Source:AgentExecutionService.java Github

copy

Full Screen

...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) {...

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