How to use getTestCase method of com.testsigma.automator.runners.TestsuiteRunner class

Best Testsigma code snippet using com.testsigma.automator.runners.TestsuiteRunner.getTestCase

Source:TestsuiteRunner.java Github

copy

Full Screen

...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 testcaseResultMap.put(testCaseEntity.getId(), testCaseResult);160 if (skipExecution) {161 testCaseResult.setMessage(resultFailureMessage);162 } else if (hasPreRequisite(testCaseEntity)) {163 testCasePrerequisiteFailed = checkTestCasePrerequisiteFailure(testCaseEntity, testCaseResult);164 }165 try {166 if (!testCaseEntity.getIsDataDriven()) {167 testCaseEntity = getTestCase(testCaseEntity, this.testCaseFetchMaxTries);168 new ErrorUtil().checkError(testCaseEntity.getErrorCode(), testCaseEntity.getMessage());169 }170 } catch (TestsigmaNoParallelRunException e) {171 log.error(e.getMessage(), e);172 testCaseRunFailed = true;173 resultFailureMessage = e.getMessage();174 testCaseResult.setResult(ResultConstant.STOPPED);175 testCaseResult.setMessage(resultFailureMessage);176 } catch (AutomatorException e) {177 log.error(e.getMessage(), e);178 testCaseRunFailed = true;179 resultFailureMessage = e.getMessage();180 testCaseResult.setResult(ResultConstant.FAILURE);181 testCaseResult.setMessage(resultFailureMessage);182 }183 if (!testCaseRunFailed) {184 if (ExecutionEnvironmentRunner.isRunning()) {185 testSuiteResult.setSessionCreatedOn(new Timestamp(System.currentTimeMillis()));186 if (testCaseEntity.getIsDataDriven()) {187 runDataDrivenTestCase(testCaseEntity, testCaseResult, false, testCasePrerequisiteFailed);188 } else {189 new TestcaseRunner(testCaseEntity, testCaseResult, mapStepResult,190 skipExecution || testCasePrerequisiteFailed, resultFailureMessage)191 .run();192 }193 executionStarted = true;194 } else {195 testCaseResult.setResult(ResultConstant.STOPPED);196 testCaseResult.setMessage(AutomatorMessages.MSG_USER_ABORTED_EXECUTION);197 testCaseResult.setEndTime(new Timestamp(System.currentTimeMillis()));198 postTestcaseResult(testCaseResult);199 break;200 }201 }202 testCaseResult.setEndTime(new Timestamp(System.currentTimeMillis()));203 postTestcaseResult(testCaseResult);204 } catch (Exception ex) {205 log.error("Unhandled exception while processing test case");206 log.error(ex.getMessage(), ex);207 testCaseResult.setResult(ResultConstant.ABORTED);208 testCaseResult.setMessage(ex.getMessage());209 try {210 postTestcaseResult(testCaseResult);211 } catch (Exception e) {212 log.error("Unhandled exception while posting test case results");213 log.error(e.getMessage(), e);214 }215 }216 if (testCaseResult.getResult().getId() > testSuiteResult.getResult().getId()) {217 testSuiteResult.setResult(testCaseResult.getResult());218 }219 }220 testSuiteResult.setSessionCompletedOn(new Timestamp(System.currentTimeMillis()));221 testSuiteResult.setEndTime(new Timestamp(System.currentTimeMillis()));222 if (testSuiteResult.getResult() == ResultConstant.SUCCESS) {223 testSuiteResult.setMessage(AutomatorMessages.MSG_GROUP_SUCCESS);224 } else if (StringUtils.isBlank(testSuiteResult.getMessage())) {225 testSuiteResult.setMessage(AutomatorMessages.MSG_GROUP_FAILED);226 }227 resetThreadContextData();228 }229 private void restartCurrentSession(TestSuiteResult testSuiteResult) {230 if (workspaceType.equals(WorkspaceType.Rest)) {231 return;232 }233 DriverManager driverManager = DriverManager.getDriverManager();234 if (driverManager.isRestart() && (driverManager.getRestartSessionId() != null)) {235 try {236 log.info("Found that driver session restarted while executing a test suite. Storing session ID " +237 "in test suite result tables. Test Suite Result - " + testSuiteResult.getId());238 driverManager.storeSessionId(DriverSessionType.TEST_SUITE_SESSION, testSuiteResult.getId());239 } catch (Exception e) {240 log.error(e.getMessage(), e);241 }242 }243 }244 public void runDataDrivenTestCase(TestCaseEntity testCaseEntity, TestCaseResult testCaseResult,245 boolean testCaseRunFailed, boolean testCasePrerequisiteFailed) throws Exception {246 ResultConstant dataDrivenStatus = ResultConstant.SUCCESS;247 for (TestCaseEntity dataDrivenTestCase : testCaseEntity.getDataDrivenTestCases()) {248 TestCaseResult dataDrivenTestCaseResult = new TestCaseResult(dataDrivenTestCase.getId());249 dataDrivenTestCaseResult.setId(getResultId(testCaseEntity, dataDrivenTestCase.getTestDataSetName()));250 dataDrivenTestCaseResult.setGroupId(testCaseResult.getGroupId());251 dataDrivenTestCaseResult.setEnvRunId(environmentRunResult.getId());252 dataDrivenTestCaseResult.setGroupResultId(testCaseResult.getGroupResultId());253 dataDrivenTestCaseResult.setParentId(testCaseResult.getId());254 dataDrivenTestCaseResult.setTestDataSetName(dataDrivenTestCase.getTestDataSetName());255 dataDrivenTestCaseResult.setTestDataId(testCaseEntity.getTestDataId());256 dataDrivenTestCaseResult.setStartTime(new Timestamp(System.currentTimeMillis()));257 testCaseResult.getTestCaseResults().add(dataDrivenTestCaseResult);258 try {259 dataDrivenTestCase = getTestCase(dataDrivenTestCase, this.testCaseFetchMaxTries);260 new ErrorUtil().checkError(dataDrivenTestCase.getErrorCode(), dataDrivenTestCase.getMessage());261 } catch (AutomatorException e) {262 log.error(e.getMessage(), e);263 if (!(skipExecution || testCasePrerequisiteFailed)) {264 testCaseRunFailed = true;265 resultFailureMessage = e.getMessage();266 dataDrivenTestCaseResult.setResult(ResultConstant.FAILURE);267 dataDrivenTestCaseResult.setMessage(resultFailureMessage);268 }269 }270 if (!(testCaseRunFailed || testCasePrerequisiteFailed)) {271 if (ExecutionEnvironmentRunner.isRunning()) {272 new TestcaseRunner(dataDrivenTestCase, dataDrivenTestCaseResult, mapStepResult,273 skipExecution || testCasePrerequisiteFailed, resultFailureMessage).run();274 boolean isFailed = (ResultConstant.SUCCESS != dataDrivenTestCaseResult.getResult());275 if (skipExecution) {276 dataDrivenTestCaseResult.setResult(testCaseResult.getResult());277 dataDrivenTestCaseResult.setMessage(testCaseResult.getMessage());278 } else if (isFailed == dataDrivenTestCase.getExpectedToFail()) {279 dataDrivenTestCaseResult.setResult(ResultConstant.SUCCESS);280 } else {281 dataDrivenTestCaseResult.setResult(ResultConstant.FAILURE);282 }283 } else {284 dataDrivenTestCaseResult.setResult(ResultConstant.STOPPED);285 dataDrivenTestCaseResult.setMessage(AutomatorMessages.MSG_USER_ABORTED_EXECUTION);286 dataDrivenTestCaseResult.setEndTime(new Timestamp(System.currentTimeMillis()));287 postTestcaseResult(dataDrivenTestCaseResult);288 break;289 }290 } else if (testCasePrerequisiteFailed) {291 dataDrivenTestCaseResult.setResult(testCaseResult.getResult());292 dataDrivenTestCaseResult.setMessage(testCaseResult.getMessage());293 }294 dataDrivenStatus = (dataDrivenTestCaseResult.getResult().getId() > dataDrivenStatus.getId()) ?295 dataDrivenTestCaseResult.getResult() : dataDrivenStatus;296 dataDrivenTestCaseResult.setEndTime(ObjectUtils.defaultIfNull(dataDrivenTestCaseResult.getEndTime(),297 new Timestamp(System.currentTimeMillis())));298 postTestcaseResult(dataDrivenTestCaseResult);299 }300 testCaseResult.setResult(ObjectUtils.defaultIfNull(testCaseResult.getResult(), dataDrivenStatus));301 if (testCaseResult.getResult() == ResultConstant.SUCCESS) {302 testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_SUCCESS);303 } else if (StringUtils.isBlank(testCaseResult.getMessage())) {304 testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_FAILURE);305 }306 }307 private TestCaseEntity getTestCase(TestCaseEntity testCaseEntity, int maxTries) throws AutomatorException {308 try {309 TestCaseEntity testCaseEntityCopy = testCaseEntity;310 testCaseEntity = AutomatorConfig.getInstance().getAppBridge().getTestCase(environmentRunResult.getId(),311 testCaseEntity);312 if (testCaseEntity != null) {313 if (ResultConstant.STOPPED == testCaseEntity.getResult()) {314 ExecutionEnvironmentRunner.setStoppedStatus();315 }316 }317 if ((testCaseEntity.getErrorCode() != null) && maxTries > 0) {318 RemoteWebDriver remoteWebDriver = DriverManager.getDriverManager().getDriver().getRemoteWebDriver();319 remoteWebDriver.getWindowHandle();320 Thread.sleep(this.testCaseFetchWaitInterval);321 return getTestCase(testCaseEntityCopy, maxTries - 1);322 }323 return testCaseEntity;324 } catch (Exception e) {325 log.error(e.getMessage(), e);326 throw new AutomatorException(ErrorCodes.TEST_CASE_DETAILS_FETCH_FAILED,327 AutomatorMessages.FAILED_TO_FETCH_TEST_CASE_DETAILS + " - " + e.getMessage());328 }329 }330 private Long getResultId(TestCaseEntity entityList, String iteration) {331 for (TestCaseEntity entity : entityList.getDataDrivenTestCases()) {332 if (entity.getTestDataSetName() != null && entity.getTestDataSetName().equals(iteration)) {333 return entity.getTestCaseResultId();334 }335 }336 return null;337 }338 public void postTestcaseResult(TestCaseResult testCaseResult) throws Exception {339 AutomatorConfig.getInstance().getAppBridge().postTestCaseResult(testCaseResult);340 }341 public void postSuiteResult(TestSuiteResult testSuiteResult) throws Exception {342 AutomatorConfig.getInstance().getAppBridge().postTestSuiteResult(testSuiteResult);343 }344 private boolean hasPreRequisite(TestSuiteEntity testSuiteEntity) {345 boolean hasPreRequisite = false;346 if (testSuiteEntity.getPreRequisite() != null) {347 if (testSuiteEntity.getPreRequisite() > 0) {...

Full Screen

Full Screen

getTestCase

Using AI Code Generation

copy

Full Screen

1import com.testsigma.automator.runners.TestsuiteRunner;2import com.testsigma.automator.testcase.TestCase;3import com.testsigma.automator.testcase.TestCaseResult;4import com.testsigma.automator.testcase.TestCaseResultStatus;5import com.testsigma.automator.testcase.TestStepResult;6import com.testsigma.automator.testcase.TestStepResultStatus;7import com.testsigma.automator.testcase.TestStepStatus;8import com.testsigma.automator.testcase.TestStepType;9import com.testsigma.automator.testcase.TestStep;10import com.testsigma.automator.testcase.TestStep;11import com.testsigma.automator.testcase.TestStepResult;12import com.testsigma.automator.testcase.TestStepResultStatus;13import com.testsigma.automator.testcase.TestStepStatus;14import com.testsigma.automator.testcase.TestStepType;15import com.testsigma.automator.testcase.TestCase;16import com.testsigma.automator.testcase.TestCaseResult;17import com.testsigma.automator.testcase.TestCaseResultStatus;18import com.testsigma.automator.testcase.TestCaseStatus;19import com.testsigma.automator.testcase.TestStepResult;20import com.testsigma.automator.testcase.TestStepResultStatus;21import com.testsigma.automator.testcase.TestStepStatus;22import com.testsigma.automator.testcase.TestStepType;23import com.testsigma.automator.testcase.TestCase;24import com.testsigma.automator.testcase.TestCaseResult;25import com.testsigma.automator.testcase.TestCaseResultStatus;26import com.testsigma.automator.testcase.TestCaseStatus;27import com.testsigma.automator.testcase.TestStepResult;28import com.testsigma.automator.testcase.TestStepResultStatus;29import com.testsigma.automator.testcase.TestStepStatus;30import com.testsigma.automator.testcase.TestStepType;31import com.testsigma.automator.testcase.TestCase;32import com.testsigma.automator.testcase.TestCaseResult;33import com.testsigma.automator.testcase.TestCaseResultStatus;34import com.testsigma.automator.testcase.TestCaseStatus;35import com.testsigma.automator.testcase.TestStepResult;36import com.testsigma.automator.testcase.TestStepResultStatus;37import com.testsigma.automator.testcase.TestStepStatus;38import com.testsigma.automator.testcase.TestStepType;39import com.testsigma.automator.testcase

Full Screen

Full Screen

getTestCase

Using AI Code Generation

copy

Full Screen

1import com.testsigma.automator.runners.TestsuiteRunner;2import com.testsigma.automator.webdriver.TestsigmaDriver;3import com.testsigma.automator.webdriver.TestsigmaWebDriver;4import com.testsigma.automator.webdriver.TestsigmaWebElement;5import com.testsigma.automator.webdriver.TestsigmaWebElements;6public class TestcaseRunner {7 public static void main(String[] args) throws Exception {8 TestsuiteRunner testsuiteRunner = new TestsuiteRunner();9 TestsigmaDriver driver = new TestsigmaWebDriver();10 TestsigmaWebElement element = new TestsigmaWebElement();11 TestsigmaWebElements elements = new TestsigmaWebElements();12 testsuiteRunner.getTestCase("testcaseName", driver, element, elements);13 }14}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful