Best Cerberus-source code snippet using org.cerberus.engine.gwt.impl.ActionService.doActionExecuteCommand
Source:ActionService.java
...289 case TestCaseStepAction.ACTION_DONOTHING:290 res = new MessageEvent(MessageEventEnum.ACTION_SUCCESS);291 break;292 case TestCaseStepAction.ACTION_EXECUTECOMMAND:293 res = this.doActionExecuteCommand(tCExecution, value1, value2);294 break;295 case TestCaseStepAction.ACTION_EXECUTECERBERUSCOMMAND:296 res = this.doActionExecuteCerberusCommand(tCExecution, value1);297 break;298 case TestCaseStepAction.ACTION_SCROLLTO:299 res = this.doActionScrollTo(tCExecution, value1, value2);300 break;301 case TestCaseStepAction.ACTION_INSTALLAPP:302 res = this.doActionInstallApp(tCExecution, value1);303 break;304 case TestCaseStepAction.ACTION_REMOVEAPP:305 res = this.doActionRemoveApp(tCExecution, value1);306 break;307 case TestCaseStepAction.ACTION_DRAGANDDROP:308 res = this.doActionDragAndDrop(tCExecution, value1, value2);309 break;310 case TestCaseStepAction.ACTION_LONGPRESS:311 res = this.doActionLongPress(tCExecution, value1, value2);312 break;313 case TestCaseStepAction.ACTION_CLEARFIELD:314 res = this.doActionClearField(tCExecution, value1);315 break;316 case TestCaseStepAction.ACTION_REFRESHCURRENTPAGE:317 res = this.doActionRefreshCurrentPage(tCExecution);318 break;319 /**320 * DEPRECATED ACTIONS FROM HERE.321 */322 case TestCaseStepAction.ACTION_MOUSEOVERANDWAIT:323 res = this.doActionMouseOverAndWait(tCExecution, value1, value2);324 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());325 logEventService.createForPrivateCalls("ENGINE", "mouseOverAndWait", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");326 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action mouseOverAndWait triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");327 break;328 case TestCaseStepAction.ACTION_REMOVEDIFFERENCE:329 res = this.doActionRemoveDifference(testCaseStepActionExecution, value1, value2);330 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());331 logEventService.createForPrivateCalls("ENGINE", "removeDifference", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");332 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action removeDifference triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");333 break;334 default:335 res = new MessageEvent(MessageEventEnum.ACTION_FAILED_UNKNOWNACTION);336 res.setDescription(res.getDescription().replace("%ACTION%", testCaseStepActionExecution.getAction()));337 }338 } catch (final Exception unexpected) {339 LOG.error("Unexpected exception: " + unexpected.getMessage(), unexpected);340 res = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC).resolveDescription("DETAIL", unexpected.getMessage());341 }342 LOG.debug("Result of the action : " + res.getCodeString() + " " + res.getDescription());343 /**344 * In case 1/ the action is flaged as being Forced with a specific345 * return code = PE and 2/ the return of the action is stoping the test346 * --> whatever the return of the action is, we force the return to move347 * forward the test with no screenshot, pagesource.348 */349 if (testCaseStepActionExecution.getForceExeStatus().equals("PE") && res.isStopTest()) {350 res.setDescription(res.getDescription() + " -- Execution forced to continue.");351 res.setDoScreenshot(false);352 res.setGetPageSource(false);353 res.setStopTest(false);354 res.setMessage(MessageGeneralEnum.EXECUTION_PE_TESTEXECUTING);355 }356 testCaseStepActionExecution.setActionResultMessage(res);357 /**358 * Determine here the impact of the Action on the full test return code359 * from the ResultMessage of the Action.360 */361 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(res.getMessage()));362 /**363 * Determine here if we stop the test from the ResultMessage of the364 * Action.365 */366 testCaseStepActionExecution.setStopExecution(res.isStopTest());367 testCaseStepActionExecution.setEnd(new Date().getTime());368 return testCaseStepActionExecution;369 }370 private MessageEvent doActionInstallApp(TestCaseExecution tCExecution, String appPath) {371 MessageEvent message;372 try {373 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {374 return androidAppiumService.installApp(tCExecution.getSession(), appPath);375 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {376 return iosAppiumService.installApp(tCExecution.getSession(), appPath);377 }378 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);379 message.setDescription(message.getDescription().replace("%ACTION%", "scrollTo"));380 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));381 return message;382 } catch (Exception e) {383 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC);384 String messageString = e.getMessage().split("\n")[0];385 message.setDescription(message.getDescription().replace("%DETAIL%", messageString));386 LOG.debug("Exception Running install app :" + messageString, e);387 return message;388 }389 }390 private MessageEvent doActionRemoveApp(TestCaseExecution tCExecution, String appPackage) {391 MessageEvent message;392 try {393 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {394 return androidAppiumService.removeApp(tCExecution.getSession(), appPackage);395 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {396 return iosAppiumService.removeApp(tCExecution.getSession(), appPackage);397 }398 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);399 message.setDescription(message.getDescription().replace("%ACTION%", "scrollTo"));400 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));401 return message;402 } catch (Exception e) {403 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC);404 String messageString = e.getMessage().split("\n")[0];405 message.setDescription(message.getDescription().replace("%DETAIL%", messageString));406 LOG.debug("Exception Running remove app :" + messageString, e);407 return message;408 }409 }410 private MessageEvent doActionScrollTo(TestCaseExecution tCExecution, String element, String text) {411 MessageEvent message;412 try {413 Identifier identifier = null;414 if (!StringUtil.isNullOrEmpty(element)) {415 identifier = identifierService.convertStringToIdentifier(element);416 }417 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {418 return androidAppiumService.scrollTo(tCExecution.getSession(), identifier, text);419 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {420 return iosAppiumService.scrollTo(tCExecution.getSession(), identifier, text);421 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {422 return webdriverService.scrollTo(tCExecution.getSession(), identifier, text);423 }424 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);425 message.setDescription(message.getDescription().replace("%ACTION%", "scrollTo"));426 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));427 return message;428 } catch (Exception e) {429 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC);430 String messageString = e.getMessage().split("\n")[0];431 message.setDescription(message.getDescription().replace("%DETAIL%", messageString));432 LOG.debug("Exception Running scroll to :" + messageString, e);433 return message;434 }435 }436 private MessageEvent doActionExecuteCommand(TestCaseExecution tCExecution, String command, String args) {437 MessageEvent message;438 try {439 return androidAppiumService.executeCommand(tCExecution.getSession(), command, args);440 } catch (Exception e) {441 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTECOMMAND);442 String messageString = e.getMessage().split("\n")[0];443 message.setDescription(message.getDescription().replace("%EXCEPTION%", messageString));444 LOG.debug("Exception Running Shell :" + messageString, e);445 return message;446 }447 }448 private MessageEvent doActionExecuteCerberusCommand(TestCaseExecution tCExecution, String command) {449 MessageEvent message;450 try {...
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!!