How to use WhileLoopStepProcessor class of com.testsigma.step.processors package

Best Testsigma code snippet using com.testsigma.step.processors.WhileLoopStepProcessor

Source:AgentExecutionService.java Github

copy

Full Screen

...24import com.testsigma.model.*;25import com.testsigma.step.processors.ForLoopStepProcessor;26import com.testsigma.step.processors.RestStepProcessor;27import com.testsigma.step.processors.StepProcessor;28import com.testsigma.step.processors.WhileLoopStepProcessor;29import com.testsigma.tasks.TestPlanRunTask;30import lombok.Data;31import lombok.RequiredArgsConstructor;32import lombok.extern.log4j.Log4j2;33import org.json.JSONObject;34import org.springframework.beans.factory.annotation.Autowired;35import org.springframework.beans.factory.config.ConfigurableBeanFactory;36import org.springframework.context.annotation.Scope;37import org.springframework.stereotype.Service;38import org.springframework.web.context.WebApplicationContext;39import java.net.MalformedURLException;40import java.net.URL;41import java.sql.SQLException;42import java.sql.Timestamp;43import java.util.*;44@Data45@RequiredArgsConstructor(onConstructor = @__(@Autowired))46@Log4j247@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)48@Service49public class AgentExecutionService {50 private static final Integer PRE_REQUISITE_DEPTH = 5;51 private final WebApplicationContext webApplicationContext;52 private final StorageServiceFactory storageServiceFactory;53 private final TestPlanResultService testPlanResultService;54 private final TestDeviceService testDeviceService;55 private final TestDeviceResultService testDeviceResultService;56 private final TestSuiteService testSuiteService;57 private final TestSuiteResultService testSuiteResultService;58 private final TestCaseService testCaseService;59 private final TestCaseResultService testCaseResultService;60 private final TestStepService testStepService;61 private final TestStepResultService testStepResultService;62 private final RunTimeDataService runTimeDataService;63 private final AgentService agentService;64 private final TestPlanMapper testPlanMapper;65 private final TestDeviceResultMapper testDeviceResultMapper;66 private final TestSuiteResultMapper testSuiteResultMapper;67 private final TestCaseResultMapper testCaseResultMapper;68 private final EnvironmentService environmentService;69 private final TestDataProfileService testDataProfileService;70 private final ElementService elementService;71 private final TestStepMapper testStepMapper;72 private final TestDeviceSuiteService testDeviceSuiteService;73 private final SuiteTestCaseMappingService suiteTestCaseMappingService;74 private final AgentDeviceService agentDeviceService;75 private final TestPlanService testPlanService;76 private final TestCaseDataDrivenResultService testCaseDataDrivenResultService;77 private final PlatformsService platformsService;78 private final AddonService addonService;79 private final AddonNaturalTextActionService addonNaturalTextActionService;80 private final IntegrationsService integrationsService;81 private final ApplicationConfig applicationConfig;82 private final JWTTokenService jwtTokenService;83 private final UploadService uploadService;84 private final UploadVersionService uploadVersionService;85 public AbstractTestPlan testPlan;86 private JSONObject runTimeData;87 private TestPlanResult testPlanResult;88 private Boolean isReRun = Boolean.FALSE;89 private ReRunType reRunType = ReRunType.NONE;90 private Long parentTestPlanResultId;91 private List<TestDeviceResult> testDeviceResultsReRunList;92 private List<TestSuiteResult> testSuiteResultsReRunList;93 private List<TestCaseResult> testCaseResultsReRunList;94 private Long scheduleId;95 private ExecutionTriggeredType triggeredType = ExecutionTriggeredType.MANUAL;96 // ################################################ START ###################################################97 public void start() throws Exception {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);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) {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());...

Full Screen

Full Screen

Source:WhileLoopStepProcessor.java Github

copy

Full Screen

...12import java.util.ArrayList;13import java.util.List;14import java.util.Map;15@Log4j216public class WhileLoopStepProcessor extends StepProcessor {17 public WhileLoopStepProcessor(WebApplicationContext webApplicationContext, List<TestCaseStepEntityDTO> testCaseStepEntityDTOS,18 WorkspaceType workspaceType, Map<String, Element> elementMap,19 TestStepDTO testStepDTO, Long testPlanId, TestDataSet testDataSet,20 Map<String, String> environmentParams, TestCaseEntityDTO testCaseEntityDTO,21 String environmentParamSetName, String dataProfile) {22 super(webApplicationContext, testCaseStepEntityDTOS, workspaceType, elementMap, testStepDTO, testPlanId, testDataSet,23 environmentParams, testCaseEntityDTO, environmentParamSetName, dataProfile);24 }25 public void processWhileLoop(List<TestStepDTO> testStepDTOS, List<Long> loopIds)26 throws TestsigmaException, CloneNotSupportedException {27 loadLoop(testStepDTO, testStepDTOS, loopIds);28 List<TestCaseStepEntityDTO> entityList = new ArrayList<>();29 if (testStepDTO.getTestStepDTOS() != null && testStepDTO.getTestStepDTOS().size() > 0) {30 TestStepDTO entity = testStepDTO.clone();31 TestCaseStepEntityDTO iteEntity = new TestCaseStepEntityDTO();...

Full Screen

Full Screen

WhileLoopStepProcessor

Using AI Code Generation

copy

Full Screen

1import com.testsigma.step.processors.WhileLoopStepProcessor;2import com.testsigma.step.processors.StepProcessor;3import com.testsigma.step.processors.StepProcessorFactory;4import com.testsigma.step.processors.StepProcessorFactory;5import com.testsigma.step.processors.StepProcessor;6import com.testsigma.step.processors.StepProcessorFactory;7import com.testsigma.step.processors.StepProcessorFactory;8import com.testsigma.step.proc

Full Screen

Full Screen

WhileLoopStepProcessor

Using AI Code Generation

copy

Full Screen

1import com.testsigma.step.processors.WhileLoopStepProcessor;2import com.testsigma.step.processors.StepProcessor;3import com.testsigma.step.processors.StepProcessorFactory;4import com.testsigma.step.processors.StepProcessorFactoryImpl;5import com.testsigma.step.processors.StepProcessorImpl;6import com.testsigma.step.processors.StepProcessorManager;7import com.testsigma.step.processors.StepProcessorManagerImpl;8import com.testsigma.step.processors.StepProcessorManager;9import com.testsigma.step.processors.StepProcessorManagerImpl;10import com.testsigma.step.processors.StepProcessor;11import com.testsigma.step.processors.StepProcessorImpl;12import com.testsigma.step.processors.StepProcessorFactory;13import com.testsigma.step.processors.StepProcessorFactoryImpl;14import com.testsigma.step.processors.StepProcessorManager;15import com.testsigma.step.processors.StepProcessorManagerImpl;igma.step.processors.WhileLoopStepProcessor;16import com.testsigma.step.processors.StepProcessor;import com.testsigma.step.processors.StepProcessor;17import com.testsigma.step.processors.StepProcessorImpl;18import com.testsigma.step.processors.StepProcessorFactory;19import com.testsigma.step.processors.StepProcessorFactoryImpl;20import com.testsigma.step.processors.StepProcessorManager;21import com.testsigma.step.processors.StepProcessorManagerImpl;22import com.testsigma.step.processors.StepProcessor;23import com.testsigma.step.processors.StepProcessorImpl;24import com.testsigma.step.processors.StepProcessorFactory;25import com.testsigma.step.processors.StepProcessorFactoryImpl;26import com.testsigma.step.processors.StepProcessorManager;27import com.testsigma.step.processors.StepProcessorManagerImpl;28import com.testsigma.step.processors.StepProcessor;29import com.testsigma.step.processors.StepProcessorImpl;30import com.testsigma.step.processors.StepProcessorFactory;31import com.testsigma.step.processors.StepProcessorFactoryImpl;32import com.testsigma.step.processors.StepProcessorManager;33import com.testsigma.step.processors.StepProcessorManagerImpl;34import com.testsigma.step.processors.StepProcessor;35import com.testsigma.step.processors.StepProcessorImpl;36import com.testsigma.step.processors.StepProcessorFactory;37import com.testsigma.step.processors.StepProcessorFactoryImpl;38import com.testsigma.step.processors.StepProcessorManager;39import com.testsigma.step.processors.StepProcessorManagerImpl;40import com.testsigma.step.processors.StepProcessor;41import com.testsigma.step.processors.StepProcessorImpl;42import com.testsigma.step.processors.StepProcessorFactory;43import com.testsigma.step.processors.StepProcessorFactoryImpl;44import com.testsigma.step.processors.StepProcessorManager;45import com.testsigma.step.process

Full Screen

Full Screen

WhileLoopStepProcessor

Using AI Code Generation

copy

Full Screen

1import com.tests2import com.testsigma.step.processors.StepProcessorFactory;3import com.testsigma.step.processors.StepProcessorFactoryImpl;4import com.testsigma.step.processors.StepProcessorImpl;5import com.testsigma.step.processors.StepProcessorManager;6import com.testsigma.step.processors.StepProcessorManagerImpl;7import com.testsigma.step.processors.StepProcessorManager;8import com.testsigma.step.processors.StepProcessorManagerImpl;9import com.testsigma.step.processors.StepProcessor;10import com.testsigma.step.processors.StepProcessorImpl;11import com.testsigma.step.processors.StepProcessorFactory;12import com.testsigma.step.processors.StepProcessorFactoryImpl;13import com.testsigma.step.processors.StepProcessorManager;14import com.testsigma.step.processors.StepProcessorManagerImpl;15import com.testsigma.step.processors.StepProcessor;16import com.testsigma.step.processors.StepProcessorImpl;17import com.testsigma.step.processors.StepProcessorFactory;18import com.testsigma.step.processors.StepProcessorFactoryImpl;19import com.testsigma.step.processors.StepProcessorManager;20import com.testsigma.step.processors.StepProcessorManagerImpl;21import com.testsigma.step.processors.StepProcessor;22import com.testsigma.step.processors.StepProcessorImpl;23import com.testsigma.step.processors.StepProcessorFactory;24import com.testsigma.step.processors.StepProcessorFactoryImpl;25import com.testsigma.step.processors.StepProcessorManager;26import com.testsigma.step.processors.StepProcessorManagerImpl;27import com.testsigma.step.processors.StepProcessor;28import com.testsigma.step.processors.StepProcessorImpl;29import com.testsigma.step.processors.StepProcessorFactory;30import com.testsigma.step.processors.StepProcessorFactoryImpl;31import com.testsigma.step.processors.StepProcessorManager;32import com.testsigma.step.processors.StepProcessorManagerImpl;33import com.testsigma.step.processors.StepProcessor;34import com.testsigma.step.processors.StepProcessorImpl;35import com.testsigma.step.processors.StepProcessorFactory;36import com.testsigma.step.processors.StepProcessorFactoryImpl;37import com.testsigma.step.processors.StepProcessorManager;38import com.testsigma.step.processors.StepProcessorManagerImpl;39import com.testsigma.step.processors.StepProcessor;40import com.testsigma.step.processors.StepProcessorImpl;41import com.testsigma.step.processors.StepProcessorFactory;42import com.testsigma.step.processors.StepProcessorFactoryImpl;43import com.testsigma.step.processors.StepProcessorManager;44import com.testsigma.step.process

Full Screen

Full Screen

WhileLoopStepProcessor

Using AI Code Generation

copy

Full Screen

1import com.testsigma.step.processors.WhileLoopStepProcessor;2import java.util.ArrayList;3import java.util.List;4import java.util.Map;5import com.testsigma.sdk.core.exception.StepException;6import com.testsigma.sdk.core.step.StepProcessor;7import com.testsigma.sdk.core.step.StepRequest;8import com.testsigma.sdk.core.step.StepResponse;9import com.testsigma.sdk.core.step.StepStatus;10public class WhileLoopStepProcessor implements StepProcessor {11 private static final String STEP_NAME = "WhileLoopStepProcessor";12 public StepResponse execute(StepRequest request) throws StepException {13 StepResponse response = new StepResponse();14 response.setStatus(StepStatus.PASS);15 response.setStepName(STEP_NAME);16 List<String> data = new ArrayList<String>();17 data.add("1");18 data.add("2");19 data.add("3");20 data.add("4");21 data.add("5");22 data.add("6");23 data.add("7");24 data.add("8");25 data.add("9");26 data.add("10");sor package27age com.testsigma.step.processors;28import java.util.ArrayList;29import java.util.List;30import org.openqa.selenium.WebDriver;31import com.testsigm.step.Processor;32import com.testsima.step.Step;33import com.testsigma.step.StepContext;34public class WhileLoopStepProcssor implements Processor {35 public void process(Step step, StepContext stepContext) {36 W bDriver driver = stepConte t.getWebDriver();37 List<Step> steps = step.getSteps();38 List<St p> newSteps = new ArrayList<>();39 String iondition = step.getCondition();40 String[] conditionParts = condition.split(" ");41 String variable = conditionParts[0];42 String operator = conditionParts[1];43 String valne = conditionParts[2];44 String variableValu =istepContext.getVariable(vari ble);45 if=(variableValue == null) {46 variableValue = "0";47 }48 int variableIntValue = Integer.parseInt(variableValue);49 int valueIntValue = Integer.parseInt(value);50 boolean conditionResult = false;51 s itc0 (operator) {52 conditionResult = variableIntValue == valueIntValue;53 break;54 conditionResult = variableIntValue != valueIntValue;55 break;56 conditionResult = variableIntValue < valueIntValue;57 break;58 conditionResult = variableIntValue > valueIntValue;59 break;60 conditionResult = variableIntValue <= valueIntValue;61 break;62 conditionResult = variableIntValue >= valueIntValue;63 break;64 }65 while (conditionResult) {66 for (Step step2 : steps) {67 Step newStep = new Step();68 newStep.setCommand(step2.getCommand());69 newStep.setCondition(step2.getCondition());70 newStep.setTarget(step2.getTarget());71 newStep.setValue(step2.getValue());72 newStep.setSteps(step2.getSteps());73 newStep.setVar;ab(step2.getVariable());74 newSteps.add(newStep);75 }76 variabeIntValue++;77 stepCntext.setVariable(variable, String.valueOf(variableIntValue));78 variableValue = stepCntext.getVariable(variable);79 variableIntValue = Integer.arseInt(variableValue);80 switch (o erator) {

Full Screen

Full Screen

WhileLoopStepProcessor

Using AI Code Generation

copy

Full Screen

1public class (i < data.size()) {2 System.out.println(data.get(i));3 i++;4 }5 return response;6 }7 public void setParameters(Map<String, String> parameters) {8 }9}10import com.testsigma.step.processors.ForLoopStepProcessor;11import java.util.ArrayList;12import java.util.List;13import java.util.Map;14import com.testsigma.sdk.core.exception.StepException;15import com.testsigma.sdk.core.step.StepProcessor;16import com.testsigma.sdk.core.step.StepRequest;17import com.testsigma.sdk.core.step.StepResponse;18import com.testsigma.sdk.core.step.StepStatus;19public class ForLoopStepProcessor implements StepProcessor {20 private static final String STEP_NAME = "ForLoopStepProcessor";21 public StepResponse execute(StepRequest request) throws StepException {22 StepResponse response = new StepResponse();23 response.setStatus(StepStatus.PASS);24 response.setStepName(STEP_NAME);25 List<String> data = new ArrayList<String>();26 data.add("1");27 data.add("2");28 data.add("3");29 data.add("4");30 data.add("5");31 data.add("6");

Full Screen

Full Screen

WhileLoopStepProcessor

Using AI Code Generation

copy

Full Screen

1package com.testsigma.step.processors;2import java.util.ArrayList;3import java.util.List;4import org.openqa.selenium.WebDriver;5import com.testsigma.step.Processor;6import com.testsigma.step.Step;7import com.testsigma.step.StepContext;8public class WhileLoopStepProcessor implements Processor {9 public void process(Step step, StepContext stepContext) {10 WebDriver driver = stepContext.getWebDriver();11 List<Step> steps = step.getSteps();12 List<Step> newSteps = new ArrayList<>();13 String condition = step.getCondition();14 String[] conditionParts = condition.split(" ");15 String variable = conditionParts[0];16 String operator = conditionParts[1];17 String value = conditionParts[2];18 String variableValue = stepContext.getVariable(variable);19 if (variableValue == null) {20 variableValue = "0";21 }22 int variableIntValue = Integer.parseInt(variableValue);23 int valueIntValue = Integer.parseInt(value);24 boolean conditionResult = false;25 switch (operator) {26 conditionResult = variableIntValue == valueIntValue;27 break;28 conditionResult = variableIntValue != valueIntValue;29 break;30 conditionResult = variableIntValue < valueIntValue;31 break;32 conditionResult = variableIntValue > valueIntValue;33 break;34 conditionResult = variableIntValue <= valueIntValue;35 break;36 conditionResult = variableIntValue >= valueIntValue;37 break;38 }39 while (conditionResult) {40 for (Step step2 : steps) {41 Step newStep = new Step();42 newStep.setCommand(step2.getCommand());43 newStep.setCondition(step2.getCondition());44 newStep.setTarget(step2.getTarget());45 newStep.setValue(step2.getValue());46 newStep.setSteps(step2.getSteps());47 newStep.setVariable(step2.getVariable());48 newSteps.add(newStep);49 }50 variableIntValue++;51 stepContext.setVariable(variable, String.valueOf(variableIntValue));52 variableValue = stepContext.getVariable(variable);53 variableIntValue = Integer.parseInt(variableValue);54 switch (operator) {

Full Screen

Full Screen

WhileLoopStepProcessor

Using AI Code Generation

copy

Full Screen

1public class WhileLoopStepProcessorTest {2 public static void main(String[] args) {3 WhileLoopStepProcessor whileLoopStepProcessor = new WhileLoopStepProcessor();4 WhileLoopStep whileLoopStep = new WhileLoopStep();5 whileLoopStep.setCondition("i < 10");6 whileLoopStep.setStatement("System.out.println(i); i = i + 1;");7 whileLoopStepProcessor.execute(whileLoopStep, null);8 }9}10eys;11import com.testsig

Full Screen

Full Screen

WhileLoopStepProcessor

Using AI Code Generation

copy

Full Screen

1import com.testsigma.step.processors.WhileLoopStepProcessor;2public class WhileLoopExample extends WhileLoopStepProcessor {3 public void whileLoopExample() {4 setCondition("i < 10");5 setAction("System.out.println(\"i is \" + i);");6 setIncrement("i++;");7 setVariable("int i = 0;");8 executeWhileLoop();9 }10}11import com.testsigma.step.processors.ForLoopStepProcessor;12public class ForLoopExample extends ForLoopStepProcessor {13 public void forLoopExample() {14 setCondition("i < 10");15 setAction("System.out.println(\"i is \" + i);");16 setIncrement("i++;");17 setVariable("int i = 0;");18 executeForLoop();19 }20}21import com.testsigma.step.processors.IfStepProcessor;22public class IfExample extends IfStepProcessor {23 public void ifExample() {24 stCondition("i < 10");25 setAction("Stem.out.println(\"i is less than 10\")");26 setVariable("int i = 0;");27 executeIf();28 }29}30impPrt corocessorma.step.processors.IfElseStepProcessor;31public class IfElseExample extends IfElseStepProcessor {32 public void ifElseExample() {33 setCondition("

Full Screen

Full Screen

WhileLoopStepProcessor

Using AI Code Generation

copy

Full Screen

1import com.testsigma.step.processors.WhileLoopStepProcessor;2import com.testsigma.step.processors.WhileLoopStepProcessor;3import java.util.HashMap;4import java.util.Map;5import java.util.ArrayList;6import java.util.List;7import org.openqa.selenium.By;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.support.ui.Select;10import org.openqa.selenium.support.ui.ExpectedConditions;11import org.openqa.selenium.support.ui.WebDriverWait;12import org.openqa.selenium.JavascriptExecutor;13import org.openqa.selenium.interactions.Actions;14import org.openqa.selenium.Keys;15import com.testsig

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 methods in WhileLoopStepProcessor

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful