How to use SikuliService class of org.cerberus.service.sikuli.impl package

Best Cerberus-source code snippet using org.cerberus.service.sikuli.impl.SikuliService

Source:ActionService.java Github

copy

Full Screen

...51import org.cerberus.service.appium.IAppiumService;52import org.cerberus.service.appservice.IServiceService;53import org.cerberus.service.cerberuscommand.ICerberusCommand;54import org.cerberus.service.rest.IRestService;55import org.cerberus.service.sikuli.ISikuliService;56import org.cerberus.service.sikuli.impl.SikuliService;57import org.cerberus.service.soap.ISoapService;58import org.cerberus.service.sql.ISQLService;59import org.cerberus.service.webdriver.IWebDriverService;60import org.cerberus.service.xmlunit.IXmlUnitService;61import org.cerberus.util.StringUtil;62import org.cerberus.util.answer.AnswerItem;63import org.openqa.selenium.Platform;64import org.springframework.beans.factory.annotation.Autowired;65import org.springframework.beans.factory.annotation.Qualifier;66import org.springframework.stereotype.Service;67/**68 *69 * @author bcivel70 */71@Service72public class ActionService implements IActionService {73 @Autowired74 private IParameterService parameterService;75 @Autowired76 private IWebDriverService webdriverService;77 @Autowired78 private ISoapService soapService;79 @Autowired80 private IRestService restService;81 @Autowired82 private IAppServiceService appServiceService;83 @Autowired84 private IRecorderService recorderService;85 @Autowired86 private IXmlUnitService xmlUnitService;87 @Autowired88 private ISikuliService sikuliService;89 @Autowired90 private IIdentifierService identifierService;91 @Autowired92 @Qualifier("AndroidAppiumService")93 private IAppiumService androidAppiumService;94 @Autowired95 @Qualifier("IOSAppiumService")96 private IAppiumService iosAppiumService;97 @Autowired98 @Qualifier("CerberusCommand")99 private ICerberusCommand cerberusCommand;100 @Autowired101 private ISQLService sqlService;102 @Autowired103 private ILogEventService logEventService;104 @Autowired105 private IVariableService variableService;106 @Autowired107 private IPropertyService propertyService;108 @Autowired109 private IServiceService serviceService;110 @Autowired111 private IFactoryTestCaseExecutionData factoryTestCaseExecutionData;112 @Autowired113 private ITestCaseExecutionDataService testCaseExecutionDataService;114 private static final Logger LOG = LogManager.getLogger(ActionService.class);115 private static final String MESSAGE_DEPRECATED = "[DEPRECATED]";116 @Override117 public TestCaseStepActionExecution doAction(TestCaseStepActionExecution testCaseStepActionExecution) {118 MessageEvent res;119 TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();120 AnswerItem<String> answerDecode = new AnswerItem<>();121 /**122 * Decode the step action description123 */124 try {125 // When starting a new action, we reset the property list that was already calculated.126 tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());127 answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getDescription(),128 tCExecution, testCaseStepActionExecution, false);129 testCaseStepActionExecution.setDescription((String) answerDecode.getItem());130 if (!(answerDecode.isCodeStringEquals("OK"))) {131 // If anything wrong with the decode --> we stop here with decode message in the action result.132 testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Description"));133 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));134 testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());135 testCaseStepActionExecution.setEnd(new Date().getTime());136 LOG.debug("Action interupted due to decode 'Description' Error.");137 return testCaseStepActionExecution;138 }139 } catch (CerberusEventException cex) {140 testCaseStepActionExecution.setActionResultMessage(cex.getMessageError());141 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));142 testCaseStepActionExecution.setEnd(new Date().getTime());143 return testCaseStepActionExecution;144 }145 /**146 * Decode the object field before doing the action.147 */148 try {149 // When starting a new action, we reset the property list that was already calculated.150 tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());151 answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getValue1(),152 tCExecution, testCaseStepActionExecution, false);153 testCaseStepActionExecution.setValue1((String) answerDecode.getItem());154 if (!(answerDecode.isCodeStringEquals("OK"))) {155 // If anything wrong with the decode --> we stop here with decode message in the action result.156 testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Value1"));157 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));158 testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());159 testCaseStepActionExecution.setEnd(new Date().getTime());160 LOG.debug("Action interupted due to decode 'Action Value1' Error.");161 return testCaseStepActionExecution;162 }163 } catch (CerberusEventException cex) {164 testCaseStepActionExecution.setActionResultMessage(cex.getMessageError());165 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));166 testCaseStepActionExecution.setEnd(new Date().getTime());167 return testCaseStepActionExecution;168 }169 try {170 // When starting a new action, we reset the property list that was already calculated.171 tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());172 answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getValue2(),173 tCExecution, testCaseStepActionExecution, false);174 testCaseStepActionExecution.setValue2((String) answerDecode.getItem());175 if (!(answerDecode.isCodeStringEquals("OK"))) {176 // If anything wrong with the decode --> we stop here with decode message in the action result.177 testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Value2"));178 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));179 testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());180 testCaseStepActionExecution.setEnd(new Date().getTime());181 LOG.debug("Action interupted due to decode 'Action Value2' Error.");182 return testCaseStepActionExecution;183 }184 } catch (CerberusEventException cex) {185 testCaseStepActionExecution.setActionResultMessage(cex.getMessageError());186 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));187 testCaseStepActionExecution.setEnd(new Date().getTime());188 return testCaseStepActionExecution;189 }190 /**191 * Timestamp starts after the decode. TODO protect when property is192 * null.193 */194 testCaseStepActionExecution.setStart(new Date().getTime());195 String value1 = testCaseStepActionExecution.getValue1();196 String value2 = testCaseStepActionExecution.getValue2();197 String value3 = testCaseStepActionExecution.getValue3();198 String propertyName = testCaseStepActionExecution.getPropertyName();199 LOG.debug("Doing Action : " + testCaseStepActionExecution.getAction() + " with value1 : " + value1 + " and value2 : " + value2 + " and value3 : " + value3);200 // When starting a new action, we reset the property list that was already calculated.201 tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());202 try {203 switch (testCaseStepActionExecution.getAction()) {204 case TestCaseStepAction.ACTION_CLICK:205 res = this.doActionClick(tCExecution, value1, value2);206 break;207 case TestCaseStepAction.ACTION_MOUSELEFTBUTTONPRESS:208 res = this.doActionMouseLeftButtonPress(tCExecution, value1, value2);209 break;210 case TestCaseStepAction.ACTION_MOUSELEFTBUTTONRELEASE:211 res = this.doActionMouseLeftButtonRelease(tCExecution, value1, value2);212 break;213 case TestCaseStepAction.ACTION_DOUBLECLICK:214 res = this.doActionDoubleClick(tCExecution, value1, value2);215 break;216 case TestCaseStepAction.ACTION_RIGHTCLICK:217 res = this.doActionRightClick(tCExecution, value1, value2);218 break;219 case TestCaseStepAction.ACTION_MOUSEOVER:220 res = this.doActionMouseOver(tCExecution, value1, value2);221 break;222 case TestCaseStepAction.ACTION_FOCUSTOIFRAME:223 res = this.doActionFocusToIframe(tCExecution, value1, value2);224 break;225 case TestCaseStepAction.ACTION_FOCUSDEFAULTIFRAME:226 res = this.doActionFocusDefaultIframe(tCExecution);227 break;228 case TestCaseStepAction.ACTION_SWITCHTOWINDOW:229 res = this.doActionSwitchToWindow(tCExecution, value1, value2);230 break;231 case TestCaseStepAction.ACTION_MANAGEDIALOG:232 res = this.doActionManageDialog(tCExecution, value1, value2);233 break;234 case TestCaseStepAction.ACTION_MANAGEDIALOGKEYPRESS:235 res = this.doActionManageDialogKeyPress(tCExecution, value1);236 break;237 case TestCaseStepAction.ACTION_OPENURLWITHBASE:238 res = this.doActionOpenURL(tCExecution, value1, value2, true);239 break;240 case TestCaseStepAction.ACTION_OPENURLLOGIN:241 testCaseStepActionExecution.setValue1(testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getCountryEnvironmentParameters().getUrlLogin());242 res = this.doActionUrlLogin(tCExecution);243 break;244 case TestCaseStepAction.ACTION_OPENURL:245 res = this.doActionOpenURL(tCExecution, value1, value2, false);246 break;247 case TestCaseStepAction.ACTION_EXECUTEJS:248 res = this.doActionExecuteJS(tCExecution, value1, value2);249 break;250 case TestCaseStepAction.ACTION_OPENAPP:251 res = this.doActionOpenApp(tCExecution, value1, value2);252 break;253 case TestCaseStepAction.ACTION_CLOSEAPP:254 res = this.doActionCloseApp(tCExecution, value1);255 break;256 case TestCaseStepAction.ACTION_SELECT:257 res = this.doActionSelect(tCExecution, value1, value2);258 break;259 case TestCaseStepAction.ACTION_KEYPRESS:260 res = this.doActionKeyPress(tCExecution, value1, value2);261 break;262 case TestCaseStepAction.ACTION_TYPE:263 res = this.doActionType(tCExecution, value1, value2, propertyName);264 break;265 case TestCaseStepAction.ACTION_HIDEKEYBOARD:266 res = this.doActionHideKeyboard(tCExecution);267 break;268 case TestCaseStepAction.ACTION_SWIPE:269 res = this.doActionSwipe(tCExecution, value1, value2);270 break;271 case TestCaseStepAction.ACTION_WAIT:272 res = this.doActionWait(tCExecution, value1, value2);273 break;274 case TestCaseStepAction.ACTION_WAITVANISH:275 res = this.doActionWaitVanish(tCExecution, value1);276 break;277 case TestCaseStepAction.ACTION_CALLSERVICE:278 res = this.doActionCallService(testCaseStepActionExecution, value1, value2, value3);279 break;280 case TestCaseStepAction.ACTION_EXECUTESQLUPDATE:281 res = this.doActionExecuteSQLUpdate(tCExecution, value1, value2);282 break;283 case TestCaseStepAction.ACTION_EXECUTESQLSTOREPROCEDURE:284 res = this.doActionExecuteSQLStoredProcedure(tCExecution, value1, value2);285 break;286 case TestCaseStepAction.ACTION_CALCULATEPROPERTY:287 res = this.doActionCalculateProperty(testCaseStepActionExecution, value1, value2);288 break;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 {451 return cerberusCommand.executeCerberusCommand(command);452 } catch (CerberusEventException e) {453 message = e.getMessageError();454 LOG.debug("Exception Running Shell :" + message.getMessage().getDescription());455 return message;456 }457 }458 private MessageEvent doActionClick(TestCaseExecution tCExecution, String value1, String value2) {459 String element;460 try {461 /**462 * Get element to use String object if not empty, String property if463 * object empty, throws Exception if both empty)464 */465 element = getElementToUse(value1, value2, TestCaseStepAction.ACTION_CLICK, tCExecution);466 /**467 * Get Identifier (identifier, locator) and check it's valid468 */469 Identifier identifier = identifierService.convertStringToIdentifier(element);470 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {471 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {472 identifierService.checkWebElementIdentifier(identifier.getIdentifier());473 return webdriverService.doSeleniumActionClick(tCExecution.getSession(), identifier, false, false);474 } else {475 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {476 return sikuliService.doSikuliActionClick(tCExecution.getSession(), identifier.getLocator(), "");477 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {478 return sikuliService.doSikuliActionClick(tCExecution.getSession(), "", identifier.getLocator());479 } else {480 identifierService.checkWebElementIdentifier(identifier.getIdentifier());481 return webdriverService.doSeleniumActionClick(tCExecution.getSession(), identifier, true, true);482 }483 }484 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {485 identifierService.checkWebElementIdentifier(identifier.getIdentifier());486 return androidAppiumService.click(tCExecution.getSession(), identifier);487 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {488 identifierService.checkWebElementIdentifier(identifier.getIdentifier());489 return iosAppiumService.click(tCExecution.getSession(), identifier);490 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {491 identifierService.checkSikuliIdentifier(identifier.getIdentifier());492 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {493 return sikuliService.doSikuliActionClick(tCExecution.getSession(), identifier.getLocator(), "");494 } else {495 return sikuliService.doSikuliActionClick(tCExecution.getSession(), "", identifier.getLocator());496 }497 } else {498 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)499 .resolveDescription("ACTION", "Click")500 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());501 }502 } catch (CerberusEventException ex) {503 LOG.fatal("Error doing Action Click :" + ex, ex);504 return ex.getMessageError();505 }506 }507 private MessageEvent doActionExecuteJS(TestCaseExecution tCExecution, String value1, String value2) {508 MessageEvent message;509 String script = value1;510 String valueFromJS;511 try {512 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {513 valueFromJS = this.webdriverService.getValueFromJS(tCExecution.getSession(), script);514 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_EXECUTEJS);515 message.setDescription(message.getDescription().replace("%SCRIPT%", script));516 message.setDescription(message.getDescription().replace("%VALUE%", valueFromJS));517 return message;518 }519 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);520 message.setDescription(message.getDescription().replace("%ACTION%", "executeJS"));521 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));522 return message;523 } catch (Exception e) {524 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTEJS);525 String messageString = e.getMessage().split("\n")[0];526 message.setDescription(message.getDescription().replace("%EXCEPTION%", messageString));527 LOG.debug("Exception Running JS Script :" + messageString);528 return message;529 }530 }531 private MessageEvent doActionMouseLeftButtonPress(TestCaseExecution tCExecution, String object, String property) {532 MessageEvent message;533 String element;534 try {535 /**536 * Get element to use String object if not empty, String property if537 * object empty, throws Exception if both empty)538 */539 element = getElementToUse(object, property, "mouseLeftButtonPress", tCExecution);540 /**541 * Get Identifier (identifier, locator)542 */543 Identifier identifier = identifierService.convertStringToIdentifier(element);544 identifierService.checkWebElementIdentifier(identifier.getIdentifier());545 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {546 return webdriverService.doSeleniumActionMouseDown(tCExecution.getSession(), identifier, true, true);547 }548 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);549 message.setDescription(message.getDescription().replace("%ACTION%", "MouseDown"));550 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));551 return message;552 } catch (CerberusEventException ex) {553 LOG.fatal("Error doing Action MouseDown :" + ex);554 return ex.getMessageError();555 }556 }557 private MessageEvent doActionRightClick(TestCaseExecution tCExecution, String object, String property) {558 MessageEvent message;559 String element;560 try {561 /**562 * Get element to use String object if not empty, String property if563 * object empty, throws Exception if both empty)564 */565 element = getElementToUse(object, property, "rightClick", tCExecution);566 /**567 * Get Identifier (identifier, locator)568 */569 Identifier identifier = identifierService.convertStringToIdentifier(element);570 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {571 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {572 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), identifier.getLocator(), "");573 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {574 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), "", identifier.getLocator());575 } else {576 identifierService.checkWebElementIdentifier(identifier.getIdentifier());577 return webdriverService.doSeleniumActionRightClick(tCExecution.getSession(), identifier);578 }579 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {580 identifierService.checkSikuliIdentifier(identifier.getIdentifier());581 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {582 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), identifier.getLocator(), "");583 } else {584 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), "", identifier.getLocator());585 }586 }587 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);588 message.setDescription(message.getDescription().replace("%ACTION%", "rightClick"));589 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));590 return message;591 } catch (CerberusEventException ex) {592 LOG.fatal("Error doing Action RightClick :" + ex);593 return ex.getMessageError();594 }595 }596 private MessageEvent doActionMouseLeftButtonRelease(TestCaseExecution tCExecution, String object, String property) {597 MessageEvent message;598 String element;599 try {600 /**601 * Get element to use String object if not empty, String property if602 * object empty, throws Exception if both empty)603 */604 element = getElementToUse(object, property, "mouseLeftButtonRelease", tCExecution);605 /**606 * Get Identifier (identifier, locator)607 */608 Identifier identifier = identifierService.convertStringToIdentifier(element);609 identifierService.checkWebElementIdentifier(identifier.getIdentifier());610 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {611 return webdriverService.doSeleniumActionMouseUp(tCExecution.getSession(), identifier, true, true);612 }613 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);614 message.setDescription(message.getDescription().replace("%ACTION%", "MouseUp"));615 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));616 return message;617 } catch (CerberusEventException ex) {618 LOG.fatal("Error doing Action MouseUp :" + ex);619 return ex.getMessageError();620 }621 }622 private MessageEvent doActionSwitchToWindow(TestCaseExecution tCExecution, String object, String property) {623 String element;624 try {625 /**626 * Get element to use String object if not empty, String property if627 * object empty, throws Exception if both empty)628 */629 element = getElementToUse(object, property, "switchToWindow", tCExecution);630 /**631 * Get Identifier (identifier, locator)632 */633 Identifier identifier = identifierService.convertStringToIdentifier(element);634 //identifierService.checkWebElementIdentifier(identifier.getIdentifier());635 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {636 return webdriverService.doSeleniumActionSwitchToWindow(tCExecution.getSession(), identifier);637 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {638 return androidAppiumService.switchToContext(tCExecution.getSession(), identifier);639 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {640 return iosAppiumService.switchToContext(tCExecution.getSession(), identifier);641 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {642 return sikuliService.doSikuliActionSwitchApp(tCExecution.getSession(), identifier.getLocator());643 } else {644 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)645 .resolveDescription("ACTION", "SwitchToWindow")646 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());647 }648 } catch (CerberusEventException ex) {649 LOG.fatal("Error doing Action SwitchToWindow :" + ex);650 return ex.getMessageError();651 }652 }653 private MessageEvent doActionManageDialog(TestCaseExecution tCExecution, String value1, String value2) {654 MessageEvent message;655 String element;656 try {657 /**658 * Get element to use String object if not empty, String property if659 * object empty, throws Exception if both empty)660 */661 element = getElementToUse(value1, value2, "manageDialog", tCExecution);662 /**663 * Get Identifier (identifier, locator)664 */665 Identifier identifier = identifierService.convertStringToIdentifier(element);666 identifierService.checkWebElementIdentifier(identifier.getIdentifier());667 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {668 return webdriverService.doSeleniumActionManageDialog(tCExecution.getSession(), identifier);669 }670 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);671 message.setDescription(message.getDescription().replace("%ACTION%", "ManageDialog"));672 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));673 return message;674 } catch (CerberusEventException ex) {675 LOG.fatal("Error doing Action ManageDialog :" + ex);676 return ex.getMessageError();677 }678 }679 private MessageEvent doActionManageDialogKeyPress(TestCaseExecution tCExecution, String value1) {680 MessageEvent message;681 String element;682 try {683 /**684 * Get element to use String object if not empty, String property if685 * object empty, throws Exception if both empty)686 */687 element = getElementToUse(value1, "", "manageDialogKeyPress", tCExecution);688 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {689 return webdriverService.doSeleniumActionManageDialogKeyPress(tCExecution.getSession(), element);690 }691 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);692 message.setDescription(message.getDescription().replace("%ACTION%", "ManageDialogKeypress"));693 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));694 return message;695 } catch (CerberusEventException ex) {696 LOG.fatal("Error doing Action ManageDialogKeypress :" + ex);697 return ex.getMessageError();698 }699 }700 private MessageEvent doActionDoubleClick(TestCaseExecution tCExecution, String object, String property) {701 MessageEvent message;702 String element;703 try {704 /**705 * Get element to use String object if not empty, String property if706 * object empty, throws Exception if both empty)707 */708 element = getElementToUse(object, property, "doubleClick", tCExecution);709 /**710 * Get Identifier (identifier, locator)711 */712 Identifier identifier = identifierService.convertStringToIdentifier(element);713 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {714 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {715 identifierService.checkWebElementIdentifier(identifier.getIdentifier());716 return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, false, false);717 } else {718 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {719 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");720 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {721 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());722 } else {723 identifierService.checkWebElementIdentifier(identifier.getIdentifier());724 return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, true);725 }726 }727 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)728 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {729 identifierService.checkWebElementIdentifier(identifier.getIdentifier());730 return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, false);731 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {732 identifierService.checkSikuliIdentifier(identifier.getIdentifier());733 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {734 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");735 } else {736 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());737 }738 }739 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);740 message.setDescription(message.getDescription().replace("%ACTION%", "doubleClick"));741 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));742 return message;743 } catch (CerberusEventException ex) {744 LOG.fatal("Error doing Action DoubleClick :" + ex);745 return ex.getMessageError();746 }747 }748 private MessageEvent doActionType(TestCaseExecution tCExecution, String object, String property, String propertyName) {749 try {750 /**751 * Check object and property are not null for GUI/APK/IPA Check752 * property is not null for FAT Application753 */754 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)755 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)756 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {757 if (object == null || property == null) {758 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);759 }760 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {761 if (property == null) {762 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);763 }764 }765 /**766 * Get Identifier (identifier, locator) if object not null767 */768 Identifier identifier = new Identifier();769 if (object != null) {770 identifier = identifierService.convertStringToIdentifier(object);771 }772 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {773 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {774 identifierService.checkWebElementIdentifier(identifier.getIdentifier());775 return webdriverService.doSeleniumActionType(tCExecution.getSession(), identifier, property, propertyName, false, false);776 } else {777 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {778 return sikuliService.doSikuliActionType(tCExecution.getSession(), identifier.getLocator(), property);779 } else {780 identifierService.checkWebElementIdentifier(identifier.getIdentifier());781 return webdriverService.doSeleniumActionType(tCExecution.getSession(), identifier, property, propertyName, true, true);782 }783 }784 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {785 return androidAppiumService.type(tCExecution.getSession(), identifier, property, propertyName);786 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {787 return iosAppiumService.type(tCExecution.getSession(), identifier, property, propertyName);788 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {789 String locator = "";790 if (!StringUtil.isNullOrEmpty(object)) {791 identifierService.checkSikuliIdentifier(identifier.getIdentifier());792 locator = identifier.getLocator();793 }794 return sikuliService.doSikuliActionType(tCExecution.getSession(), locator, property);795 } else {796 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)797 .resolveDescription("ACTION", "Type")798 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());799 }800 } catch (CerberusEventException ex) {801 LOG.fatal("Error doing Action Type : " + ex);802 return ex.getMessageError();803 }804 }805 private MessageEvent doActionMouseOver(TestCaseExecution tCExecution, String object, String property) {806 MessageEvent message;807 String element;808 try {809 /**810 * Get element to use String object if not empty, String property if811 * object empty, throws Exception if both empty)812 */813 element = getElementToUse(object, property, "mouseOver", tCExecution);814 /**815 * Get Identifier (identifier, locator)816 */817 Identifier identifier = identifierService.convertStringToIdentifier(element);818 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {819 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {820 identifierService.checkWebElementIdentifier(identifier.getIdentifier());821 return webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier, false, false);822 } else {823 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {824 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");825 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {826 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());827 } else {828 identifierService.checkWebElementIdentifier(identifier.getIdentifier());829 return webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier, true, true);830 }831 }832 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {833 identifierService.checkSikuliIdentifier(identifier.getIdentifier());834 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {835 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");836 } else {837 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());838 }839 }840 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);841 message.setDescription(message.getDescription().replace("%ACTION%", "mouseOver"));842 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));843 return message;844 } catch (CerberusEventException ex) {845 LOG.fatal("Error doing Action MouseOver :" + ex);846 return ex.getMessageError();847 }848 }849 private MessageEvent doActionMouseOverAndWait(TestCaseExecution tCExecution, String object, String property) {850 MessageEvent message;851 try {852 /**853 * Check object is not null854 */855 if (object == null) {856 return new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVERANDWAIT_GENERIC);857 }858 /**859 * Get Identifier (identifier, locator)860 */861 Identifier identifier = identifierService.convertStringToIdentifier(object);862 identifierService.checkWebElementIdentifier(identifier.getIdentifier());863 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {864 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {865 message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");866 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {867 message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());868 } else {869 message = webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier, true, true);870 }871 if (message.getCodeString().equals("OK")) {872 message = this.doActionWait(tCExecution, property, null);873 }874 return message;875 }876 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);877 message.setDescription(message.getDescription().replace("%ACTION%", "mouseOverAndWait"));878 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));879 return message;880 } catch (CerberusEventException ex) {881 LOG.fatal("Error doing Action MouseOverAndWait :" + ex);882 return ex.getMessageError();883 }884 }885 private MessageEvent doActionWait(TestCaseExecution tCExecution, String object, String property) {886 MessageEvent message;887 String element;888 long timeToWaitInMs = 0;889 Identifier identifier = null;890 try {891 /**892 * Get element to use String object if not empty, String property if893 * object empty, null if both are empty894 */895 element = getElementToUse(object, property, "wait", tCExecution);896 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)897 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)898 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)899 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) { // If application are Selenium or appium based, we have a session and can use it to wait.900 /**901 * if element is integer, set time to that value else Get902 * Identifier (identifier, locator)903 */904 if (StringUtil.isNullOrEmpty(element)) {905 timeToWaitInMs = tCExecution.getCerberus_action_wait_default();906 } else if (StringUtil.isInteger(element)) {907 timeToWaitInMs = Long.valueOf(element);908 } else {909 identifier = identifierService.convertStringToIdentifier(element);910 }911 if (identifier != null && identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {912 return sikuliService.doSikuliActionWait(tCExecution.getSession(), identifier.getLocator(), "");913 } else if (identifier != null && identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {914 return sikuliService.doSikuliActionWait(tCExecution.getSession(), "", identifier.getLocator());915 } else if (identifier != null) {916 identifierService.checkWebElementIdentifier(identifier.getIdentifier());917 return webdriverService.doSeleniumActionWait(tCExecution.getSession(), identifier);918 } else {919 return this.waitTime(timeToWaitInMs);920 }921 } else { // For any other application we wait for the integer value.922 if (StringUtil.isNullOrEmpty(element)) {923 // Get default wait from parameter924 timeToWaitInMs = tCExecution.getCerberus_action_wait_default();925 } else if (StringUtil.isInteger(element)) {926 timeToWaitInMs = Long.valueOf(element);927 }928 return this.waitTime(timeToWaitInMs);929 }930 } catch (CerberusEventException ex) {931 LOG.fatal("Error doing Action Wait :" + ex);932 return ex.getMessageError();933 }934 }935 private MessageEvent doActionKeyPress(TestCaseExecution tCExecution, String value1, String value2) {936 try {937 String appType = tCExecution.getApplicationObj().getType();938 /**939 * Check value1 and value2 are not null For IPA and APK, only value2940 * (key to press) is mandatory For GUI and FAT, both parameters are941 * mandatory942 */943 if (StringUtil.isNullOrEmpty(value2)) {944 return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_MISSINGKEY).resolveDescription("APPLICATIONTYPE", appType);945 }946 /**947 * Get Identifier (identifier, locator)948 */949 if (StringUtil.isNullOrEmpty(value1) && appType.equalsIgnoreCase(Application.TYPE_GUI)) {950 value1 = "xpath=//body";951 }952 Identifier objectIdentifier = identifierService.convertStringToIdentifier(value1);953 if (appType.equalsIgnoreCase(Application.TYPE_GUI)) {954 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.MAC.toString())955 || tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.IOS.toString())) {956 return iosAppiumService.keyPress(tCExecution.getSession(), value2);957 } else if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {958 return webdriverService.doSeleniumActionKeyPress(tCExecution.getSession(), objectIdentifier, value2, false, false);959 }960 if (objectIdentifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {961 return sikuliService.doSikuliActionKeyPress(tCExecution.getSession(), objectIdentifier.getLocator(), value2);962 } else {963 identifierService.checkWebElementIdentifier(objectIdentifier.getIdentifier());964 return webdriverService.doSeleniumActionKeyPress(tCExecution.getSession(), objectIdentifier, value2, true, true);965 }966 } else if (appType.equalsIgnoreCase(Application.TYPE_APK)) {967 return androidAppiumService.keyPress(tCExecution.getSession(), value2);968 } else if (appType.equalsIgnoreCase(Application.TYPE_IPA)) {969 return iosAppiumService.keyPress(tCExecution.getSession(), value2);970 } else if (appType.equalsIgnoreCase(Application.TYPE_FAT)) {971 return sikuliService.doSikuliActionKeyPress(tCExecution.getSession(), objectIdentifier.getLocator(), value2);972 } else {973 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)974 .resolveDescription("ACTION", "KeyPress")975 .resolveDescription("APPLICATIONTYPE", appType);976 }977 } catch (CerberusEventException ex) {978 LOG.debug("Error doing Action KeyPress :" + ex);979 return ex.getMessageError();980 } catch (Exception ex) {981 LOG.debug("Error doing Action KeyPress :" + ex);982 return new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC)983 .resolveDescription("DETAIL", ex.toString());984 }985 }986 private MessageEvent doActionOpenURL(TestCaseExecution tCExecution, String object, String property, boolean withBase) {987 MessageEvent message;988 String element;989 try {990 /**991 * Get element to use String object if not empty, String property if992 * object empty, throws Exception if both empty)993 */994 element = getElementToUse(object, property, "openUrl[WithBase]", tCExecution);995 /**996 * Get Identifier (identifier, locator)997 */998 Identifier identifier = new Identifier();999 identifier.setIdentifier("url");1000 identifier.setLocator(element);1001 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1002 return webdriverService.doSeleniumActionOpenURL(tCExecution.getSession(), tCExecution.getUrl(), identifier, withBase);1003 }1004 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1005 message.setDescription(message.getDescription().replace("%ACTION%", "OpenURL[WithBase]"));1006 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1007 return message;1008 } catch (CerberusEventException ex) {1009 LOG.fatal("Error doing Action OpenUrl :" + ex);1010 return ex.getMessageError();1011 }1012 }1013 private MessageEvent doActionOpenApp(TestCaseExecution tCExecution, String value1, String value2) {1014 MessageEvent message;1015 /**1016 * Check value1 is not null or empty1017 */1018 if (value1 == null || "".equals(value1)) {1019 return new MessageEvent(MessageEventEnum.ACTION_FAILED_OPENAPP);1020 }1021 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)1022 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1023 return sikuliService.doSikuliActionOpenApp(tCExecution.getSession(), value1);1024 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {1025 return androidAppiumService.openApp(tCExecution.getSession(), value1, value2);1026 }1027 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1028 message.setDescription(message.getDescription().replace("%ACTION%", "OpenApp"));1029 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1030 return message;1031 }1032 private MessageEvent doActionCloseApp(TestCaseExecution tCExecution, String value1) {1033 MessageEvent message;1034 /**1035 * Check value1 is not null or empty1036 */1037 if (value1 == null || "".equals(value1)) {1038 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLOSEAPP);1039 }1040 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)1041 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1042 return sikuliService.doSikuliActionCloseApp(tCExecution.getSession(), value1);1043 }1044 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1045 message.setDescription(message.getDescription().replace("%ACTION%", "CloseApp"));1046 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1047 return message;1048 }1049 private MessageEvent doActionWaitVanish(TestCaseExecution tCExecution, String value1) {1050 try {1051 /**1052 * Check value1 is not null or empty1053 */1054 if (value1 == null || "".equals(value1)) {1055 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLOSEAPP);1056 }1057 /**1058 * Get Identifier (identifier, locator)1059 */1060 Identifier identifier = identifierService.convertStringToIdentifier(value1);1061 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1062 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {1063 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), identifier.getLocator(), "");1064 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {1065 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), "", identifier.getLocator());1066 } else {1067 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1068 return webdriverService.doSeleniumActionWaitVanish(tCExecution.getSession(), identifier);1069 }1070 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)1071 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1072 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1073 return webdriverService.doSeleniumActionWaitVanish(tCExecution.getSession(), identifier);1074 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {1075 identifierService.checkSikuliIdentifier(identifier.getIdentifier());1076 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {1077 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), identifier.getLocator(), "");1078 } else {1079 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), "", identifier.getLocator());1080 }1081 } else {1082 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1083 .resolveDescription("ACTION", "WaitVanish")1084 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());1085 }1086 } catch (CerberusEventException ex) {1087 LOG.fatal("Error doing Action KeyPress :" + ex);1088 return ex.getMessageError();1089 }1090 }...

Full Screen

Full Screen

SikuliService

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.sikuli.impl.SikuliService;2import org.cerberus.service.sikuli.impl.SikuliServiceFactory;3import org.cerberus.service.sikuli.impl.SikuliServiceFactory.SikuliServiceType;4import org.cerberus.service.sikuli.impl.SikuliServiceFactory.SikuliServiceVersion;5SikuliService sikuliService = SikuliServiceFactory.getSikuliService(SikuliServiceType.JAVA, SikuliServiceVersion.V1_1_1);6sikuliService.doSomething();7sikuliService.doSomething(1, 2, "test", new Date());8String result = sikuliService.doSomething(1, 2, "test", new Date());9String result = (String) sikuliService.doSomething(1, 2, "test", new Date());10import org.cerberus.service.sikuli.impl.SikuliService;11import org.cerberus.service.sikuli.impl.SikuliServiceFactory;12import org.cerberus.service.sikuli.impl.SikuliServiceFactory.SikuliServiceType;13import org.cerberus.service.sikuli.impl.SikuliServiceFactory.SikuliServiceVersion;14SikuliService sikuliService = SikuliServiceFactory.getSikuliService(SikuliServiceType.JAVA, SikuliServiceVersion.V1_1_1);15sikuliService.doSomething();16sikuliService.doSomething(1, 2, "test", new Date());17String result = sikuliService.doSomething(1, 2, "test", new Date());18String result = (String) sikuliService.doSomething(1, 2, "test", new Date());19import

Full Screen

Full Screen

SikuliService

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.sikuli.impl.SikuliService2SikuliService sikuliService = new SikuliService()3sikuliService.setImagePath("C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg")4sikuliService.clickImage()5String imageText = sikuliService.getImageText()6print(imageText)7String imageText = sikuliService.getImageText("eng")8print(imageText)9String imageText = sikuliService.getImageText("eng","6")10print(imageText)11String imageText = sikuliService.getImageText("eng","6","3")12print(imageText)13String imageText = sikuliService.getImageText("eng","6","3","0,0,100,100")14print(imageText)15String imageText = sikuliService.getImageText("eng","6","3","0,0,100,100","C:\\Program Files (x86)\\Tesseract-OCR\\tessdata\\config.txt")16print(imageText)17String imageText = sikuliService.getImageText("eng","6","3","0,0,100,100","C:\\Program Files (x86)\\Tesseract-OCR\\tessdata\\config.txt","-l eng --oem 1 --psm 3")18print(imageText)19String imageText = sikuliService.getImageText("eng","6","3","0,0,100,100","C:\\Program Files (x86)\\Tesseract-OCR\\tessdata\\config.txt","-l eng --oem 1 --psm 3","C:\\

Full Screen

Full Screen

SikuliService

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.sikuli.impl.SikuliService;2SikuliService sikuliService = new SikuliService();3sikuliService.doSomething();4sikuliService.doSomethingElse();5sikuliService.doSomethingMore();6sikuliService.doSomethingEvenMore();7sikuliService.doSomethingAgain();8sikuliService.doSomethingAgainAndAgain();9sikuliService.doSomethingAgainAndAgainAndAgain();10sikuliService.doSomethingAgainAndAgainAndAgainAndAgain();11sikuliService.doSomethingAgainAndAgainAndAgainAndAgainAndAgain();12sikuliService.doSomethingAgainAndAgainAndAgainAndAgainAndAgainAndAgain();13sikuliService.doSomethingAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgain();14sikuliService.doSomethingAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgain();15sikuliService.doSomethingAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgain();16sikuliService.doSomethingAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgain();17sikuliService.doSomethingAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgain();18sikuliService.doSomethingAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgainAndAgain();

Full Screen

Full Screen

SikuliService

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.sikuli.impl.SikuliService2SikuliService sikuliService = new SikuliService()3SikuliService sikuliService = new SikuliService()4sikuliService.setImagePath("/path/to/image")5sikuliService.getImagePath()6sikuliService.setImagePath("/path/to/image")7sikuliService.getImagePath()8sikuliService.setImagePath("/path/to/image")9sikuliService.getImagePath()10sikuliService.setImagePath("/path/to/image")11sikuliService.getImagePath()12sikuliService.setImagePath("/path/to/image")13sikuliService.getImagePath()14sikuliService.setImagePath("/path/to/image")15sikuliService.getImagePath()16sikuliService.setImagePath("/path/to/image")17sikuliService.getImagePath()18sikuliService.setImagePath("/path/to/image")19sikuliService.getImagePath()20sikuliService.setImagePath("/path/to/image")21sikuliService.getImagePath()22sikuliService.setImagePath("/path/to/image")

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