Best Testsigma code snippet using com.testsigma.automator.entity.TestCaseResult
Source:TestsuiteRunner.java
...23@Log4j224@Data25public abstract class TestsuiteRunner {26 protected Map<Long, TestSuiteResult> groupResultMap = new HashMap<Long, TestSuiteResult>();27 protected Map<Long, TestCaseResult> testcaseResultMap = new HashMap<Long, TestCaseResult>();28 protected Map<Long, TestCaseStepResult> mapStepResult = new HashMap<Long, TestCaseStepResult>();29 protected TestDeviceEntity testDeviceEntity;30 protected EnvironmentRunResult environmentRunResult;31 protected TestPlanRunSettingEntity testPlanRunSettingEntity;32 protected TestDeviceSettings testDeviceSettings;33 protected String testPlanId;34 protected WorkspaceType workspaceType;35 protected boolean skipExecution;36 protected String resultFailureMessage;37 private HttpClient httpClient;38 private int testCaseFetchWaitInterval;39 private int testCaseFetchMaxTries;40 public TestsuiteRunner() {41 this.testDeviceEntity = EnvironmentRunner.getRunnerEnvironmentEntity();42 this.environmentRunResult = EnvironmentRunner.getRunnerEnvironmentRunResult();43 this.testPlanRunSettingEntity = testDeviceEntity.getTestPlanSettings();44 this.testDeviceSettings = testDeviceEntity.getEnvSettings();45 this.testPlanId = EnvironmentRunner.getRunnerExecutionId();46 this.workspaceType = testDeviceEntity.getWorkspaceType();47 this.httpClient = EnvironmentRunner.getWebAppHttpClient();48 this.skipExecution = false;49 this.resultFailureMessage = null;50 this.testCaseFetchWaitInterval = AutomatorConfig.getInstance().getTestCaseFetchWaitInterval();51 this.testCaseFetchMaxTries = AutomatorConfig.getInstance().getTestCaseDefaultMaxTries();52 }53 public EnvironmentRunResult runSuites(List<TestSuiteEntity> testCaseGroupEntities) throws AutomatorException {54 log.debug("----- Running Test Suites For Environment Run Result [" + environmentRunResult.getId() + "] -----");55 List<TestSuiteResult> testCaseGroupsResults = new ArrayList<TestSuiteResult>();56 environmentRunResult.setGroupResults(testCaseGroupsResults);57 ResultConstant result = ResultConstant.SUCCESS;58 for (TestSuiteEntity testSuiteEntity : testCaseGroupEntities) {59 skipExecution = false;60 resultFailureMessage = null;61 TestSuiteResult testSuiteResult = new TestSuiteResult();62 testSuiteResult.setId(testSuiteEntity.getResultId());63 testSuiteResult.setGroupId(testSuiteEntity.getId());64 testSuiteResult.setEnvRunId(testSuiteEntity.getEnvironmentResultId());65 testSuiteResult.setExecutionInitiatedOn(environmentRunResult.getExecutionInitiatedOn());66 testSuiteResult.setAgentPickedOn(environmentRunResult.getAgentPickedOn());67 testSuiteResult.setDeviceAllocatedOn(environmentRunResult.getDeviceAllocatedOn());68 testCaseGroupsResults.add(testSuiteResult);69 groupResultMap.put(testSuiteEntity.getId(), testSuiteResult);70 testSuiteResult.setStartTime(new Timestamp(System.currentTimeMillis()));71 try {72 log.debug("Running Test Suite - " + testSuiteEntity);73 try {74 checkSuitePrerequisiteFailure(testSuiteEntity, testSuiteResult);75 if (ExecutionEnvironmentRunner.isRunning()) {76 log.debug("Execution environment status is running...Proceeding with the test suite execution....");77 runSuite(testSuiteEntity, testSuiteResult);78 } else {79 log.debug("Execution environment status is stopped...stopping test suite execution....");80 testSuiteResult.setResult(ResultConstant.STOPPED);81 testSuiteResult.setMessage(AutomatorMessages.MSG_USER_ABORTED_EXECUTION);82 testSuiteResult.setEndTime(new Timestamp(System.currentTimeMillis()));83 postSuiteResult(testSuiteResult);84 break;85 }86 } catch (Exception ex) {87 log.error(ex.getMessage(), ex);88 testSuiteResult.setResult(ResultConstant.FAILURE);89 testSuiteResult.setMessage(ex.getMessage());90 }91 testSuiteResult.setEndTime(new Timestamp(System.currentTimeMillis()));92 postSuiteResult(testSuiteResult);93 } catch (Exception ex) {94 log.error("Unhandled exception while processing test suite");95 log.error(ex.getMessage(), ex);96 testSuiteResult.setEndTime(new Timestamp(System.currentTimeMillis()));97 testSuiteResult.setResult(ResultConstant.FAILURE);98 testSuiteResult.setMessage(ex.getMessage());99 try {100 postSuiteResult(testSuiteResult);101 } catch (Exception e) {102 log.error("Unhandled exception while sending test suite results");103 log.error(e.getMessage(), e);104 }105 }106 if (testSuiteResult.getResult().getId() > result.getId()) {107 result = testSuiteResult.getResult();108 }109 }110 if (environmentRunResult.getResult() == null) {111 environmentRunResult.setResult(result);112 }113 return environmentRunResult;114 }115 public abstract void startSession(Long entityId, DriverSessionType driverSessionType) throws AutomatorException;116 public void endSession() throws AutomatorException {117 DriverManager driverManager = DriverManager.getDriverManager();118 if (driverManager != null) {119 driverManager.endSession();120 }121 }122 private void populateThreadContextData(TestSuiteEntity testSuiteEntity123 , TestSuiteResult testSuiteResult) {124 ThreadContext.put("TEST_SUITE", testSuiteEntity.getId() + "");125 ThreadContext.put("TEST_SUITE_RESULT", testSuiteResult.getId() + "");126 }127 private void resetThreadContextData() {128 ThreadContext.put("TEST_SUITE", "");129 ThreadContext.put("TEST_SUITE_RESULT", "");130 }131 private void runSuite(TestSuiteEntity testSuiteEntity, TestSuiteResult testSuiteResult) throws AutomatorException {132 resetThreadContextData();133 populateThreadContextData(testSuiteEntity, testSuiteResult);134 log.debug("Running test suite - " + testSuiteEntity.getName());135 if (!testDeviceEntity.getCreateSessionAtCaseLevel()) {136 restartCurrentSession(testSuiteResult);137 }138 List<TestCaseEntity> testCaseEntityList = testSuiteEntity.getTestCases();139 List<TestCaseResult> testCasesResult = new ArrayList<>();140 testSuiteResult.setTestCaseResults(testCasesResult);141 testSuiteResult.setResult(ResultConstant.SUCCESS);142 boolean executionStarted = false;143 for (TestCaseEntity testCaseEntity : testCaseEntityList) {144 boolean testCaseRunFailed = false;145 boolean testCasePrerequisiteFailed = false;146 TestCaseResult testCaseResult = new TestCaseResult(testCaseEntity.getId());147 try {148 testCaseResult.setId(testCaseEntity.getTestCaseResultId());149 testCaseResult.setEnvRunId(testSuiteEntity.getEnvironmentResultId());150 testCaseResult.setGroupResultId(testSuiteEntity.getResultId());151 testCaseResult.setGroupId(testSuiteEntity.getId());152 testCaseResult.setTestCaseId(testCaseEntity.getId());153 testCaseResult.setTestDataSetName(testCaseEntity.getTestDataSetName());154 testCaseResult.setTestDataId(testCaseEntity.getTestDataId());155 testCaseResult.setIsStepGroup(testCaseEntity.getIsStepGroup());156 testCaseResult.setDataDriven(testCaseEntity.getIsDataDriven());157 testCaseResult.setStartTime(new Timestamp(System.currentTimeMillis()));158 testCasesResult.add(testCaseResult);159 testCaseResult.setVisualTestingEnabled(testPlanRunSettingEntity.isVisualTestingEnabled());160 testcaseResultMap.put(testCaseEntity.getId(), testCaseResult);161 if (skipExecution) {162 testCaseResult.setMessage(resultFailureMessage);163 } else if (hasPreRequisite(testCaseEntity)) {164 testCasePrerequisiteFailed = checkTestCasePrerequisiteFailure(testCaseEntity, testCaseResult);165 }166 try {167 if (!testCaseEntity.getIsDataDriven()) {168 testCaseEntity = getTestCase(testCaseEntity, this.testCaseFetchMaxTries);169 new ErrorUtil().checkError(testCaseEntity.getErrorCode(), testCaseEntity.getMessage());170 }171 } catch (TestsigmaNoParallelRunException e) {172 log.error(e.getMessage(), e);173 testCaseRunFailed = true;174 resultFailureMessage = e.getMessage();175 testCaseResult.setResult(ResultConstant.STOPPED);176 testCaseResult.setMessage(resultFailureMessage);177 } catch (AutomatorException e) {178 log.error(e.getMessage(), e);179 testCaseRunFailed = true;180 resultFailureMessage = e.getMessage();181 testCaseResult.setResult(ResultConstant.FAILURE);182 testCaseResult.setMessage(resultFailureMessage);183 }184 if (!testCaseRunFailed) {185 if (ExecutionEnvironmentRunner.isRunning()) {186 testSuiteResult.setSessionCreatedOn(new Timestamp(System.currentTimeMillis()));187 if (testCaseEntity.getIsDataDriven()) {188 runDataDrivenTestCase(testCaseEntity, testCaseResult, false, testCasePrerequisiteFailed);189 } else {190 new TestcaseRunner(testCaseEntity, testCaseResult, mapStepResult,191 skipExecution || testCasePrerequisiteFailed, resultFailureMessage)192 .run();193 }194 executionStarted = true;195 } else {196 testCaseResult.setResult(ResultConstant.STOPPED);197 testCaseResult.setMessage(AutomatorMessages.MSG_USER_ABORTED_EXECUTION);198 testCaseResult.setEndTime(new Timestamp(System.currentTimeMillis()));199 postTestcaseResult(testCaseResult);200 break;201 }202 }203 testCaseResult.setEndTime(new Timestamp(System.currentTimeMillis()));204 postTestcaseResult(testCaseResult);205 } catch (Exception ex) {206 log.error("Unhandled exception while processing test case");207 log.error(ex.getMessage(), ex);208 testCaseResult.setResult(ResultConstant.ABORTED);209 testCaseResult.setMessage(ex.getMessage());210 try {211 postTestcaseResult(testCaseResult);212 } catch (Exception e) {213 log.error("Unhandled exception while posting test case results");214 log.error(e.getMessage(), e);215 }216 }217 if (testCaseResult.getResult().getId() > testSuiteResult.getResult().getId()) {218 testSuiteResult.setResult(testCaseResult.getResult());219 }220 }221 testSuiteResult.setSessionCompletedOn(new Timestamp(System.currentTimeMillis()));222 testSuiteResult.setEndTime(new Timestamp(System.currentTimeMillis()));223 if (testSuiteResult.getResult() == ResultConstant.SUCCESS) {224 testSuiteResult.setMessage(AutomatorMessages.MSG_GROUP_SUCCESS);225 } else if (StringUtils.isBlank(testSuiteResult.getMessage())) {226 testSuiteResult.setMessage(AutomatorMessages.MSG_GROUP_FAILED);227 }228 resetThreadContextData();229 }230 private void restartCurrentSession(TestSuiteResult testSuiteResult) {231 if (workspaceType.equals(WorkspaceType.Rest)) {232 return;233 }234 DriverManager driverManager = DriverManager.getDriverManager();235 if (driverManager.isRestart() && (driverManager.getRestartSessionId() != null)) {236 try {237 log.info("Found that driver session restarted while executing a test suite. Storing session ID " +238 "in test suite result tables. Test Suite Result - " + testSuiteResult.getId());239 driverManager.storeSessionId(DriverSessionType.TEST_SUITE_SESSION, testSuiteResult.getId());240 } catch (Exception e) {241 log.error(e.getMessage(), e);242 }243 }244 }245 public void runDataDrivenTestCase(TestCaseEntity testCaseEntity, TestCaseResult testCaseResult,246 boolean testCaseRunFailed, boolean testCasePrerequisiteFailed) throws Exception {247 ResultConstant dataDrivenStatus = ResultConstant.SUCCESS;248 for (TestCaseEntity dataDrivenTestCase : testCaseEntity.getDataDrivenTestCases()) {249 TestCaseResult dataDrivenTestCaseResult = new TestCaseResult(dataDrivenTestCase.getId());250 dataDrivenTestCaseResult.setId(getResultId(testCaseEntity, dataDrivenTestCase.getTestDataSetName()));251 dataDrivenTestCaseResult.setGroupId(testCaseResult.getGroupId());252 dataDrivenTestCaseResult.setEnvRunId(environmentRunResult.getId());253 dataDrivenTestCaseResult.setGroupResultId(testCaseResult.getGroupResultId());254 dataDrivenTestCaseResult.setParentId(testCaseResult.getId());255 dataDrivenTestCaseResult.setTestDataSetName(dataDrivenTestCase.getTestDataSetName());256 dataDrivenTestCaseResult.setTestDataId(testCaseEntity.getTestDataId());257 dataDrivenTestCaseResult.setStartTime(new Timestamp(System.currentTimeMillis()));258 dataDrivenTestCaseResult.setVisualTestingEnabled(testCaseResult.isVisualTestingEnabled());259 testCaseResult.getTestCaseResults().add(dataDrivenTestCaseResult);260 try {261 dataDrivenTestCase = getTestCase(dataDrivenTestCase, this.testCaseFetchMaxTries);262 new ErrorUtil().checkError(dataDrivenTestCase.getErrorCode(), dataDrivenTestCase.getMessage());263 } catch (AutomatorException e) {264 log.error(e.getMessage(), e);265 if (!(skipExecution || testCasePrerequisiteFailed)) {266 testCaseRunFailed = true;267 resultFailureMessage = e.getMessage();268 dataDrivenTestCaseResult.setResult(ResultConstant.FAILURE);269 dataDrivenTestCaseResult.setMessage(resultFailureMessage);270 }271 }272 if (!(testCaseRunFailed || testCasePrerequisiteFailed)) {273 if (ExecutionEnvironmentRunner.isRunning()) {274 new TestcaseRunner(dataDrivenTestCase, dataDrivenTestCaseResult, mapStepResult,275 skipExecution || testCasePrerequisiteFailed, resultFailureMessage).run();276 boolean isFailed = (ResultConstant.SUCCESS != dataDrivenTestCaseResult.getResult());277 if (skipExecution) {278 dataDrivenTestCaseResult.setResult(testCaseResult.getResult());279 dataDrivenTestCaseResult.setMessage(testCaseResult.getMessage());280 } else if (isFailed == dataDrivenTestCase.getExpectedToFail()) {281 dataDrivenTestCaseResult.setResult(ResultConstant.SUCCESS);282 } else {283 dataDrivenTestCaseResult.setResult(ResultConstant.FAILURE);284 }285 } else {286 dataDrivenTestCaseResult.setResult(ResultConstant.STOPPED);287 dataDrivenTestCaseResult.setMessage(AutomatorMessages.MSG_USER_ABORTED_EXECUTION);288 dataDrivenTestCaseResult.setEndTime(new Timestamp(System.currentTimeMillis()));289 postTestcaseResult(dataDrivenTestCaseResult);290 break;291 }292 } else if (testCasePrerequisiteFailed) {293 dataDrivenTestCaseResult.setResult(testCaseResult.getResult());294 dataDrivenTestCaseResult.setMessage(testCaseResult.getMessage());295 }296 dataDrivenStatus = (dataDrivenTestCaseResult.getResult().getId() > dataDrivenStatus.getId()) ?297 dataDrivenTestCaseResult.getResult() : dataDrivenStatus;298 dataDrivenTestCaseResult.setEndTime(ObjectUtils.defaultIfNull(dataDrivenTestCaseResult.getEndTime(),299 new Timestamp(System.currentTimeMillis())));300 postTestcaseResult(dataDrivenTestCaseResult);301 }302 testCaseResult.setResult(ObjectUtils.defaultIfNull(testCaseResult.getResult(), dataDrivenStatus));303 if (testCaseResult.getResult() == ResultConstant.SUCCESS) {304 testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_SUCCESS);305 } else if (StringUtils.isBlank(testCaseResult.getMessage())) {306 testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_FAILURE);307 }308 }309 private TestCaseEntity getTestCase(TestCaseEntity testCaseEntity, int maxTries) throws AutomatorException {310 try {311 TestCaseEntity testCaseEntityCopy = testCaseEntity;312 testCaseEntity = AutomatorConfig.getInstance().getAppBridge().getTestCase(environmentRunResult.getId(),313 testCaseEntity);314 if (testCaseEntity != null) {315 if (ResultConstant.STOPPED == testCaseEntity.getResult()) {316 ExecutionEnvironmentRunner.setStoppedStatus();317 }318 }319 if ((testCaseEntity.getErrorCode() != null) && maxTries > 0) {320 RemoteWebDriver remoteWebDriver = DriverManager.getDriverManager().getDriver().getRemoteWebDriver();321 remoteWebDriver.getWindowHandle();322 Thread.sleep(this.testCaseFetchWaitInterval);323 return getTestCase(testCaseEntityCopy, maxTries - 1);324 }325 return testCaseEntity;326 } catch (Exception e) {327 log.error(e.getMessage(), e);328 throw new AutomatorException(ErrorCodes.TEST_CASE_DETAILS_FETCH_FAILED,329 AutomatorMessages.FAILED_TO_FETCH_TEST_CASE_DETAILS + " - " + e.getMessage());330 }331 }332 private Long getResultId(TestCaseEntity entityList, String iteration) {333 for (TestCaseEntity entity : entityList.getDataDrivenTestCases()) {334 if (entity.getTestDataSetName() != null && entity.getTestDataSetName().equals(iteration)) {335 return entity.getTestCaseResultId();336 }337 }338 return null;339 }340 public void postTestcaseResult(TestCaseResult testCaseResult) throws Exception {341 AutomatorConfig.getInstance().getAppBridge().postTestCaseResult(testCaseResult);342 }343 public void postSuiteResult(TestSuiteResult testSuiteResult) throws Exception {344 AutomatorConfig.getInstance().getAppBridge().postTestSuiteResult(testSuiteResult);345 }346 private boolean hasPreRequisite(TestSuiteEntity testSuiteEntity) {347 boolean hasPreRequisite = false;348 if (testSuiteEntity.getPreRequisite() != null) {349 if (testSuiteEntity.getPreRequisite() > 0) {350 hasPreRequisite = true;351 } else if (testSuiteEntity.getPreRequisite() == 0) {352 log.error("Test Case Group entity found with 0 as value for prerequisite");353 }354 }355 return hasPreRequisite;356 }357 private boolean hasPreRequisite(TestCaseEntity testCaseEntity) {358 boolean hasPreRequisite = false;359 if (testCaseEntity.getPreRequisite() != null) {360 if (testCaseEntity.getPreRequisite() > 0) {361 hasPreRequisite = true;362 } else if (testCaseEntity.getPreRequisite() == 0) {363 log.error("Test Case entity found with 0 as value for prerequisite");364 }365 }366 return hasPreRequisite;367 }368 private void checkSuitePrerequisiteFailure(TestSuiteEntity testSuiteEntity,369 TestSuiteResult testSuiteResult) {370 boolean hasPrerequisite = hasPreRequisite(testSuiteEntity);371 if (hasPrerequisite) {372 TestSuiteResult prerequisiteTestSuiteResult = groupResultMap.get(testSuiteEntity.getPreRequisite());373 log.debug("Found a prerequisite for the test suite. Checking its result - " + prerequisiteTestSuiteResult);374 boolean prerequisiteFailed = ((prerequisiteTestSuiteResult == null)375 || (ResultConstant.SUCCESS != prerequisiteTestSuiteResult.getResult()));376 if (prerequisiteFailed) {377 testSuiteResult.setResult(ResultConstant.FAILURE);378 testSuiteResult.setMessage(AutomatorMessages.MSG_GROUP_PRE_REQUISITE_FAILED);379 if (testPlanRunSettingEntity.getOnSuitePreRequisiteFail() == PreRequisiteAction.Abort) {380 testSuiteResult.setEndTime(new Timestamp(System.currentTimeMillis()));381 skipExecution = true;382 resultFailureMessage = AutomatorMessages.MSG_GROUP_PRE_REQUISITE_FAILED;383 }384 }385 } else {386 log.debug("Test has no prerequisites. Proceeding with normal execution...");387 }388 }389 private boolean checkTestCasePrerequisiteFailure(TestCaseEntity testCaseEntity, TestCaseResult testCaseResult) {390 boolean testCasePrerequisiteFailed = false;391 TestCaseResult prerequisiteTestCaseResult = testcaseResultMap.get(testCaseEntity.getPreRequisite());392 log.debug("Found that test case has prerequisite. Checking the prerequisite result - " + prerequisiteTestCaseResult);393 boolean abortOnPrerequisiteFailure = (((prerequisiteTestCaseResult == null)394 || (prerequisiteTestCaseResult.getResult() != ResultConstant.SUCCESS))395 && (testPlanRunSettingEntity.getOnTestcasePreRequisiteFail() == PreRequisiteAction.Abort));396 if (abortOnPrerequisiteFailure) {397 log.debug("Prerequisite failed for test suite. Aborting....");398 testCaseResult.setResult(ResultConstant.FAILURE);399 testCaseResult.setMessage(AutomatorMessages.MSG_CASE_PRE_REQUISITE_FAILED);400 testCaseResult.setEndTime(new Timestamp(System.currentTimeMillis()));401 testCasePrerequisiteFailed = true;402 resultFailureMessage = AutomatorMessages.MSG_CASE_PRE_REQUISITE_FAILED;403 }404 return testCasePrerequisiteFailed;405 }406}...
Source:ActionStepExecutor.java
2import com.testsigma.automator.constants.ActionResult;3import com.testsigma.automator.constants.AutomatorMessages;4import com.testsigma.automator.drivers.DriverManager;5import com.testsigma.automator.entity.ResultConstant;6import com.testsigma.automator.entity.TestCaseResult;7import com.testsigma.automator.entity.TestCaseStepEntity;8import com.testsigma.automator.entity.TestCaseStepResult;9import com.testsigma.automator.exceptions.AutomatorException;10import com.testsigma.automator.actions.DriverAction;11import com.testsigma.automator.actions.constants.ErrorCodes;12import com.testsigma.automator.actions.exceptions.NaturalActionException;13import com.testsigma.automator.utilities.RuntimeDataProvider;14import lombok.AllArgsConstructor;15import lombok.Data;16import lombok.extern.log4j.Log4j2;17import org.openqa.selenium.StaleElementReferenceException;18import java.lang.reflect.InvocationTargetException;19import java.util.Arrays;20import java.util.List;21import java.util.Map;22@Data23@Log4j224@AllArgsConstructor25public class ActionStepExecutor {26 private static final List<ErrorCodes> ERROR_CODES = Arrays.asList(27 ErrorCodes.UNREACHABLE_BROWSER,28 ErrorCodes.NO_SUCH_SESSION_EXCEPTION,29 ErrorCodes.GENERAL_EXCEPTION);30 private TestCaseStepEntity testCaseStepEntity;31 private TestCaseStepResult testCaseStepResult;32 private Map<String, String> envSettings;33 private TestCaseResult testCaseResult;34 public void execute() throws IllegalAccessException,35 IllegalArgumentException, InvocationTargetException, SecurityException, NoSuchMethodException,36 AutomatorException, ClassNotFoundException, InstantiationException {37 Class<?> className = Class.forName(testCaseStepEntity.getSnippetClass());38 DriverAction snippet = (DriverAction) className.getDeclaredConstructor().newInstance();39 snippet.setDriver(DriverManager.getRemoteWebDriver());40 snippet.setTimeout(testCaseStepEntity.getWaitTime().longValue());41 snippet.setTestDataPropertiesEntityMap(testCaseStepEntity.getTestDataMap());42 snippet.setElementPropertiesEntityMap(testCaseStepEntity.getElementsMap());43 snippet.setAttributesMap(testCaseStepEntity.getAttributesMap());44 snippet.setGlobalElementTimeOut(testCaseStepResult.getTestPlanRunSettingEntity().getElementTimeOut().longValue());45 snippet.setRuntimeDataProvider(prepareRunTimeDataProvider());46 snippet.setEnvSettings(envSettings);47 snippet.setAdditionalData(testCaseStepEntity.getAdditionalData());48 ActionResult snippetResult = snippet.run();49 //We retry test step execution on failure based on the exception type.50 snippetResult = reTrySnippetIfEligible(snippetResult, snippet, testCaseStepEntity, testCaseStepResult);51 testCaseStepResult.getMetadata().setSnippetResultMetadata(snippet.getResultMetadata());52 testCaseStepResult.getOutputData().putAll(snippet.getTestDataParams());53 if (snippetResult == ActionResult.FAILED) {54 log.error("Test case step FAILED....");55 NaturalActionException naturalActionException = new NaturalActionException(snippet.getErrorMessage(), snippet.getException(),56 snippet.getErrorCode().getErrorCode().intValue());57 testCaseStepResult.setWebDriverException(naturalActionException.getErrorStackTraceTruncated());58 testCaseStepResult.setErrorCode(snippet.getErrorCode().getErrorCode().intValue());59 testCaseStepResult.setMessage(snippet.getErrorMessage());60 markTestcaseAborted(testCaseResult, testCaseStepResult, snippet);61 testCaseStepResult.getMetadata().setLog(testCaseStepResult.getWebDriverException());62 throw naturalActionException; //We are throwing an InvocationTargetException to handle Auto Healing63 } else {64 testCaseStepResult.setMessage(snippet.getSuccessMessage());65 }66 }67 private ActionResult reTrySnippetIfEligible(ActionResult snippetResult, DriverAction snippet,68 TestCaseStepEntity testCaseStepEntity,69 TestCaseStepResult testCaseStepResult) throws AutomatorException {70 for (int i = 0; i < testCaseStepEntity.getNoOfRetriesOnStepFailure(); i++) {71 boolean reTryRequired = eligibleForReTry(snippetResult, snippet, testCaseStepEntity, testCaseStepResult);72 if (reTryRequired) {73 testCaseStepResult.setRetriedCount(testCaseStepResult.getRetriedCount() + 1);74 log.info("Snippet Retry Count - " + testCaseStepResult.getRetriedCount());75 snippetResult = snippet.run();76 } else {77 log.info("Snippet is not eligible for retry...continuing");78 break;79 }80 }81 return snippetResult;82 }83 private boolean eligibleForReTry(ActionResult snippetResult, DriverAction snippet, TestCaseStepEntity stepEntity,84 TestCaseStepResult stepResult) {85 if (snippetResult != ActionResult.FAILED) {86 return false;87 }88 if (stepResult.getRetriedCount() < stepEntity.getNoOfRetriesOnStepFailure() && snippet.getException() != null89 && snippet.getException().getCause() != null) {90 if (snippet.getException().getCause() instanceof StaleElementReferenceException) {91 log.info("Snippet is eligible for retry...retrying");92 return true;93 }94 }95 return false;96 }97 private RuntimeDataProvider prepareRunTimeDataProvider() {98 return new RuntimeDataProvider();99 }100 private void markTestcaseAborted(TestCaseResult testCaseResult, TestCaseStepResult result, DriverAction snippet) {101 boolean isInAbortedList = ERROR_CODES.stream().anyMatch(code -> snippet.getErrorCode().equals(code));102 if (isInAbortedList) {103 DriverManager.getDriverManager().setRestartDriverSession(Boolean.TRUE);104 result.setResult(ResultConstant.ABORTED);105 result.setSkipExe(true);106 result.setMessage(AutomatorMessages.MSG_STEP_MAJOR_STEP_FAILURE);107 testCaseResult.setResult(ResultConstant.ABORTED);108 testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_ABORTED);109 if(!testCaseStepEntity.getStepDetails().getIgnoreStepResult()) {110 testCaseResult.setResult(ResultConstant.ABORTED);111 testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_ABORTED);112 }113 } else {114 result.setResult(ResultConstant.FAILURE);...
Source:AddonNaturalTextActionStepExecutor.java
...24 ErrorCodes.NO_SUCH_SESSION_EXCEPTION,25 ErrorCodes.GENERAL_EXCEPTION);26 private TestCaseStepEntity testCaseStepEntity;27 private TestCaseStepResult testCaseStepResult;28 private TestCaseResult testCaseResult;29 private URLClassLoader jarFileLoader;30 private Class<?> elementClass;31 private Class<?> testDataClass;32 private Class<?> loggerClass;33 private Class<?> runTimeDataClass;34 private Map<String, String> envSettings;35 private LinkedList<ElementPropertiesEntity> addonElementPropertiesEntity;36 public AddonNaturalTextActionStepExecutor(TestCaseStepEntity testCaseStepEntity, TestCaseStepResult testCaseStepResult,37 TestCaseResult testCaseResult,38 Map<String, String> envSettings) {39 this.testCaseStepEntity = testCaseStepEntity;40 this.testCaseStepResult = testCaseStepResult;41 this.testCaseResult = testCaseResult;42 this.envSettings = envSettings;43 }44 public void execute() throws IOException, IllegalAccessException, NoSuchMethodException, ClassNotFoundException, InvocationTargetException, InstantiationException, AutomatorException, NoSuchFieldException, NaturalActionException {45 AddonAction addonAction = new AddonAction(testCaseStepEntity, testCaseStepResult, this.addonElementPropertiesEntity, this.envSettings);46 ActionResult snippetResult = addonAction.run();47 if (snippetResult == ActionResult.FAILED) {48 log.error("Test case step FAILED....");49 NaturalActionException actionException;50 if(addonAction.getException() != null){51 actionException = new NaturalActionException(addonAction.getErrorMessage(), addonAction.getException(),52 addonAction.getErrorCode().getErrorCode().intValue());53 } else {54 actionException = new NaturalActionException(addonAction.getErrorMessage());55 }56 testCaseStepResult.setWebDriverException(actionException.getErrorStackTraceTruncated());57 testCaseStepResult.setErrorCode(addonAction.getErrorCode().getErrorCode().intValue());58 testCaseStepResult.setMessage(addonAction.getErrorMessage());59 markTestcaseAborted(testCaseResult, testCaseStepResult, addonAction);60 testCaseStepResult.getMetadata().setLog(testCaseStepResult.getWebDriverException());61 throw actionException; //We are throwing an InvocationTargetException to handle Auto Healing62 } else {63 testCaseStepResult.setMessage(addonAction.getSuccessMessage());64 }65 }66 private void markTestcaseAborted(TestCaseResult testCaseResult, TestCaseStepResult result, AddonAction snippet) {67 boolean isInAbortedList = ERROR_CODES.stream().anyMatch(code -> snippet.getErrorCode().equals(code));68 if (isInAbortedList) {69 DriverManager.getDriverManager().setRestartDriverSession(Boolean.TRUE);70 result.setResult(ResultConstant.ABORTED);71 result.setSkipExe(true);72 result.setMessage(AutomatorMessages.MSG_STEP_MAJOR_STEP_FAILURE);73 testCaseResult.setResult(ResultConstant.ABORTED);74 testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_ABORTED);75 if(!testCaseStepEntity.getStepDetails().getIgnoreStepResult()) {76 testCaseResult.setResult(ResultConstant.ABORTED);77 testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_ABORTED);78 }79 } else {80 result.setResult(ResultConstant.FAILURE);...
TestCaseResult
Using AI Code Generation
1import com.testsigma.automator.entity.TestCaseResult;2import com.testsigma.automator.entity.TestSuiteResult;3import com.testsigma.automator.entity.TestRunResult;4public class TestRunResultDemo {5 public static void main(String[] args) {6 TestSuiteResult testSuiteResult = new TestSuiteResult();7 TestCaseResult testCaseResult = new TestCaseResult();8 TestRunResult testRunResult = new TestRunResult();9 testSuiteResult.setTestSuiteName("TestSuiteName");10 testCaseResult.setTestCaseName("TestCaseName");11 testRunResult.setTestSuiteResult(testSuiteResult);12 testRunResult.setTestCaseResult(testCaseResult);13 testRunResult.setTestRunResult("PASS");14 testRunResult.setTestRunResultMessage("Test run result message");15 testRunResult.setTestRunResultTime("2018-04-09 10:00:00");16 testRunResult.setTestRunResultScreenshotPath("C:\\TestRunResultScreenshotPath");17 System.out.println(testRunResult.getTestSuiteResult().getTestSuiteName());18 System.out.println(testRunResult.getTestCaseResult().getTestCaseName());19 System.out.println(testRunResult.getTestRunResult());20 System.out.println(testRunResult.getTestRunResultMessage());21 System.out.println(testRunResult.getTestRunResultTime());22 System.out.println(testRunResult.getTest
TestCaseResult
Using AI Code Generation
1import com.testsigma.automator.entity.TestCaseResult;2import com.testsigma.automator.entity.TestSuiteResult;3import com.testsigma.automator.entity.TestRunResult;4import com.testsigma.automator.entity.TestRunResult;5import com.testsigma.automator.entity.TestRunResult;6import com.testsigma.automator.entity.TestRunResult;7import com.testsigma.automator.entity.TestRunResult;8import com.testsigma.automator.entity.TestRunResult;9import com.testsigma.automator.entity.TestRunResult;10import com.testsigma.automator.entity.TestRunResult;11import com.testsigma.automator.entity.TestRunResult;12import com.tests
TestCaseResult
Using AI Code Generation
1import com.testsigma.automator.entity.TestCaseResult;2import com.testsigma.automator.entity.TestResult;3import com.testsigma.automator.entity.TestStepResult;4import com.testsigma.automator.entity.TestStepStatus;5import com.testsigma.automator.entity.TestStatus;6import com.testsigma.automator.entity.TestStep;7import com.testsigma.automator.entity.TestStepType;8import com.testsigma.automator.entity.TestStepResult;9import com.testsigma.automator.entity.TestStepStatus;10import com.testsigma.automator.entity.TestStatus;11import com.testsigma.automator.entity.TestStep;12import com.testsigma.automator.entity.TestStepType;13import com.testsigma.automator.entity.TestStepResult;14import com.testsigma.automator.entity.TestStepStatus;15import com.testsigma.automator.entity.TestStatus;16import com.testsigma.automator.entity.TestStep;17import com.testsigma.automator.entity.TestStepType;18import com.testsigma.automator.entity.TestStepResult;19import com.testsigma.automator.entity.TestStepStatus;20import com.testsigma.automator.entity.TestStatus;21import com.testsigma.automator.entity.TestStep;22import com.testsigma.automator.entity.TestStepType;23import com.testsigma.automator.entity.TestStepResult;24import com.testsigma.automator.entity.TestStepStatus;25import com.testsigma.automator.entity.TestStatus;26import com.testsigma.automator.entity.TestStep;27import com.testsigma.automator.entity.TestStepType;28import com.testsigma.automator.entity.TestStepResult;29import com.testsigma.automator.entity.TestStepStatus;30import com.testsigma.automator.entity.TestStatus;31import com.testsigma.automator.entity.TestStep;32import com.testsigma.automator.entity.TestStepType;33import com.testsigma.automator.entity.TestStepResult;34import com.testsigma.automator.entity.TestStepStatus;35import com.testsigma.automator.entity.TestStatus;36import com.testsigma.automator.entity.TestStep;37import com.testsigma.automator.entity.TestStepType;38import com.testsigma.automator.entity.TestStepResult;39import com.testsigma.automator.entity.TestStepStatus;40import com.testsigma.automator.entity.TestStatus;41import com.testsigma.automator.entity.TestStep;42import com.testsigma.automator.entity.TestStepType;43import com.testsigma.automator.entity.TestStepResult;
TestCaseResult
Using AI Code Generation
1import com.testsigma.automator.entity.TestCaseResult;2import com.testsigma.automator.entity.TestStepResult;3import com.testsigma.automator.entity.TestStepResultStatus;4import com.testsigma.automator.entity.TestStepResultType;5import com.testsigma.automator.entity.TestStepStatus;6import com.testsigma.automator.entity.TestStepType;7import com.testsigma.automator.entity.TestStepResult;8import com.testsigma.automator.entity.TestStepResultStatus;9import com.testsigma.automator.entity.TestStepResultType;10import com.testsigma.automator.entity.TestStepStatus;11import com.testsigma.automator.entity.TestStepType;12import com.testsigma.automator.entity.TestStepResult;13import com.testsigma.automator.entity.TestStepResultStatus;14import com.testsigma.automator.entity.TestStepResultType;15import com.testsigma.automator.entity.TestStepStatus;16import com.testsigma.automator.entity.TestStepType;17import com.testsigma.automator.entity.TestStepResult;18import com.testsigma.automator.entity.TestStepResultStatus;19import com.testsigma.automator.entity.TestStepResultType;
TestCaseResult
Using AI Code Generation
1import com.testsigma.automator.entity.TestCaseResult;2import com.testsigma.automator.entity.TestSuiteResult;3import com.testsigma.automator.entity.TestResult;4public class TestResultDemo {5 public static void main(String[] args) {6 TestCaseResult testCaseResult = new TestCaseResult("testcase1", "testcase1");7 testCaseResult.setTestStatus(TestResult.PASS);8 testCaseResult.setDuration(1000);9 testCaseResult.setStartTime(System.currentTimeMillis());10 testCaseResult.setEndTime(System.currentTimeMillis());11 testCaseResult.setStepCount(1);12 testCaseResult.setPassCount(1);13 testCaseResult.setFailCount(0);14 testCaseResult.setSkipCount(0);15 testCaseResult.setBlockCount(0);16 testCaseResult.setWarningCount(0);17 testCaseResult.setExceptionCount(0);18 testCaseResult.setInfoCount(0);19 testCaseResult.setComment("test");20 testCaseResult.addStep("step1", "step1", TestResult.PASS);21 TestSuiteResult testSuiteResult = new TestSuiteResult("testsuite1", "testsuite1");22 testSuiteResult.setTestStatus(TestResult.PASS);23 testSuiteResult.setDuration(1000);24 testSuiteResult.setStartTime(System.currentTimeMillis());25 testSuiteResult.setEndTime(System.currentTimeMillis());26 testSuiteResult.setTestCaseCount(1);27 testSuiteResult.setPassCount(1);28 testSuiteResult.setFailCount(0);29 testSuiteResult.setSkipCount(0);30 testSuiteResult.setBlockCount(0);31 testSuiteResult.setWarningCount(0);32 testSuiteResult.setExceptionCount(0);33 testSuiteResult.setInfoCount(0);34 testSuiteResult.setComment("test");35 testSuiteResult.addTestCase(testCaseResult);36 testSuiteResult.addStep("step1", "step1", TestResult.PASS);37 testSuiteResult.addStep("step2", "step2", TestResult.PASS);38 System.out.println(testSuiteResult.toString());39 }40}41import com.testsigma.automator.entity.TestCaseResult;42import com.testsigma.automator.entity.TestSuiteResult;43import com.testsigma.automator.entity.TestResult;
TestCaseResult
Using AI Code Generation
1import com.testsigma.automator.entity.TestCaseResult;2import com.testsigma.automator.entity.TestSuiteResult;3public class TestClass {4 public static void main(String[] args) {5 TestSuiteResult testSuiteResult = new TestSuiteResult();6 testSuiteResult.addTestCaseResult(new TestCaseResult("Test case 1", "Test case 1 description", "Test case 1 status", "Test case 1 execution time"));7 testSuiteResult.addTestCaseResult(new TestCaseResult("Test case 2", "Test case 2 description", "Test case 2 status", "Test case 2 execution time"));8 testSuiteResult.addTestCaseResult(new TestCaseResult("Test case 3", "Test case 3 description", "Test case 3 status", "Test case 3 execution time"));9 testSuiteResult.addTestCaseResult(new TestCaseResult("Test case 4", "Test case 4 description", "Test case 4 status", "Test case 4 execution time"));10 testSuiteResult.addTestCaseResult(new TestCaseResult("Test case 5", "Test case 5 description", "Test case 5 status", "Test case 5 execution time"));11 testSuiteResult.addTestCaseResult(new TestCaseResult("Test case 6", "Test case 6 description", "Test case 6 status", "Test case 6 execution time"));12 testSuiteResult.addTestCaseResult(new TestCaseResult("Test case 7", "Test case 7 description", "Test case 7 status", "Test case 7 execution time"));13 testSuiteResult.addTestCaseResult(new TestCaseResult("Test case 8", "Test case 8 description", "Test case 8 status", "Test case
TestCaseResult
Using AI Code Generation
1public class Test1 extends TestCaseResult {2 public void test1() {3 }4}5public class Test2 extends TestCaseResult {6 public void test2() {7 }8}9public class Test3 extends TestCaseResult {10 public void test3() {11 }12}13public class Test4 extends TestCaseResult {14 public void test4() {15 }16}17public class Test5 extends TestCaseResult {18 public void test5() {19 }20}21public class Test6 extends TestCaseResult {22 public void test6() {23 }24}25public class Test7 extends TestCaseResult {26 public void test7() {27 }28}29public class Test8 extends TestCaseResult {30 public void test8() {31 }32}33public class Test9 extends TestCaseResult {34 public void test9() {35 }36}37public class Test10 extends TestCaseResult {38 public void test10() {39 }40}41public class Test11 extends TestCaseResult {42 public void test11() {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!