How to use getSession method of org.cerberus.engine.execution.impl.RobotServerService class

Best Cerberus-source code snippet using org.cerberus.engine.execution.impl.RobotServerService.getSession

Source:ActionService.java Github

copy

Full Screen

...224 HashMap<String, String> optionsMap = robotServerService.getMapFromOptions(actionExecution.getOptions());225 if (optionsMap.containsKey(RobotServerService.OPTIONS_TIMEOUT_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX).isEmpty()) {226 Optional<Integer> timeoutOptionValue = Optional.ofNullable(Ints.tryParse(optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX)));227 if (timeoutOptionValue.isPresent()) {228 robotServerService.setOptionsTimeout(tCExecution.getSession(), timeoutOptionValue.get());229 } else {230 //TODO return a message alerting about the failed cast231 LOG.debug("failed to parse option value : {}", optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX));232 }233 }234 if (optionsMap.containsKey(RobotServerService.OPTIONS_HIGHLIGHTELEMENT_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_HIGHLIGHTELEMENT_SYNTAX).isEmpty()) {235 Optional<Integer> highlightOptionValue = Optional.ofNullable(Ints.tryParse(optionsMap.get(RobotServerService.OPTIONS_HIGHLIGHTELEMENT_SYNTAX)));236 if (highlightOptionValue.isPresent()) {237 robotServerService.setOptionsHighlightElement(tCExecution.getSession(), highlightOptionValue.get());238 } else {239 //TODO return a message alerting about the failed cast240 LOG.debug("failed to parse option value : {}", optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX));241 }242 }243 if (optionsMap.containsKey(RobotServerService.OPTIONS_MINSIMILARITY_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_MINSIMILARITY_SYNTAX).isEmpty()) {244 String minSimilarity = optionsMap.get(RobotServerService.OPTIONS_MINSIMILARITY_SYNTAX);245 robotServerService.setOptionsMinSimilarity(tCExecution.getSession(), minSimilarity);246 }247 if (optionsMap.containsKey(RobotServerService.OPTIONS_TYPEDELAY_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_TYPEDELAY_SYNTAX).isEmpty()) {248 String typeDelay = optionsMap.get(RobotServerService.OPTIONS_TYPEDELAY_SYNTAX);249 robotServerService.setOptionsTypeDelay(tCExecution.getSession(), typeDelay);250 }251 // Record picture= files at action level.252 Identifier identifier = identifierService.convertStringToIdentifier(value1);253 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isNullOrEmpty(identifier.getLocator())) {254 LOG.warn("Saving Image 1 on Action : " + identifier.getLocator());255 actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "1"));256 }257 identifier = identifierService.convertStringToIdentifier(value2);258 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isNullOrEmpty(identifier.getLocator())) {259 LOG.warn("Saving Image 2 on Action : " + identifier.getLocator());260 actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "2"));261 }262 try {263 switch (actionExecution.getAction()) {264 case TestCaseStepAction.ACTION_CLICK:265 res = this.doActionClick(tCExecution, value1, value2);266 break;267 case TestCaseStepAction.ACTION_LONGPRESS:268 res = this.doActionLongPress(tCExecution, value1, value2);269 break;270 case TestCaseStepAction.ACTION_MOUSELEFTBUTTONPRESS:271 res = this.doActionMouseLeftButtonPress(tCExecution, value1, value2);272 break;273 case TestCaseStepAction.ACTION_MOUSELEFTBUTTONRELEASE:274 res = this.doActionMouseLeftButtonRelease(tCExecution, value1, value2);275 break;276 case TestCaseStepAction.ACTION_MOUSEMOVE:277 res = this.doActionMouseMove(tCExecution, value1, value2);278 break;279 case TestCaseStepAction.ACTION_DOUBLECLICK:280 res = this.doActionDoubleClick(tCExecution, value1, value2);281 break;282 case TestCaseStepAction.ACTION_RIGHTCLICK:283 res = this.doActionRightClick(tCExecution, value1, value2);284 break;285 case TestCaseStepAction.ACTION_MOUSEOVER:286 res = this.doActionMouseOver(tCExecution, value1, value2);287 break;288 case TestCaseStepAction.ACTION_FOCUSTOIFRAME:289 res = this.doActionFocusToIframe(tCExecution, value1, value2);290 break;291 case TestCaseStepAction.ACTION_FOCUSDEFAULTIFRAME:292 res = this.doActionFocusDefaultIframe(tCExecution);293 break;294 case TestCaseStepAction.ACTION_SWITCHTOWINDOW:295 res = this.doActionSwitchToWindow(tCExecution, value1, value2);296 break;297 case TestCaseStepAction.ACTION_MANAGEDIALOG:298 res = this.doActionManageDialog(tCExecution, value1, value2);299 break;300 case TestCaseStepAction.ACTION_MANAGEDIALOGKEYPRESS:301 res = this.doActionManageDialogKeyPress(tCExecution, value1);302 break;303 case TestCaseStepAction.ACTION_OPENURLWITHBASE:304 res = this.doActionOpenURL(tCExecution, value1, value2, true);305 break;306 case TestCaseStepAction.ACTION_OPENURLLOGIN:307 actionExecution.setValue1(actionExecution.getTestCaseStepExecution().gettCExecution().getCountryEnvironmentParameters().getUrlLogin());308 res = this.doActionUrlLogin(tCExecution);309 break;310 case TestCaseStepAction.ACTION_OPENURL:311 res = this.doActionOpenURL(tCExecution, value1, value2, false);312 break;313 case TestCaseStepAction.ACTION_REFRESHCURRENTPAGE:314 res = this.doActionRefreshCurrentPage(tCExecution);315 break;316 case TestCaseStepAction.ACTION_EXECUTEJS:317 res = this.doActionExecuteJS(tCExecution, value1, value2);318 break;319 case TestCaseStepAction.ACTION_EXECUTECOMMAND:320 res = this.doActionExecuteCommand(tCExecution, value1, value2);321 break;322 case TestCaseStepAction.ACTION_EXECUTECERBERUSCOMMAND:323 res = this.doActionExecuteCerberusCommand(tCExecution, value1);324 break;325 case TestCaseStepAction.ACTION_OPENAPP:326 res = this.doActionOpenApp(tCExecution, value1, value2);327 break;328 case TestCaseStepAction.ACTION_CLOSEAPP:329 res = this.doActionCloseApp(tCExecution, value1);330 break;331 case TestCaseStepAction.ACTION_DRAGANDDROP:332 res = this.doActionDragAndDrop(tCExecution, value1, value2);333 break;334 case TestCaseStepAction.ACTION_SELECT:335 res = this.doActionSelect(tCExecution, value1, value2);336 break;337 case TestCaseStepAction.ACTION_KEYPRESS:338 res = this.doActionKeyPress(tCExecution, value1, value2, value3);339 break;340 case TestCaseStepAction.ACTION_TYPE:341 res = this.doActionType(tCExecution, value1, value2, propertyName);342 break;343 case TestCaseStepAction.ACTION_CLEARFIELD:344 res = this.doActionClearField(tCExecution, value1);345 break;346 case TestCaseStepAction.ACTION_HIDEKEYBOARD:347 res = this.doActionHideKeyboard(tCExecution);348 break;349 case TestCaseStepAction.ACTION_SWIPE:350 res = this.doActionSwipe(tCExecution, value1, value2);351 break;352 case TestCaseStepAction.ACTION_SCROLLTO:353 res = this.doActionScrollTo(tCExecution, value1, value2);354 break;355 case TestCaseStepAction.ACTION_INSTALLAPP:356 res = this.doActionInstallApp(tCExecution, value1);357 break;358 case TestCaseStepAction.ACTION_REMOVEAPP:359 res = this.doActionRemoveApp(tCExecution, value1);360 break;361 case TestCaseStepAction.ACTION_WAIT:362 res = this.doActionWait(tCExecution, value1, value2);363 break;364 case TestCaseStepAction.ACTION_WAITVANISH:365 res = this.doActionWaitVanish(tCExecution, value1);366 break;367 case TestCaseStepAction.ACTION_WAITNETWORKTRAFFICIDLE:368 res = this.doActionWaitNetworkTrafficIdle(tCExecution);369 break;370 case TestCaseStepAction.ACTION_CALLSERVICE:371 res = this.doActionCallService(actionExecution, value1, value2, value3);372 break;373 case TestCaseStepAction.ACTION_EXECUTESQLUPDATE:374 res = this.doActionExecuteSQLUpdate(tCExecution, value1, value2);375 break;376 case TestCaseStepAction.ACTION_EXECUTESQLSTOREPROCEDURE:377 res = this.doActionExecuteSQLStoredProcedure(tCExecution, value1, value2);378 break;379 case TestCaseStepAction.ACTION_CALCULATEPROPERTY:380 res = this.doActionCalculateProperty(actionExecution, value1, value2);381 break;382 case TestCaseStepAction.ACTION_SETNETWORKTRAFFICCONTENT:383 res = this.doActionSetNetworkTrafficContent(tCExecution, actionExecution, value1, value2);384 break;385 case TestCaseStepAction.ACTION_INDEXNETWORKTRAFFIC:386 res = this.doActionIndexNetworkTraffic(tCExecution, actionExecution, value1);387 break;388 case TestCaseStepAction.ACTION_SETCONSOLECONTENT:389 res = this.doActionSetConsoleContent(tCExecution, actionExecution, value1);390 break;391 case TestCaseStepAction.ACTION_SETSERVICECALLCONTENT:392 res = this.doActionSetServiceCallContent(tCExecution, actionExecution);393 break;394 case TestCaseStepAction.ACTION_SETCONTENT:395 res = this.doActionSetContent(tCExecution, actionExecution, value1);396 break;397 case TestCaseStepAction.ACTION_DONOTHING:398 res = new MessageEvent(MessageEventEnum.ACTION_SUCCESS);399 break;400 /**401 * DEPRECATED ACTIONS FROM HERE.402 */403 case TestCaseStepAction.ACTION_MOUSEOVERANDWAIT:404 res = this.doActionMouseOverAndWait(tCExecution, value1, value2);405 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());406 logEventService.createForPrivateCalls("ENGINE", "mouseOverAndWait", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + actionExecution.getTest() + "|" + actionExecution.getTestCase() + "']");407 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action mouseOverAndWait triggered by TestCase : ['" + actionExecution.getTest() + "'|'" + actionExecution.getTestCase() + "']");408 break;409 case TestCaseStepAction.ACTION_REMOVEDIFFERENCE:410 res = this.doActionRemoveDifference(actionExecution, value1, value2);411 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());412 logEventService.createForPrivateCalls("ENGINE", "removeDifference", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + actionExecution.getTest() + "|" + actionExecution.getTestCase() + "']");413 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action removeDifference triggered by TestCase : ['" + actionExecution.getTest() + "'|'" + actionExecution.getTestCase() + "']");414 break;415 default:416 res = new MessageEvent(MessageEventEnum.ACTION_FAILED_UNKNOWNACTION);417 res.setDescription(res.getDescription().replace("%ACTION%", actionExecution.getAction()));418 }419 } catch (final Exception unexpected) {420 LOG.error("Unexpected exception: " + unexpected.getMessage(), unexpected);421 res = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC).resolveDescription("DETAIL", unexpected.getMessage());422 }423 LOG.debug("Result of the action : " + res.getCodeString() + " " + res.getDescription());424 // Reset Timeout to default425 robotServerService.setOptionsToDefault(tCExecution.getSession());426 /**427 * In case 1/ the action is flagged as not fatal with a specific return428 * code = N and 2/ the return of the action is stopping the test -->429 * whatever the return of the action is, we force the return to move430 * forward the test with no screenshot, pagesource.431 */432 if (actionExecution.isFatal().equals("N") && res.isStopTest()) {433 res.setDescription(res.getDescription() + " -- Execution forced to continue.");434 res.setStopTest(false);435 res.setMessage(MessageGeneralEnum.EXECUTION_PE_TESTEXECUTING);436 }437 actionExecution.setActionResultMessage(res);438 /**439 * Determine here the impact of the Action on the full test return code440 * from the ResultMessage of the Action.441 */442 actionExecution.setExecutionResultMessage(new MessageGeneral(res.getMessage()));443 /**444 * Determine here if we stop the test from the ResultMessage of the445 * Action.446 */447 actionExecution.setStopExecution(res.isStopTest());448 /**449 * Timestamp stops here.450 */451 actionExecution.setEnd(new Date().getTime());452 return actionExecution;453 }454 private MessageEvent doActionInstallApp(TestCaseExecution tCExecution, String appPath) {455 MessageEvent message;456 try {457 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {458 return androidAppiumService.installApp(tCExecution.getSession(), appPath);459 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {460 return iosAppiumService.installApp(tCExecution.getSession(), appPath);461 }462 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);463 message.setDescription(message.getDescription().replace("%ACTION%", "scrollTo"));464 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));465 return message;466 } catch (Exception e) {467 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC);468 String messageString = e.getMessage().split("\n")[0];469 message.setDescription(message.getDescription().replace("%DETAIL%", messageString));470 LOG.debug("Exception Running install app :" + messageString, e);471 return message;472 }473 }474 private MessageEvent doActionRemoveApp(TestCaseExecution tCExecution, String appPackage) {475 MessageEvent message;476 try {477 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {478 return androidAppiumService.removeApp(tCExecution.getSession(), appPackage);479 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {480 return iosAppiumService.removeApp(tCExecution.getSession(), appPackage);481 }482 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);483 message.setDescription(message.getDescription().replace("%ACTION%", "scrollTo"));484 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));485 return message;486 } catch (Exception e) {487 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC);488 String messageString = e.getMessage().split("\n")[0];489 message.setDescription(message.getDescription().replace("%DETAIL%", messageString));490 LOG.debug("Exception Running remove app :" + messageString, e);491 return message;492 }493 }494 private MessageEvent doActionScrollTo(TestCaseExecution tCExecution, String element, String text) {495 MessageEvent message;496 try {497 Identifier identifier = null;498 if (!StringUtil.isNullOrEmpty(element)) {499 identifier = identifierService.convertStringToIdentifier(element);500 }501 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {502 return androidAppiumService.scrollTo(tCExecution.getSession(), identifier, text);503 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {504 return iosAppiumService.scrollTo(tCExecution.getSession(), identifier, text);505 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {506 return webdriverService.scrollTo(tCExecution.getSession(), identifier, text);507 }508 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);509 message.setDescription(message.getDescription().replace("%ACTION%", "scrollTo"));510 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));511 return message;512 } catch (Exception e) {513 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC);514 String messageString = e.getMessage().split("\n")[0];515 message.setDescription(message.getDescription().replace("%DETAIL%", messageString));516 LOG.debug("Exception Running scroll to :" + messageString, e);517 return message;518 }519 }520 private MessageEvent doActionExecuteCommand(TestCaseExecution tCExecution, String command, String args) {521 MessageEvent message;522 try {523 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {524 return androidAppiumService.executeCommand(tCExecution.getSession(), command, args);525 }526 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);527 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_EXECUTECOMMAND));528 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));529 return message;530 } catch (Exception e) {531 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTECOMMAND);532 String messageString = e.getMessage().split("\n")[0];533 message.setDescription(message.getDescription().replace("%EXCEPTION%", messageString));534 LOG.debug("Exception Running Shell :" + messageString, e);535 return message;536 }537 }538 private MessageEvent doActionExecuteCerberusCommand(TestCaseExecution tCExecution, String command) {539 MessageEvent message;540 try {541 return cerberusCommand.executeCerberusCommand(command);542 } catch (CerberusEventException e) {543 message = e.getMessageError();544 LOG.debug("Exception Running Shell :" + message.getMessage().getDescription());545 return message;546 }547 }548 private MessageEvent doActionClick(TestCaseExecution tCExecution, String value1, String value2) {549 String element;550 try {551 /**552 * Get element to use String object if not empty, String property if553 * object empty, throws Exception if both empty)554 */555 element = value1;556 /**557 * Get Identifier (identifier, locator) and check it's valid558 */559 Identifier identifier = identifierService.convertStringToIdentifier(element);560 LOG.debug("Click : " + identifier.toString());561 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {562 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {563 identifierService.checkWebElementIdentifier(identifier.getIdentifier());564 return webdriverService.doSeleniumActionClick(tCExecution.getSession(), identifier, false, false);565 } else {566 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {567 return sikuliService.doSikuliActionClick(tCExecution.getSession(), identifier.getLocator(), "");568 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {569 return sikuliService.doSikuliActionClick(tCExecution.getSession(), "", identifier.getLocator());570 } else {571 identifierService.checkWebElementIdentifier(identifier.getIdentifier());572 return webdriverService.doSeleniumActionClick(tCExecution.getSession(), identifier, true, true);573 }574 }575 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {576 identifierService.checkWebElementIdentifier(identifier.getIdentifier());577 return androidAppiumService.click(tCExecution.getSession(), identifier);578 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {579 identifierService.checkWebElementIdentifier(identifier.getIdentifier());580 return iosAppiumService.click(tCExecution.getSession(), identifier);581 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {582 if (StringUtil.isNullOrEmpty(identifier.getLocator())) {583 return sikuliService.doSikuliActionClick(tCExecution.getSession(), "", "");584 }585 identifierService.checkSikuliIdentifier(identifier.getIdentifier());586 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {587 return sikuliService.doSikuliActionClick(tCExecution.getSession(), identifier.getLocator(), "");588 } else {589 return sikuliService.doSikuliActionClick(tCExecution.getSession(), "", identifier.getLocator());590 }591 } else {592 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)593 .resolveDescription("ACTION", "Click")594 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());595 }596 } catch (CerberusEventException ex) {597 LOG.fatal("Error doing Action Click :" + ex, ex);598 return ex.getMessageError();599 }600 }601 private MessageEvent doActionExecuteJS(TestCaseExecution tCExecution, String value1, String value2) {602 MessageEvent message;603 String script = value1;604 String valueFromJS;605 try {606 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {607 valueFromJS = this.webdriverService.getValueFromJS(tCExecution.getSession(), script);608 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_EXECUTEJS);609 message.setDescription(message.getDescription().replace("%SCRIPT%", script));610 message.setDescription(message.getDescription().replace("%VALUE%", valueFromJS));611 return message;612 }613 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);614 message.setDescription(message.getDescription().replace("%ACTION%", "executeJS"));615 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));616 return message;617 } catch (Exception e) {618 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTEJS);619 String messageString = e.getMessage().split("\n")[0];620 message.setDescription(message.getDescription().replace("%EXCEPTION%", messageString));621 LOG.debug("Exception Running JS Script :" + messageString);622 return message;623 }624 }625 private MessageEvent doActionMouseLeftButtonPress(TestCaseExecution tCExecution, String value1, String value2) {626 MessageEvent message;627 String element;628 try {629 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT) || StringUtil.isNullOrEmpty(value1)) {630 // If value1 is empty, the Sikuli engine must be used in order to click without element to click.631 return sikuliService.doSikuliActionLeftButtonPress(tCExecution.getSession());632 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {633 /**634 * Get element to use String object if not empty, String635 * property if object empty, throws Exception if both empty)636 */637 element = getElementToUse(value1, value2, "mouseLeftButtonPress", tCExecution);638 /**639 * Get Identifier (identifier, locator)640 */641 Identifier identifier = identifierService.convertStringToIdentifier(value1);642 identifierService.checkWebElementIdentifier(identifier.getIdentifier());643 return webdriverService.doSeleniumActionMouseDown(tCExecution.getSession(), identifier, true, true);644 }645 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);646 message.setDescription(message.getDescription().replace("%ACTION%", "MouseDown"));647 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));648 return message;649 } catch (CerberusEventException ex) {650 LOG.fatal("Error doing Action MouseDown :" + ex);651 return ex.getMessageError();652 }653 }654 private MessageEvent doActionRightClick(TestCaseExecution tCExecution, String value1, String value2) {655 MessageEvent message;656 String element;657 try {658 /**659 * Get element to use String object if not empty, String property if660 * object empty, throws Exception if both empty)661 */662 element = value1;663 /**664 * Get Identifier (identifier, locator)665 */666 Identifier identifier = identifierService.convertStringToIdentifier(element);667 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {668 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {669 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), identifier.getLocator(), "");670 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {671 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), "", identifier.getLocator());672 } else {673 identifierService.checkWebElementIdentifier(identifier.getIdentifier());674 return webdriverService.doSeleniumActionRightClick(tCExecution.getSession(), identifier);675 }676 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {677 if (StringUtil.isNullOrEmpty(identifier.getLocator())) {678 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), "", "");679 }680 identifierService.checkSikuliIdentifier(identifier.getIdentifier());681 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {682 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), identifier.getLocator(), "");683 } else {684 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), "", identifier.getLocator());685 }686 }687 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);688 message.setDescription(message.getDescription().replace("%ACTION%", "rightClick"));689 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));690 return message;691 } catch (CerberusEventException ex) {692 LOG.fatal("Error doing Action RightClick :" + ex);693 return ex.getMessageError();694 }695 }696 private MessageEvent doActionMouseLeftButtonRelease(TestCaseExecution tCExecution, String value1, String value2) {697 MessageEvent message;698 String element;699 try {700 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT) || StringUtil.isNullOrEmpty(value1)) {701 // If value1 is empty, the Sikuli engine must be used in order to click without element to click.702 return sikuliService.doSikuliActionLeftButtonRelease(tCExecution.getSession());703 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {704 /**705 * Get element to use String object if not empty, String706 * property if object empty, throws Exception if both empty)707 */708 element = getElementToUse(value1, value2, "mouseLeftButtonRelease", tCExecution);709 /**710 * Get Identifier (identifier, locator)711 */712 Identifier identifier = identifierService.convertStringToIdentifier(element);713 identifierService.checkWebElementIdentifier(identifier.getIdentifier());714 return webdriverService.doSeleniumActionMouseUp(tCExecution.getSession(), identifier, true, true);715 }716 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);717 message.setDescription(message.getDescription().replace("%ACTION%", "MouseUp"));718 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));719 return message;720 } catch (CerberusEventException ex) {721 LOG.fatal("Error doing Action MouseUp :" + ex);722 return ex.getMessageError();723 }724 }725 private MessageEvent doActionMouseMove(TestCaseExecution tCExecution, String value1, String value2) {726 MessageEvent message;727 String element;728 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)729 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {730 return sikuliService.doSikuliActionMouseMove(tCExecution.getSession(), value1);731 }732 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);733 message.setDescription(message.getDescription().replace("%ACTION%", "MouseMove"));734 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));735 return message;736 }737 private MessageEvent doActionSwitchToWindow(TestCaseExecution tCExecution, String object, String property) {738 String element;739 try {740 /**741 * Get element to use String object if not empty, String property if742 * object empty, throws Exception if both empty)743 */744 element = getElementToUse(object, property, "switchToWindow", tCExecution);745 /**746 * Get Identifier (identifier, locator)747 */748 Identifier identifier = identifierService.convertStringToIdentifier(element);749 //identifierService.checkWebElementIdentifier(identifier.getIdentifier());750 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {751 return webdriverService.doSeleniumActionSwitchToWindow(tCExecution.getSession(), identifier);752 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {753 return androidAppiumService.switchToContext(tCExecution.getSession(), identifier);754 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {755 return iosAppiumService.switchToContext(tCExecution.getSession(), identifier);756 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {757 return sikuliService.doSikuliActionSwitchApp(tCExecution.getSession(), identifier.getLocator());758 } else {759 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)760 .resolveDescription("ACTION", "SwitchToWindow")761 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());762 }763 } catch (CerberusEventException ex) {764 LOG.fatal("Error doing Action SwitchToWindow :" + ex);765 return ex.getMessageError();766 }767 }768 private MessageEvent doActionManageDialog(TestCaseExecution tCExecution, String value1, String value2) {769 MessageEvent message;770 String element;771 try {772 /**773 * Get element to use String object if not empty, String property if774 * object empty, throws Exception if both empty)775 */776 element = getElementToUse(value1, value2, "manageDialog", tCExecution);777 /**778 * Get Identifier (identifier, locator)779 */780 Identifier identifier = identifierService.convertStringToIdentifier(element);781 identifierService.checkWebElementIdentifier(identifier.getIdentifier());782 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {783 return webdriverService.doSeleniumActionManageDialog(tCExecution.getSession(), identifier);784 }785 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);786 message.setDescription(message.getDescription().replace("%ACTION%", "ManageDialog"));787 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));788 return message;789 } catch (CerberusEventException ex) {790 LOG.fatal("Error doing Action ManageDialog :" + ex);791 return ex.getMessageError();792 }793 }794 private MessageEvent doActionManageDialogKeyPress(TestCaseExecution tCExecution, String value1) {795 MessageEvent message;796 String element;797 try {798 /**799 * Get element to use String object if not empty, String property if800 * object empty, throws Exception if both empty)801 */802 element = getElementToUse(value1, "", "manageDialogKeyPress", tCExecution);803 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {804 return webdriverService.doSeleniumActionManageDialogKeyPress(tCExecution.getSession(), element);805 }806 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);807 message.setDescription(message.getDescription().replace("%ACTION%", "ManageDialogKeypress"));808 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));809 return message;810 } catch (CerberusEventException ex) {811 LOG.fatal("Error doing Action ManageDialogKeypress :" + ex);812 return ex.getMessageError();813 }814 }815 private MessageEvent doActionDoubleClick(TestCaseExecution tCExecution, String value1, String value2) {816 MessageEvent message;817 String element;818 try {819 /**820 * Get element to use String object if not empty, String property if821 * object empty, throws Exception if both empty)822 */823 element = value1;824 /**825 * Get Identifier (identifier, locator)826 */827 Identifier identifier = identifierService.convertStringToIdentifier(element);828 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {829 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {830 identifierService.checkWebElementIdentifier(identifier.getIdentifier());831 return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, false, false);832 } else {833 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {834 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");835 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {836 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());837 } else {838 identifierService.checkWebElementIdentifier(identifier.getIdentifier());839 return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, true);840 }841 }842 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)843 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {844 identifierService.checkWebElementIdentifier(identifier.getIdentifier());845 return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, false);846 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {847 if (StringUtil.isNullOrEmpty(identifier.getLocator())) {848 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", "");849 }850 identifierService.checkSikuliIdentifier(identifier.getIdentifier());851 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {852 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");853 } else {854 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());855 }856 }857 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);858 message.setDescription(message.getDescription().replace("%ACTION%", "doubleClick"));859 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));860 return message;861 } catch (CerberusEventException ex) {862 LOG.fatal("Error doing Action DoubleClick :" + ex);863 return ex.getMessageError();864 }865 }866 private MessageEvent doActionType(TestCaseExecution tCExecution, String value1, String value2, String propertyName) {867 try {868 /**869 * Check object and property are not null for GUI/APK/IPA Check870 * property is not null for FAT Application871 */872 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)873 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)874 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {875 if (value1 == null || value2 == null) {876 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);877 }878 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {879 if (value2 == null) {880 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);881 }882 }883 /**884 * Get Identifier (identifier, locator) if object not null885 */886 Identifier identifier = new Identifier();887 if (value1 != null) {888 identifier = identifierService.convertStringToIdentifier(value1);889 }890 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {891 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {892 identifierService.checkWebElementIdentifier(identifier.getIdentifier());893 return webdriverService.doSeleniumActionType(tCExecution.getSession(), identifier, value2, propertyName, false, false);894 } else {895 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {896 return sikuliService.doSikuliActionType(tCExecution.getSession(), identifier.getLocator(), value2);897 } else {898 identifierService.checkWebElementIdentifier(identifier.getIdentifier());899 return webdriverService.doSeleniumActionType(tCExecution.getSession(), identifier, value2, propertyName, true, true);900 }901 }902 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {903 return androidAppiumService.type(tCExecution.getSession(), identifier, value2, propertyName);904 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {905 return iosAppiumService.type(tCExecution.getSession(), identifier, value2, propertyName);906 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {907 String locator = "";908 if (!StringUtil.isNullOrEmpty(value1)) {909 identifierService.checkSikuliIdentifier(identifier.getIdentifier());910 locator = identifier.getLocator();911 }912 return sikuliService.doSikuliActionType(tCExecution.getSession(), locator, value2);913 } else {914 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)915 .resolveDescription("ACTION", "Type")916 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());917 }918 } catch (CerberusEventException ex) {919 LOG.fatal("Error doing Action Type : " + ex);920 return ex.getMessageError();921 }922 }923 private MessageEvent doActionMouseOver(TestCaseExecution tCExecution, String object, String property) {924 MessageEvent message;925 String element;926 try {927 /**928 * Get element to use String object if not empty, String property if929 * object empty, throws Exception if both empty)930 */931 element = getElementToUse(object, property, "mouseOver", tCExecution);932 /**933 * Get Identifier (identifier, locator)934 */935 Identifier identifier = identifierService.convertStringToIdentifier(element);936 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {937 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {938 identifierService.checkWebElementIdentifier(identifier.getIdentifier());939 return webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier, false, false);940 } else {941 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {942 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");943 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {944 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());945 } else {946 identifierService.checkWebElementIdentifier(identifier.getIdentifier());947 return webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier, true, true);948 }949 }950 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {951 identifierService.checkSikuliIdentifier(identifier.getIdentifier());952 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {953 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");954 } else {955 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());956 }957 }958 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);959 message.setDescription(message.getDescription().replace("%ACTION%", "mouseOver"));960 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));961 return message;962 } catch (CerberusEventException ex) {963 LOG.fatal("Error doing Action MouseOver :" + ex);964 return ex.getMessageError();965 }966 }967 private MessageEvent doActionMouseOverAndWait(TestCaseExecution tCExecution, String object, String property) {968 MessageEvent message;969 try {970 /**971 * Check object is not null972 */973 if (object == null) {974 return new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVERANDWAIT_GENERIC);975 }976 /**977 * Get Identifier (identifier, locator)978 */979 Identifier identifier = identifierService.convertStringToIdentifier(object);980 identifierService.checkWebElementIdentifier(identifier.getIdentifier());981 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {982 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {983 message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");984 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {985 message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());986 } else {987 message = webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier, true, true);988 }989 if (message.getCodeString().equals("OK")) {990 message = this.doActionWait(tCExecution, property, null);991 }992 return message;993 }994 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);995 message.setDescription(message.getDescription().replace("%ACTION%", "mouseOverAndWait"));996 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));997 return message;998 } catch (CerberusEventException ex) {999 LOG.fatal("Error doing Action MouseOverAndWait :" + ex);1000 return ex.getMessageError();1001 }1002 }1003 private MessageEvent doActionWait(TestCaseExecution tCExecution, String value1, String value2) {1004 MessageEvent message;1005 String element;1006 long timeToWaitInMs = 0;1007 Identifier identifier = null;1008 try {1009 /**1010 * Get element to use String object if not empty, String property if1011 * object empty, null if both are empty1012 */1013 element = getElementToUse(value1, value2, "wait", tCExecution);1014 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)1015 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)1016 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)1017 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) { // If application are Selenium or appium based, we have a session and can use it to wait.1018 /**1019 * if element is integer, set time to that value else Get1020 * Identifier (identifier, locator)1021 */1022 if (StringUtil.isNullOrEmpty(element)) {1023 timeToWaitInMs = tCExecution.getCerberus_action_wait_default();1024 } else if (StringUtil.isInteger(element)) {1025 timeToWaitInMs = Long.valueOf(element);1026 } else {1027 identifier = identifierService.convertStringToIdentifier(element);1028 }1029 if (identifier != null && identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {1030 return sikuliService.doSikuliActionWait(tCExecution.getSession(), identifier.getLocator(), "");1031 } else if (identifier != null && identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {1032 return sikuliService.doSikuliActionWait(tCExecution.getSession(), "", identifier.getLocator());1033 } else if (identifier != null) {1034 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1035 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {1036 return androidAppiumService.wait(tCExecution.getSession(), identifier);1037 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1038 return iosAppiumService.wait(tCExecution.getSession(), identifier);1039 } else {1040 return webdriverService.doSeleniumActionWait(tCExecution.getSession(), identifier);1041 }1042 } else {1043 return this.waitTime(timeToWaitInMs);1044 }1045 } else { // For any other application we wait for the integer value.1046 if (StringUtil.isNullOrEmpty(element)) {1047 // Get default wait from parameter1048 timeToWaitInMs = tCExecution.getCerberus_action_wait_default();1049 } else if (StringUtil.isInteger(element)) {1050 timeToWaitInMs = Long.valueOf(element);1051 }1052 return this.waitTime(timeToWaitInMs);1053 }1054 } catch (CerberusEventException ex) {1055 LOG.fatal("Error doing Action Wait :" + ex);1056 return ex.getMessageError();1057 }1058 }1059 private MessageEvent doActionKeyPress(TestCaseExecution tCExecution, String element, String valueToKey, String modifier) {1060 try {1061 String appType = tCExecution.getApplicationObj().getType();1062 /**1063 * Check value1 and value2 are not null For IPA and APK, only value21064 * (key to press) is mandatory For GUI and FAT, both parameters are1065 * mandatory1066 */1067 if (StringUtil.isNullOrEmpty(valueToKey)) {1068 return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_MISSINGKEY).resolveDescription("APPLICATIONTYPE", appType);1069 }1070 /**1071 * Get Identifier (identifier, locator)1072 */1073 if (StringUtil.isNullOrEmpty(element) && appType.equalsIgnoreCase(Application.TYPE_GUI)) {1074 element = "xpath=//body";1075 }1076 Identifier objectIdentifier = identifierService.convertStringToIdentifier(element);1077 if (appType.equalsIgnoreCase(Application.TYPE_GUI)) {1078 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.MAC.toString())1079 || tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.IOS.toString())) {1080 return iosAppiumService.keyPress(tCExecution.getSession(), valueToKey);1081 } else if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {1082 return webdriverService.doSeleniumActionKeyPress(tCExecution.getSession(), objectIdentifier, valueToKey, false, false);1083 }1084 if (objectIdentifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {1085 return sikuliService.doSikuliActionKeyPress(tCExecution.getSession(), objectIdentifier.getLocator(), valueToKey, modifier);1086 } else {1087 identifierService.checkWebElementIdentifier(objectIdentifier.getIdentifier());1088 return webdriverService.doSeleniumActionKeyPress(tCExecution.getSession(), objectIdentifier, valueToKey, true, true);1089 }1090 } else if (appType.equalsIgnoreCase(Application.TYPE_APK)) {1091 return androidAppiumService.keyPress(tCExecution.getSession(), valueToKey);1092 } else if (appType.equalsIgnoreCase(Application.TYPE_IPA)) {1093 return iosAppiumService.keyPress(tCExecution.getSession(), valueToKey);1094 } else if (appType.equalsIgnoreCase(Application.TYPE_FAT)) {1095 return sikuliService.doSikuliActionKeyPress(tCExecution.getSession(), objectIdentifier.getLocator(), valueToKey, modifier);1096 } else {1097 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1098 .resolveDescription("ACTION", "KeyPress")1099 .resolveDescription("APPLICATIONTYPE", appType);1100 }1101 } catch (CerberusEventException ex) {1102 LOG.debug("Error doing Action KeyPress :" + ex);1103 return ex.getMessageError();1104 } catch (Exception ex) {1105 LOG.debug("Error doing Action KeyPress :" + ex);1106 return new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC)1107 .resolveDescription("DETAIL", ex.toString());1108 }1109 }1110 private MessageEvent doActionOpenURL(TestCaseExecution execution, String value1, String value2, boolean withBase) {1111 MessageEvent message;1112 String element;1113 try {1114 /**1115 * Get element to use String object if not empty, String property if1116 * object empty, throws Exception if both empty)1117 */1118 if (withBase && StringUtil.isNullOrEmpty(value1)) {1119 value1 = "/";1120 }1121 element = getElementToUse(value1, value2, "openUrl[WithBase]", execution);1122 /**1123 * Get Identifier (identifier, locator)1124 */1125 Identifier identifier = new Identifier();1126 identifier.setIdentifier("url");1127 identifier.setLocator(element);1128 if (execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1129 return webdriverService.doSeleniumActionOpenURL(execution.getSession(), execution.getUrl(), identifier, withBase);1130 }1131 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1132 message.setDescription(message.getDescription().replace("%ACTION%", "OpenURL[WithBase]"));1133 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", execution.getApplicationObj().getType()));1134 return message;1135 } catch (CerberusEventException ex) {1136 LOG.fatal("Error doing Action OpenUrl :" + ex);1137 return ex.getMessageError();1138 }1139 }1140 private MessageEvent doActionOpenApp(TestCaseExecution tCExecution, String value1, String value2) {1141 MessageEvent message;1142 /**1143 * Check value1 is not null or empty1144 */1145 if (value1 == null || "".equals(value1)) {1146 return new MessageEvent(MessageEventEnum.ACTION_FAILED_OPENAPP);1147 }1148 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)1149 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1150 return sikuliService.doSikuliActionOpenApp(tCExecution.getSession(), value1);1151 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {1152 return androidAppiumService.openApp(tCExecution.getSession(), value1, value2);1153 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1154 return iosAppiumService.openApp(tCExecution.getSession(), value1, value2);1155 }1156 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1157 message.setDescription(message.getDescription().replace("%ACTION%", "OpenApp"));1158 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1159 return message;1160 }1161 private MessageEvent doActionCloseApp(TestCaseExecution tCExecution, String value1) {1162 MessageEvent message;1163 /**1164 * Check value1 is not null or empty1165 */1166 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)1167 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1168 if (value1 == null || "".equals(value1)) {1169 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLOSEAPP);1170 }1171 return sikuliService.doSikuliActionCloseApp(tCExecution.getSession(), value1);1172 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {1173 return androidAppiumService.closeApp(tCExecution.getSession());1174 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1175 return iosAppiumService.closeApp(tCExecution.getSession());1176 }1177 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1178 message.setDescription(message.getDescription().replace("%ACTION%", "CloseApp"));1179 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1180 return message;1181 }1182 private MessageEvent doActionWaitVanish(TestCaseExecution tCExecution, String value1) {1183 try {1184 /**1185 * Check value1 is not null or empty1186 */1187 if (value1 == null || "".equals(value1)) {1188 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLOSEAPP);1189 }1190 /**1191 * Get Identifier (identifier, locator)1192 */1193 Identifier identifier = identifierService.convertStringToIdentifier(value1);1194 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1195 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {1196 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), identifier.getLocator(), "");1197 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {1198 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), "", identifier.getLocator());1199 } else {1200 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1201 return webdriverService.doSeleniumActionWaitVanish(tCExecution.getSession(), identifier);1202 }1203 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)1204 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1205 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1206 return webdriverService.doSeleniumActionWaitVanish(tCExecution.getSession(), identifier);1207 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {1208 identifierService.checkSikuliIdentifier(identifier.getIdentifier());1209 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {1210 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), identifier.getLocator(), "");1211 } else {1212 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), "", identifier.getLocator());1213 }1214 } else {1215 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1216 .resolveDescription("ACTION", "WaitVanish")1217 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());1218 }1219 } catch (CerberusEventException ex) {1220 LOG.fatal("Error doing Action KeyPress :" + ex);1221 return ex.getMessageError();1222 }1223 }1224 private MessageEvent doActionWaitNetworkTrafficIdle(TestCaseExecution tCExecution) {1225 try {1226 return executorService.waitForIdleNetwork(tCExecution.getRobotExecutorObj().getExecutorExtensionHost(), tCExecution.getRobotExecutorObj().getExecutorExtensionPort(),1227 tCExecution.getRemoteProxyUUID(), tCExecution.getSystem());1228 } catch (CerberusEventException ex) {1229 LOG.fatal("Error doing Action WaitNetworkTrafficIdle :" + ex);1230 return ex.getMessageError();1231 }1232 }1233 private MessageEvent doActionSelect(TestCaseExecution tCExecution, String value1, String value2) {1234 MessageEvent message;1235 try {1236 /**1237 * Check object and property are not null1238 */1239 if (StringUtil.isNullOrEmpty(value1) || StringUtil.isNullOrEmpty(value2)) {1240 return new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT);1241 }1242 /**1243 * Get Identifier (identifier, locator)1244 */1245 Identifier identifierValue1 = identifierService.convertStringToIdentifier(value1);1246 Identifier identifierValue2 = identifierService.convertStringToSelectIdentifier(value2);1247 identifierService.checkWebElementIdentifier(identifierValue1.getIdentifier());1248 identifierService.checkSelectOptionsIdentifier(identifierValue2.getIdentifier());1249 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)1250 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)1251 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1252 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {1253 return webdriverService.doSeleniumActionSelect(tCExecution.getSession(), identifierValue1, identifierValue2, false, false);1254 }1255 return webdriverService.doSeleniumActionSelect(tCExecution.getSession(), identifierValue1, identifierValue2, true, true);1256 }1257 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1258 message.setDescription(message.getDescription().replace("%ACTION%", "Select"));1259 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1260 return message;1261 } catch (CerberusEventException ex) {1262 LOG.fatal("Error doing Action Select :" + ex);1263 return ex.getMessageError();1264 }1265 }1266 private MessageEvent doActionUrlLogin(TestCaseExecution tCExecution) {1267 MessageEvent message;1268 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1269 return webdriverService.doSeleniumActionUrlLogin(tCExecution.getSession(), tCExecution.getUrl(), tCExecution.getCountryEnvironmentParameters().getUrlLogin());1270 }1271 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1272 message.setDescription(message.getDescription().replace("%ACTION%", "UrlLogin"));1273 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1274 return message;1275 }1276 private MessageEvent doActionFocusToIframe(TestCaseExecution tCExecution, String object, String property) {1277 MessageEvent message;1278 String element;1279 try {1280 /**1281 * Get element to use String object if not empty, String property if1282 * object empty, throws Exception if both empty)1283 */1284 element = getElementToUse(object, property, "focusToIframe", tCExecution);1285 /**1286 * Get Identifier (identifier, locator)1287 */1288 Identifier identifier = identifierService.convertStringToIdentifier(element);1289 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1290 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1291 return webdriverService.doSeleniumActionFocusToIframe(tCExecution.getSession(), identifier);1292 }1293 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1294 message.setDescription(message.getDescription().replace("%ACTION%", "FocusToIframe"));1295 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1296 return message;1297 } catch (CerberusEventException ex) {1298 LOG.fatal("Error doing Action FocusToIframe :" + ex);1299 return ex.getMessageError();1300 }1301 }1302 private MessageEvent doActionFocusDefaultIframe(TestCaseExecution tCExecution) {1303 MessageEvent message;1304 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1305 return webdriverService.doSeleniumActionFocusDefaultIframe(tCExecution.getSession());1306 }1307 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1308 message.setDescription(message.getDescription().replace("%ACTION%", "FocusDefaultIframe"));1309 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1310 return message;1311 }1312 public MessageEvent doActionDragAndDrop(TestCaseExecution tCExecution, String value1, String value2) throws IOException {1313 MessageEvent message;1314 try {1315 /**1316 * Check source and target are not null1317 */1318 if (StringUtil.isNullOrEmpty(value1)) {1319 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DRAGANDDROP);1320 message.setDescription(message.getDescription().replace("%ELEMENT%", value1));1321 return message;1322 } else if (StringUtil.isNullOrEmpty(value2)) {1323 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DRAGANDDROP);1324 message.setDescription(message.getDescription().replace("%ELEMENT%", value2));1325 return message;1326 }1327 Identifier identifierDrag = identifierService.convertStringToIdentifier(value1);1328 Identifier identifierDrop = identifierService.convertStringToIdentifier(value2);1329 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1330 identifierService.checkWebElementIdentifier(identifierDrag.getIdentifier());1331 identifierService.checkWebElementIdentifier(identifierDrop.getIdentifier());1332 if (identifierDrag.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)1333 && identifierDrop.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {1334 return sikuliService.doSikuliActionDragAndDrop(tCExecution.getSession(), identifierDrag, identifierDrop);1335 } else {1336 return webdriverService.doSeleniumActionDragAndDrop(tCExecution.getSession(), identifierDrag, identifierDrop, true, true);1337 }1338 }1339 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {1340 identifierService.checkSikuliIdentifier(identifierDrag.getIdentifier());1341 identifierService.checkSikuliIdentifier(identifierDrop.getIdentifier());1342 return sikuliService.doSikuliActionDragAndDrop(tCExecution.getSession(), identifierDrag, identifierDrop);1343 }1344 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1345 message.setDescription(message.getDescription().replace("%ACTION%", "Select"));1346 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1347 return message;1348 } catch (CerberusEventException ex) {1349 LOG.fatal("Error doing Action DragAndDrop :" + ex);1350 return ex.getMessageError();1351 }1352 }1353 private MessageEvent doActionCallService(TestCaseStepActionExecution testCaseStepActionExecution, String value1, String value2, String value3) {1354 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);1355 TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();1356 AnswerItem lastServiceCalledAnswer;1357 lastServiceCalledAnswer = serviceService.callService(value1, value2, value3, null, null, null, null, tCExecution);1358 message = lastServiceCalledAnswer.getResultMessage();1359 if (lastServiceCalledAnswer.getItem() != null) {1360 AppService lastServiceCalled = (AppService) lastServiceCalledAnswer.getItem();1361 tCExecution.setLastServiceCalled(lastServiceCalled);1362 tCExecution.setOriginalLastServiceCalled(lastServiceCalled.getResponseHTTPBody());1363 tCExecution.setOriginalLastServiceCalledContent(lastServiceCalled.getResponseHTTPBodyContentType());1364 /**1365 * Record the Request and Response in file system.1366 */1367 testCaseStepActionExecution.addFileList(recorderService.recordServiceCall(tCExecution, testCaseStepActionExecution, 0, null, lastServiceCalled));1368 }1369 return message;1370 }1371 private MessageEvent doActionRemoveDifference(TestCaseStepActionExecution testCaseStepActionExecution, String object, String property) {1372 // Filters differences from the given object pattern1373 String filteredDifferences = xmlUnitService.removeDifference(object, property);1374 // If filtered differences are null then service has returned with errors1375 if (filteredDifferences == null) {1376 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_REMOVEDIFFERENCE);1377 message.setDescription(message.getDescription().replace("%DIFFERENCE%", object));1378 message.setDescription(message.getDescription().replace("%DIFFERENCES%", property));1379 return message;1380 }1381 // Sets the property value to the new filtered one1382 for (TestCaseExecutionData data : testCaseStepActionExecution.getTestCaseExecutionDataList()) {1383 if (data.getProperty().equals(testCaseStepActionExecution.getPropertyName())) {1384 data.setValue(filteredDifferences);1385 break;1386 }1387 }1388 // Sends success1389 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_REMOVEDIFFERENCE);1390 message.setDescription(message.getDescription().replace("%DIFFERENCE%", object));1391 message.setDescription(message.getDescription().replace("%DIFFERENCES%", property));1392 return message;1393 }1394 private MessageEvent doActionCalculateProperty(TestCaseStepActionExecution testCaseStepActionExecution, String value1, String value2) {1395 MessageEvent message;1396 AnswerItem<String> answerDecode = new AnswerItem<>();1397 if (StringUtil.isNullOrEmpty(value1)) {1398 // Value1 is a mandatory parameter.1399 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_MISSINGPROPERTY);1400 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY));1401 } else {1402 try {1403 TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();1404 // Getting the Country property definition.1405 TestCaseCountryProperties tccp = null;1406 boolean propertyExistOnAnyCountry = false;1407 for (TestCaseCountryProperties object : tCExecution.getTestCaseCountryPropertyList()) {1408 if ((object.getProperty().equalsIgnoreCase(value1)) && (object.getCountry().equalsIgnoreCase(tCExecution.getCountry()))) {1409 tccp = object;1410 }1411 if ((object.getProperty().equalsIgnoreCase(value1))) {1412 propertyExistOnAnyCountry = true;1413 }1414 }1415 if (tccp == null) { // Could not find a country property inside the existing execution.1416 if (propertyExistOnAnyCountry) {1417 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NO_PROPERTY_DEFINITION);1418 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY)1419 .replace("%PROP%", value1)1420 .replace("%COUNTRY%", tCExecution.getCountry()));1421 return message;1422 } else {1423 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_PROPERTYNOTFOUND);1424 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY)1425 .replace("%PROP%", value1)1426 .replace("%COUNTRY%", tCExecution.getCountry()));1427 return message;1428 }1429 } else {1430 if (!(StringUtil.isNullOrEmpty(value2))) {1431 // If value2 is fed with something, we control here that value is a valid property name and gets its defintion.1432 tccp = null;1433 propertyExistOnAnyCountry = false;1434 for (TestCaseCountryProperties object : tCExecution.getTestCaseCountryPropertyList()) {1435 if ((object.getProperty().equalsIgnoreCase(value2)) && (object.getCountry().equalsIgnoreCase(tCExecution.getCountry()))) {1436 tccp = object;1437 }1438 if ((object.getProperty().equalsIgnoreCase(value2))) {1439 propertyExistOnAnyCountry = true;1440 }1441 }1442 if (tccp == null) { // Could not find a country property inside the existing execution.1443 if (propertyExistOnAnyCountry) {1444 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NO_PROPERTY_DEFINITION);1445 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY)1446 .replace("%PROP%", value2)1447 .replace("%COUNTRY%", tCExecution.getCountry()));1448 return message;1449 } else {1450 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_PROPERTYNOTFOUND);1451 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY)1452 .replace("%PROP%", value2)1453 .replace("%COUNTRY%", tCExecution.getCountry()));1454 return message;1455 }1456 }1457 }1458 // We calculate the property here.1459 long now = new Date().getTime();1460 TestCaseExecutionData tcExeData;1461 tcExeData = factoryTestCaseExecutionData.create(tCExecution.getId(), tccp.getProperty(), 1, tccp.getDescription(), null, tccp.getType(),1462 tccp.getRank(), tccp.getValue1(), tccp.getValue2(), null, null, now, now, now, now, new MessageEvent(MessageEventEnum.PROPERTY_PENDING),1463 tccp.getRetryNb(), tccp.getRetryPeriod(), tccp.getDatabase(), tccp.getValue1(), tccp.getValue2(), tccp.getLength(), tccp.getLength(),1464 tccp.getRowLimit(), tccp.getNature(), "", "", "", "", "", "N");1465 tcExeData.setTestCaseCountryProperties(tccp);1466 propertyService.calculateProperty(tcExeData, tCExecution, testCaseStepActionExecution, tccp, true);1467 // Property message goes to Action message.1468 message = tcExeData.getPropertyResultMessage();1469 if (message.getCodeString().equals("OK")) {1470 // If Property calculated successfully we summarize the message to a shorter version.1471 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CALCULATEPROPERTY);1472 message.resolveDescription("VALUE", tcExeData.getValue());1473 message.resolveDescription("PROP", value1);1474 if (tcExeData.getDataLibRawData() != null) {1475 message.setDescription(message.getDescription() + " %NBROWS% row(s) with %NBSUBDATA% Subdata(s) calculated."1476 .replace("%NBROWS%", String.valueOf(tcExeData.getDataLibRawData().size()))1477 .replace("%NBSUBDATA%", String.valueOf(tcExeData.getDataLibRawData().get(0).size())));1478 }1479 }1480 if (!(StringUtil.isNullOrEmpty(value2))) {1481 // If value2 is fed we force the result to value1.1482 tcExeData.setProperty(value1);1483 }1484 //saves the result1485 try {1486 testCaseExecutionDataService.save(tcExeData, tCExecution.getSecrets());1487 LOG.debug("Adding into Execution data list. Property : '" + tcExeData.getProperty() + "' Index : '" + tcExeData.getIndex() + "' Value : '" + tcExeData.getValue() + "'");1488 tCExecution.getTestCaseExecutionDataMap().put(tcExeData.getProperty(), tcExeData);1489 if (tcExeData.getDataLibRawData() != null) { // If the property is a TestDataLib, we same all rows retreived in order to support nature such as NOTINUSe or RANDOMNEW.1490 for (int i = 1; i < (tcExeData.getDataLibRawData().size()); i++) {1491 now = new Date().getTime();1492 TestCaseExecutionData tcedS = factoryTestCaseExecutionData.create(tcExeData.getId(), tcExeData.getProperty(), (i + 1),1493 tcExeData.getDescription(), tcExeData.getDataLibRawData().get(i).get(""), tcExeData.getType(), tcExeData.getRank(), "", "",1494 tcExeData.getRC(), "", now, now, now, now, null, 0, 0, "", "", "", "", "", 0, "", "", "", "", "", "", "N");1495 testCaseExecutionDataService.save(tcedS, tCExecution.getSecrets());1496 }1497 }1498 } catch (CerberusException cex) {1499 LOG.error(cex.getMessage(), cex);1500 }1501 }1502 } catch (Exception ex) {1503 LOG.error(ex.toString(), ex);1504 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC).resolveDescription("DETAIL", ex.toString());1505 }1506 }1507 return message;1508 }1509 private MessageEvent doActionSetNetworkTrafficContent(TestCaseExecution exe, TestCaseStepActionExecution actionexe, String urlToFilter, String withResponseContent) throws IOException {1510 MessageEvent message;1511 try {1512 // Check that robot has executor activated1513 if (!"Y".equalsIgnoreCase(exe.getRobotExecutorObj().getExecutorProxyActive()) || StringUtil.isNullOrEmpty(exe.getRobotExecutorObj().getExecutorProxyHost())) {1514 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SETNETWORKTRAFFICCONTENT_ROBOTEXECUTORPROXYNOTACTIVATED);1515 message.setDescription(message.getDescription().replace("%ROBOT%", exe.getRobotExecutorObj().getRobot()).replace("%EXECUTOR%", exe.getRobotExecutorObj().getExecutor()));1516 return message;1517 }1518 LOG.debug("Getting Network Traffic content.");1519 Integer indexFrom = 0;1520 if (!exe.getNetworkTrafficIndexList().isEmpty()) {1521 // Take the value from the last entry.1522 indexFrom = exe.getNetworkTrafficIndexList().get(exe.getNetworkTrafficIndexList().size() - 1).getIndexRequestNb();1523 }1524 // We now get the har data.1525 boolean doWithResponse = ParameterParserUtil.parseBooleanParam(withResponseContent, false);1526 JSONObject har = executorService.getHar(urlToFilter, doWithResponse, exe.getRobotExecutorObj().getExecutorExtensionHost(), exe.getRobotExecutorObj().getExecutorExtensionPort(), exe.getRemoteProxyUUID(), exe.getSystem(), indexFrom);1527 har = harService.enrichWithStats(har, exe.getCountryEnvironmentParameters().getDomain(), exe.getSystem(), exe.getNetworkTrafficIndexList());1528 AppService appSrv = factoryAppService.create("", AppService.TYPE_REST, AppService.METHOD_HTTPGET, "", "", "", "", "", "", "", "", "", "", "", true, "", "", false, "", "", "", null, "", null, null);1529 appSrv.setResponseHTTPBody(har.toString());1530 appSrv.setResponseHTTPBodyContentType(AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON);1531 appSrv.setRecordTraceFile(false);1532 exe.setLastServiceCalled(appSrv);1533 /**1534 * Record the Request and Response in file system.1535 */1536 actionexe.addFileList(recorderService.recordNetworkTrafficContent(exe, actionexe, 0, null, appSrv, true));1537 // Forcing the apptype to SRV in order to allow all controls to plug to the json context of the har.1538 exe.setAppTypeEngine(Application.TYPE_SRV);1539 if (!exe.getNetworkTrafficIndexList().isEmpty()) {1540 // Message will include the index and request nb when the content start.1541 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SETNETWORKTRAFFICCONTENT).resolveDescription("INDEX", String.valueOf(exe.getNetworkTrafficIndexList().size())).resolveDescription("NBHITS", String.valueOf(indexFrom));1542 } else {1543 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SETNETWORKTRAFFICCONTENT_FROMINDEX0);1544 }1545 return message;1546 } catch (Exception ex) {1547 LOG.error("Error doing Action setNetworkTrafficContent :" + ex, ex);1548 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SETNETWORKTRAFFICCONTENT);1549 message.setDescription(message.getDescription().replace("%DETAIL%", ex.toString()));1550 return message;1551 }1552 }1553 private MessageEvent doActionIndexNetworkTraffic(TestCaseExecution exe, TestCaseStepActionExecution actionexe, String value1) throws IOException {1554 MessageEvent message;1555 try {1556 // Check that robot has executor activated1557 if (!"Y".equalsIgnoreCase(exe.getRobotExecutorObj().getExecutorProxyActive()) || StringUtil.isNullOrEmpty(exe.getRobotExecutorObj().getExecutorProxyHost())) {1558 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_INDEXNETWORKTRAFFIC_ROBOTEXECUTORPROXYNOTACTIVATED);1559 message.setDescription(message.getDescription().replace("%ROBOT%", exe.getRobotExecutorObj().getRobot()).replace("%EXECUTOR%", exe.getRobotExecutorObj().getExecutor()));1560 return message;1561 }1562 LOG.debug("Getting Network Traffic index");1563 /**1564 * Building the url to get the Latest index from cerberus-executor1565 */1566 Integer nbHits = executorService.getHitsNb(exe.getRobotExecutorObj().getExecutorExtensionHost(), exe.getRobotExecutorObj().getExecutorExtensionPort(), exe.getRemoteProxyUUID());1567 NetworkTrafficIndex nti = new NetworkTrafficIndex();1568 if (StringUtil.isNullOrEmpty(value1)) {1569 value1 = "INDEX" + (exe.getNetworkTrafficIndexList().size() + 1);1570 }1571 nti.setName(value1);1572 nti.setIndexRequestNb(nbHits);1573 exe.appendNetworkTrafficIndexList(nti);1574 LOG.debug("New Index : " + exe.getNetworkTrafficIndexList());1575 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_INDEXNETWORKTRAFFIC).resolveDescription("NB", nbHits.toString()).resolveDescription("INDEX", String.valueOf(exe.getNetworkTrafficIndexList().size()));1576 return message;1577 } catch (Exception ex) {1578 LOG.error("Error doing Action indexNetworkTraffic :" + ex, ex);1579 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_INDEXNETWORKTRAFFIC);1580 message.setDescription(message.getDescription().replace("%DETAIL%", ex.toString()));1581 return message;1582 }1583 }1584 private MessageEvent doActionSetConsoleContent(TestCaseExecution exe, TestCaseStepActionExecution actionexe, String textToFilter) throws IOException {1585 MessageEvent message;1586 try {1587 /**1588 * Building the url to get the Har file from cerberus-executor1589 */1590 LOG.debug("Getting Console Logs content.");1591 JSONObject consoleRecap = new JSONObject();1592 JSONArray consoleLogs = webdriverService.getJSONConsoleLog(exe.getSession());1593 consoleRecap.put("logs", consoleLogs);1594 JSONObject consoleStat = new JSONObject();1595 consoleStat = consolelogService.enrichWithStats(consoleLogs);1596 consoleRecap.put("stat", consoleStat);1597 AppService appSrv = factoryAppService.create("", "", "", "", "", "", "", "", "", "", "", "", "", "", false, "", "", false, "", null, "", null, "", null, "");1598 appSrv.setResponseHTTPBody(consoleRecap.toString());1599 appSrv.setResponseHTTPBodyContentType(AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON);1600 appSrv.setRecordTraceFile(false);1601 exe.setLastServiceCalled(appSrv);1602 /**1603 * Record the Request and Response in file system.1604 */1605 actionexe.addFileList(recorderService.recordConsoleContent(exe, actionexe, 0, null, consoleRecap, true));1606 // Forcing the apptype to SRV in order to allow all controls to plug to the json context of the har.1607 exe.setAppTypeEngine(Application.TYPE_SRV);1608 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SETCONSOLECONTENT);1609 return message;1610 } catch (Exception ex) {1611 LOG.error("Error doing Action setNetworkTrafficContent :" + ex);1612 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SETCONSOLECONTENT);1613 message.setDescription(message.getDescription().replace("%DETAIL%", ex.toString()));1614 return message;1615 }1616 }1617 private MessageEvent doActionSetContent(TestCaseExecution exe, TestCaseStepActionExecution actionexe, String textContent) throws IOException {1618 MessageEvent message;1619 try {1620 /**1621 * Building the url to get the Har file from cerberus-executor1622 */1623 LOG.debug("Setting static content.");1624 AppService appSrv = factoryAppService.create("", "", "", "", "", "", "", "", "", "", "", "", "", "", false, "", "", false, "", "", "", null, "", null, "");1625 appSrv.setResponseHTTPBody(textContent);1626 appSrv.setResponseHTTPBodyContentType(appServiceService.guessContentType(appSrv, AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON));1627 appSrv.setRecordTraceFile(false);1628 exe.setLastServiceCalled(appSrv);1629 /**1630 * Record the Request and Response in file system.1631 */1632 actionexe.addFileList(recorderService.recordContent(exe, actionexe, 0, null, textContent, appSrv.getResponseHTTPBodyContentType()));1633 // Forcing the apptype to SRV in order to allow all controls to plug to the json context of the har.1634 exe.setAppTypeEngine(Application.TYPE_SRV);1635 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SETCONTENT);1636 message.resolveDescription("TYPE", appSrv.getResponseHTTPBodyContentType());1637 return message;1638 } catch (Exception ex) {1639 LOG.error("Error doing Action setNetworkTrafficContent :" + ex);1640 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SETCONTENT);1641 message.setDescription(message.getDescription().replace("%DETAIL%", ex.toString()));1642 return message;1643 }1644 }1645 public MessageEvent doActionSetServiceCallContent(TestCaseExecution exe, TestCaseStepActionExecution actionexe) throws IOException {1646 MessageEvent message;1647 try {1648 // Check that robot has executor activated1649 if (exe.getLastServiceCalled() == null) {1650 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SETSERVICECALLCONTENT_NOLASTCALLDONE);1651 return message;1652 }1653 // Force last service call content to JSON Service Call Structure & disable file save.1654 exe.getLastServiceCalled().setResponseHTTPBody(exe.getLastServiceCalled().toJSONOnExecution().toString());1655 exe.getLastServiceCalled().setResponseHTTPBodyContentType(AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON);1656 exe.getLastServiceCalled().setRecordTraceFile(false);1657 /**1658 * Record the Request and Response in file system.1659 */1660 actionexe.addFileList(recorderService.recordServiceCallContent(exe, actionexe, exe.getLastServiceCalled()));1661 // Forcing the apptype to SRV in order to allow all controls to plug to the json context of the har.1662 exe.setAppTypeEngine(Application.TYPE_SRV);1663 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SETSERVICECALLCONTENT);1664 return message;1665 } catch (Exception ex) {1666 LOG.error("Error doing Action setServiceCallContent :" + ex);1667 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SETSERVICECALLCONTENT);1668 message.setDescription(message.getDescription().replace("%DETAIL%", ex.toString()));1669 return message;1670 }1671 }1672 private String getElementToUse(String value1, String value2, String action, TestCaseExecution execution) throws CerberusEventException {1673 if (!StringUtil.isNullOrEmpty(value1)) {1674 return value1;1675 } else if (!StringUtil.isNullOrEmpty(value2)) {1676 logEventService.createForPrivateCalls("ENGINE", action, MESSAGE_DEPRECATED + " Beware, in future release, it won't be allowed to use action without using field value1. Triggered by TestCase : ['" + execution.getTest() + "'|'" + execution.getTestCase() + "'] Property : " + value2);1677 LOG.warn(MESSAGE_DEPRECATED + " Action : " + action + ". Beware, in future release, it won't be allowed to use action without using field value1. Triggered by TestCase : ['" + execution.getTest() + "'|'" + execution.getTestCase() + "'] Property : " + value2);1678 return value2;1679 }1680 if (!(action.equals("wait"))) { // Wait is the only action can be excuted with no parameters. For all other actions we raize an exception as this should never happen.1681 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_NO_ELEMENT_TO_PERFORM_ACTION);1682 message.setDescription(message.getDescription().replace("%ACTION%", action));1683 throw new CerberusEventException(message);1684 }1685 return null;1686 }1687 private MessageEvent waitTime(Long timeToWaitMs) {1688 MessageEvent message;1689 /**1690 * if timeToWait is null, throw CerberusException1691 */1692 if (timeToWaitMs == 0) {1693 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_INVALID_FORMAT);1694 return message;1695 }1696 try {1697 LOG.debug("TIME TO WAIT = " + timeToWaitMs);1698 Thread.sleep(timeToWaitMs);1699 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_TIME);1700 message.setDescription(message.getDescription().replace("%TIME%", String.valueOf(timeToWaitMs)));1701 return message;1702 } catch (InterruptedException exception) {1703 LOG.warn(exception.toString());1704 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_TIME_WITHWARNINGS);1705 message.setDescription(message.getDescription()1706 .replace("%TIME%", String.valueOf(timeToWaitMs))1707 .replace("%MESSAGE%", exception.toString()));1708 return message;1709 }1710 }1711 private MessageEvent doActionExecuteSQLUpdate(TestCaseExecution tCExecution, String object, String property) {1712 return sqlService.executeUpdate(tCExecution.getApplicationObj().getSystem(),1713 tCExecution.getCountry(), tCExecution.getEnvironment(), object, property);1714 }1715 private MessageEvent doActionExecuteSQLStoredProcedure(TestCaseExecution tCExecution, String object, String property) {1716 return sqlService.executeCallableStatement(tCExecution.getApplicationObj().getSystem(),1717 tCExecution.getCountry(), tCExecution.getEnvironment(), object, property);1718 }1719 private MessageEvent doActionHideKeyboard(TestCaseExecution tCExecution) {1720 // Check argument1721 if (tCExecution == null) {1722 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);1723 }1724 // Hide keyboard according to application type1725 String applicationType = tCExecution.getApplicationObj().getType();1726 if (Application.TYPE_APK.equals(applicationType)) {1727 return androidAppiumService.hideKeyboard(tCExecution.getSession());1728 }1729 if (Application.TYPE_IPA.equals(applicationType)) {1730 return iosAppiumService.hideKeyboard(tCExecution.getSession());1731 }1732 // Else we are faced with a non supported application1733 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1734 .resolveDescription("ACTION", "Hide keyboard")1735 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());1736 }1737 private MessageEvent doActionSwipe(TestCaseExecution tCExecution, String object, String property) {1738 // Check arguments1739 if (tCExecution == null || object == null) {1740 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);1741 }1742 // Create the associated swipe action to the given arguments1743 SwipeAction action = null;1744 try {1745 action = SwipeAction.fromStrings(object, property);1746 } catch (Exception e) {1747 return new MessageEvent(MessageEventEnum.ACTION_FAILED_SWIPE)1748 .resolveDescription("DIRECTION", action == null ? "Unknown" : action.getActionType().name())1749 .resolveDescription("REASON", e.getMessage());1750 }1751 // Swipe screen according to the application type1752 String applicationType = tCExecution.getApplicationObj().getType();1753 if (Application.TYPE_APK.equals(applicationType)) {1754 return androidAppiumService.swipe(tCExecution.getSession(), action);1755 }1756 if (Application.TYPE_IPA.equals(applicationType)) {1757 return iosAppiumService.swipe(tCExecution.getSession(), action);1758 }1759 // Else we are faced with a non supported application1760 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1761 .resolveDescription("ACTION", "Swipe screen")1762 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());1763 }1764 private MessageEvent doActionLongPress(TestCaseExecution tCExecution, String value1, String value2) {1765 String element;1766 try {1767 /**1768 * Get element to use String object if not empty, String property if1769 * object empty, throws Exception if both empty)1770 */1771 element = getElementToUse(value1, value2, TestCaseStepAction.ACTION_LONGPRESS, tCExecution);1772 /**1773 * Get Identifier (identifier, locator) and check it's valid1774 */1775 Integer longPressTime = 8000;1776 try {1777 longPressTime = Integer.parseInt(value2);1778 } catch (NumberFormatException e) {1779 // do nothing1780 }1781 Identifier identifier = identifierService.convertStringToIdentifier(element);1782 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {1783 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1784 return androidAppiumService.longPress(tCExecution.getSession(), identifier, longPressTime);1785 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1786 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1787 return iosAppiumService.longPress(tCExecution.getSession(), identifier, longPressTime);1788 } else {1789 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1790 .resolveDescription("ACTION", "Long Click")1791 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());1792 }1793 } catch (CerberusEventException ex) {1794 LOG.fatal("Error doing Action Click :" + ex, ex);1795 return ex.getMessageError();1796 }1797 }1798 private MessageEvent doActionClearField(TestCaseExecution tCExecution, String value1) {1799 String element;1800 try {1801 /**1802 * Check object and property are not null for GUI/APK/IPA Check1803 * property is not null for FAT Application1804 */1805 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)1806 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1807 if (value1 == null) {1808 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLEARFIELD);1809 }1810 }1811 /**1812 * Get Identifier (identifier, locator) if object not null1813 */1814 Identifier identifier = new Identifier();1815 if (value1 != null) {1816 identifier = identifierService.convertStringToIdentifier(value1);1817 }1818 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {1819 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1820 return androidAppiumService.clearField(tCExecution.getSession(), identifier);1821 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1822 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1823 return iosAppiumService.clearField(tCExecution.getSession(), identifier);1824 } else {1825 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1826 .resolveDescription("ACTION", "ClearField")1827 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());1828 }1829 } catch (CerberusEventException ex) {1830 LOG.fatal("Error doing Action Type : " + ex);1831 return ex.getMessageError();1832 }1833 }1834 private MessageEvent doActionRefreshCurrentPage(TestCaseExecution tCExecution) {1835 MessageEvent message;1836 try {1837 LOG.debug("REFRESH CURRENT PAGE");1838 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1839 return this.webdriverService.doSeleniumActionRefreshCurrentPage(tCExecution.getSession());1840 }1841 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1842 message.setDescription(message.getDescription().replace("%ACTION%", "refreshCurrentPage"));1843 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1844 return message;1845 } catch (Exception e) {1846 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_REFRESHCURRENTPAGE);1847 String messageString = e.getMessage().split("\n")[0];1848 message.setDescription(message.getDescription().replace("%DETAIL%", messageString));1849 LOG.debug("Exception doing action refreshCurrentPage :" + messageString, e);1850 return message;1851 }1852 }1853}...

Full Screen

Full Screen

Source:ControlService.java Github

copy

Full Screen

...187 HashMap<String, String> optionsMap = robotServerService.getMapFromOptions(controlExecution.getOptions());188 if (optionsMap.containsKey(RobotServerService.OPTIONS_TIMEOUT_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX).isEmpty()) {189 Optional<Integer> timeoutOptionValue = Optional.ofNullable(Ints.tryParse(optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX)));190 if (timeoutOptionValue.isPresent()) {191 robotServerService.setOptionsTimeout(execution.getSession(), timeoutOptionValue.get());192 } else {193 //TODO return a message alerting about the failed cast194 LOG.debug("failed to parse option value : {}", optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX));195 }196 }197 if (optionsMap.containsKey(RobotServerService.OPTIONS_HIGHLIGHTELEMENT_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_HIGHLIGHTELEMENT_SYNTAX).isEmpty()) {198 Optional<Integer> highlightOptionValue = Optional.ofNullable(Ints.tryParse(optionsMap.get(RobotServerService.OPTIONS_HIGHLIGHTELEMENT_SYNTAX)));199 if (highlightOptionValue.isPresent()) {200 robotServerService.setOptionsHighlightElement(execution.getSession(), highlightOptionValue.get());201 } else {202 //TODO return a message alerting about the failed cast203 LOG.debug("failed to parse option value : {}", optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX));204 }205 }206 if (optionsMap.containsKey(RobotServerService.OPTIONS_MINSIMILARITY_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_MINSIMILARITY_SYNTAX).isEmpty()) {207 String minSimilarity = optionsMap.get(RobotServerService.OPTIONS_MINSIMILARITY_SYNTAX);208 robotServerService.setOptionsMinSimilarity(execution.getSession(), minSimilarity);209 }210 if (optionsMap.containsKey(RobotServerService.OPTIONS_TYPEDELAY_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_TYPEDELAY_SYNTAX).isEmpty()) {211 String typeDelay = optionsMap.get(RobotServerService.OPTIONS_TYPEDELAY_SYNTAX);212 robotServerService.setOptionsTypeDelay(execution.getSession(), typeDelay);213 }214 // Record picture= files at action level.215 Identifier identifier = identifierService.convertStringToIdentifier(value1);216 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isNullOrEmpty(identifier.getLocator())) {217 LOG.warn("Saving Image 1 on Control : {}", identifier.getLocator());218 controlExecution.addFileList(recorderService.recordPicture(controlExecution.getTestCaseStepActionExecution(), controlExecution.getControlId(), identifier.getLocator(), "1"));219 }220 identifier = identifierService.convertStringToIdentifier(value2);221 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isNullOrEmpty(identifier.getLocator())) {222 LOG.warn("Saving Image 2 on Control : {}", identifier.getLocator());223 controlExecution.addFileList(recorderService.recordPicture(controlExecution.getTestCaseStepActionExecution(), controlExecution.getControlId(), identifier.getLocator(), "2"));224 }225 try {226 switch (controlExecution.getControl()) {227 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGEQUAL:228 res = this.verifyStringEqual(value1, controlExecution.getValue2(), controlExecution.getValue3());229 break;230 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGDIFFERENT:231 res = this.verifyStringDifferent(value1, controlExecution.getValue2(), controlExecution.getValue3());232 break;233 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGGREATER:234 res = this.verifyStringGreater(value1, controlExecution.getValue2());235 break;236 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGMINOR:237 res = this.verifyStringMinor(value1, controlExecution.getValue2());238 break;239 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGCONTAINS:240 res = this.verifyStringContains(value1, controlExecution.getValue2(), controlExecution.getValue3());241 break;242 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGNOTCONTAINS:243 res = this.verifyStringNotContains(value1, controlExecution.getValue2(), controlExecution.getValue3());244 break;245 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICEQUALS:246 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICDIFFERENT:247 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATER:248 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATEROREQUAL:249 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOR:250 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOROREQUAL:251 res = this.evaluateControlIfNumericXXX(controlExecution.getControl(), value1, controlExecution.getValue2());252 break;253 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT:254 res = this.verifyElementPresent(execution, value1);255 break;256 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT:257 res = this.verifyElementNotPresent(execution, value1);258 break;259 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTVISIBLE:260 res = this.verifyElementVisible(execution, value1);261 break;262 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTVISIBLE:263 res = this.verifyElementNotVisible(execution, value1);264 break;265 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTEQUALS:266 res = this.verifyElementEquals(execution, value1, controlExecution.getValue2());267 break;268 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTDIFFERENT:269 res = this.verifyElementDifferent(execution, value1, controlExecution.getValue2());270 break;271 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTINELEMENT:272 res = this.verifyElementInElement(execution, value1, controlExecution.getValue2());273 break;274 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTCLICKABLE:275 res = this.verifyElementClickable(execution, value1);276 break;277 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTCLICKABLE:278 res = this.verifyElementNotClickable(execution, value1);279 break;280 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTEQUAL:281 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTEQUAL, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());282 break;283 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTDIFFERENT:284 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTDIFFERENT, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());285 break;286 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTCONTAINS:287 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTCONTAINS, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());288 break;289 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:290 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());291 break;292 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:293 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());294 break;295 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:296 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());297 break;298 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:299 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());300 break;301 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:302 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());303 break;304 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:305 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());306 break;307 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTMATCHREGEX:308 res = this.verifyElementTextMatchRegex(execution, value1, controlExecution.getValue2());309 break;310 case TestCaseStepActionControl.CONTROL_VERIFYTEXTINPAGE:311 res = this.verifyTextInPage(execution, value1);312 break;313 case TestCaseStepActionControl.CONTROL_VERIFYTEXTNOTINPAGE:314 res = this.verifyTextNotInPage(execution, value1);315 break;316 case TestCaseStepActionControl.CONTROL_VERIFYTITLE:317 res = this.verifyTitle(execution, value1, controlExecution.getValue3());318 break;319 case TestCaseStepActionControl.CONTROL_VERIFYURL:320 res = this.verifyUrl(execution, value1);321 break;322 case TestCaseStepActionControl.CONTROL_VERIFYTEXTINDIALOG:323 res = this.verifyTextInDialog(execution, value1, controlExecution.getValue2());324 break;325 case TestCaseStepActionControl.CONTROL_VERIFYXMLTREESTRUCTURE:326 res = this.verifyXmlTreeStructure(execution, value1, controlExecution.getValue2());327 break;328 case TestCaseStepActionControl.CONTROL_TAKESCREENSHOT:329 res = this.takeScreenshot(execution, controlExecution.getTestCaseStepActionExecution(), controlExecution, value1);330 break;331 case TestCaseStepActionControl.CONTROL_GETPAGESOURCE:332 res = this.getPageSource(execution, controlExecution.getTestCaseStepActionExecution(), controlExecution);333 break;334 default:335 res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_UNKNOWNCONTROL);336 res.resolveDescription("CONTROL", controlExecution.getControl());337 }338 } catch (final CerberusEventException exception) {339 res = exception.getMessageError();340 } catch (final Exception unexpected) {341 LOG.debug("Unexpected exception on control!", unexpected);342 res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC).resolveDescription("ERROR", unexpected.getMessage());343 }344 // Reset Timeout to default345 robotServerService.setOptionsToDefault(execution.getSession());346 controlExecution.setControlResultMessage(res);347 /*348 * Updating Control result message only if control is not successful.349 * This is to keep the last KO information and preventing KO to be350 * transformed to OK.351 */352 if (!(res.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS)))) {353 controlExecution.setExecutionResultMessage(new MessageGeneral(res.getMessage()));354 }355 /*356 * We only stop the test if Control Event message is in stop status AND357 * the control is FATAL. If control is not fatal, we continue the test358 * but refresh the Execution status.359 */360 if (res.isStopTest() && controlExecution.getFatal().equals("Y")) {361 controlExecution.setStopExecution(true);362 }363 controlExecution.setEnd(new Date().getTime());364 return controlExecution;365 }366 private MessageEvent verifyStringDifferent(String value1, String value2, String isCaseSensitive) {367 MessageEvent mes;368 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? !value1.equals(value2) : !value1.equalsIgnoreCase(value2)) {369 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_STRINGDIFFERENT);370 } else {371 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_STRINGDIFFERENT);372 }373 mes.resolveDescription("STRING1", value1);374 mes.resolveDescription("STRING2", value2);375 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));376 return mes;377 }378 private MessageEvent verifyStringEqual(String value1, String value2, String isCaseSensitive) {379 MessageEvent mes;380 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? value1.equals(value2) : value1.equalsIgnoreCase(value2)) {381 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_STRINGEQUAL);382 } else {383 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_STRINGEQUAL);384 }385 mes.resolveDescription("STRING1", value1);386 mes.resolveDescription("STRING2", value2);387 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));388 return mes;389 }390 private MessageEvent verifyStringContains(String value1, String value2, String isCaseSensitive) {391 MessageEvent mes;392 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? value1.contains(value2) : value1.toLowerCase().contains(value2.toLowerCase())) {393 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_CONTAINS);394 } else {395 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CONTAINS);396 }397 mes.resolveDescription("STRING1", value1);398 mes.resolveDescription("STRING2", value2);399 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));400 return mes;401 }402 private MessageEvent verifyStringNotContains(String value1, String value2, String isCaseSensitive) {403 MessageEvent mes;404 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? value1.contains(value2) : value1.toLowerCase().contains(value2.toLowerCase())) {405 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCONTAINS);406 } else {407 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTCONTAINS);408 }409 mes.resolveDescription("STRING1", value1);410 mes.resolveDescription("STRING2", value2);411 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));412 return mes;413 }414 private MessageEvent verifyStringGreater(String value1, String value2) {415 MessageEvent mes;416 if (value1.compareToIgnoreCase(value2) > 0) {417 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GREATER);418 } else {419 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GREATER);420 }421 mes.resolveDescription("STRING1", value1);422 mes.resolveDescription("STRING2", value2);423 return mes;424 }425 private MessageEvent verifyStringMinor(String value1, String value2) {426 MessageEvent mes;427 if (value1.compareToIgnoreCase(value2) < 0) {428 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_MINOR);429 } else {430 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_MINOR);431 }432 mes.resolveDescription("STRING1", value1);433 mes.resolveDescription("STRING2", value2);434 return mes;435 }436 private MessageEvent evaluateControlIfNumericXXX(String control, String controlValue1, String controlValue2) {437 if (LOG.isDebugEnabled()) {438 LOG.debug("Checking if Numeric Equals");439 }440 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_PENDING);441 // We first prepare the string for numeric conversion to replace , by .442 String newControlValue1 = StringUtil.prepareToNumeric(controlValue1);443 String newControlValue2 = StringUtil.prepareToNumeric(controlValue2);444 // We try to convert the strings value1 to numeric.445 Double value1;446 try {447 value1 = Double.valueOf(newControlValue1);448 } catch (NumberFormatException nfe) {449 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);450 mes.resolveDescription("COND", control);451 mes.resolveDescription("STRINGVALUE", newControlValue1);452 return mes;453 }454 // We try to convert the strings value2 to numeric.455 Double value2;456 try {457 value2 = Double.valueOf(newControlValue2);458 } catch (NumberFormatException nfe) {459 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);460 mes.resolveDescription("COND", control);461 mes.resolveDescription("STRINGVALUE", newControlValue2);462 return mes;463 }464 // Now that both values are converted to double we check the operator here.465 switch (control) {466 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICEQUALS:467 if (Objects.equals(value1, value2)) {468 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_EQUAL);469 } else {470 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_EQUAL);471 }472 break;473 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICDIFFERENT:474 if (!(Objects.equals(value1, value2))) {475 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_DIFFERENT);476 } else {477 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_DIFFERENT);478 }479 break;480 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATER:481 if (value1 > value2) {482 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GREATER);483 } else {484 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GREATER);485 }486 break;487 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATEROREQUAL:488 if (value1 >= value2) {489 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GREATEROREQUAL);490 } else {491 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GREATEROREQUAL);492 }493 break;494 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOR:495 if (value1 < value2) {496 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_MINOR);497 } else {498 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_MINOR);499 }500 break;501 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOROREQUAL:502 if (value1 <= value2) {503 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_MINOROREQUAL);504 } else {505 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_MINOROREQUAL);506 }507 break;508 default:509 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED);510 }511 mes.resolveDescription("COND", control);512 mes.resolveDescription("STRING1", value1.toString());513 mes.resolveDescription("STRING2", value2.toString());514 return mes;515 }516 private MessageEvent verifyElementPresent(TestCaseExecution tCExecution, String elementPath) {517 LOG.debug("Control: verifyElementPresent on: {}", elementPath);518 MessageEvent mes;519 if (!StringUtil.isNull(elementPath)) {520 Identifier identifier = identifierService.convertStringToIdentifier(elementPath);521 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)522 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)523 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {524 try {525 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {526 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator(), "");527 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {528 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), "", identifier.getLocator());529 } else if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {530 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);531 mes.resolveDescription("STRING1", elementPath);532 return mes;533 } else {534 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);535 mes.resolveDescription("STRING1", elementPath);536 return mes;537 }538 } catch (WebDriverException exception) {539 return parseWebDriverException(exception);540 }541 } else if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {542 if (tCExecution.getLastServiceCalled() != null) {543 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();544 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {545 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:546 if (xmlUnitService.isElementPresent(responseBody, elementPath)) {547 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);548 } else {549 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);550 }551 mes.resolveDescription("STRING1", elementPath);552 return mes;553 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {554 try {555 //Return of getFromJson can be "[]" in case when the path has this pattern "$..ex" and no elements found. Two dots after $ return a list.556 if (!jsonService.getFromJson(responseBody, null, elementPath).equals("[]")) {557 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);558 mes.resolveDescription("STRING1", elementPath);559 return mes;560 } else {561 throw new PathNotFoundException();562 }563 } catch (PathNotFoundException ex) {564 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);565 mes.resolveDescription("STRING1", elementPath);566 return mes;567 } catch (Exception ex) {568 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);569 mes.resolveDescription("ERROR", ex.toString());570 return mes;571 }572 }573 default:574 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);575 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());576 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT);577 return mes;578 }579 } else {580 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);581 return mes;582 }583 } else if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_FAT)) {584 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {585 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator(), "");586 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {587 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), "", identifier.getLocator());588 } else {589 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION_AND_IDENTIFIER);590 mes.resolveDescription("IDENTIFIER", identifier.getIdentifier());591 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT);592 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());593 return mes;594 }595 } else {596 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);597 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT);598 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());599 return mes;600 }601 } else {602 return new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT_NULL);603 }604 }605 private MessageEvent verifyElementNotPresent(TestCaseExecution execution, String elementPath) {606 LOG.debug("Control: verifyElementNotPresent on: {}", elementPath);607 MessageEvent mes;608 if (!StringUtil.isNull(elementPath)) {609 Identifier identifier = identifierService.convertStringToIdentifier(elementPath);610 if (execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)611 || execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)612 || execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {613 try {614 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {615 return sikuliService.doSikuliVerifyElementNotPresent(execution.getSession(), identifier.getLocator(), "");616 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {617 return sikuliService.doSikuliVerifyElementNotPresent(execution.getSession(), "", identifier.getLocator());618 } else if (!this.webdriverService.isElementPresent(execution.getSession(), identifier)) {619 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);620 } else {621 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);622 }623 mes.resolveDescription("STRING1", elementPath);624 return mes;625 } catch (WebDriverException exception) {626 return parseWebDriverException(exception);627 }628 } else if (execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_FAT)) {629 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {630 return sikuliService.doSikuliVerifyElementNotPresent(execution.getSession(), identifier.getLocator(), "");631 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {632 return sikuliService.doSikuliVerifyElementNotPresent(execution.getSession(), "", identifier.getLocator());633 } else {634 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION_AND_IDENTIFIER);635 mes.resolveDescription("IDENTIFIER", identifier.getIdentifier());636 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT);637 mes.resolveDescription("APPLICATIONTYPE", execution.getAppTypeEngine());638 return mes;639 }640 } else if (execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {641 if (execution.getLastServiceCalled() != null) {642 String responseBody = execution.getLastServiceCalled().getResponseHTTPBody();643 switch (execution.getLastServiceCalled().getResponseHTTPBodyContentType()) {644 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:645 if (!(xmlUnitService.isElementPresent(responseBody, elementPath))) {646 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);647 } else {648 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);649 }650 mes.resolveDescription("STRING1", elementPath);651 return mes;652 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {653 try {654 //Return of getFromJson can be "[]" in case when the path has this pattern "$..ex" and no elements found. Two dots after $ return a list.655 if (!jsonService.getFromJson(responseBody, null, elementPath).equals("[]")) {656 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);657 mes.resolveDescription("STRING1", elementPath);658 return mes;659 } else {660 throw new PathNotFoundException();661 }662 } catch (PathNotFoundException ex) {663 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);664 mes.resolveDescription("STRING1", elementPath);665 return mes;666 } catch (Exception ex) {667 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);668 mes.resolveDescription("ERROR", ex.toString());669 return mes;670 }671 }672 default:673 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);674 mes.resolveDescription("TYPE", execution.getLastServiceCalled().getResponseHTTPBodyContentType());675 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT);676 return mes;677 }678 } else {679 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);680 return mes;681 }682 } else {683 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);684 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT);685 mes.resolveDescription("APPLICATIONTYPE", execution.getAppTypeEngine());686 return mes;687 }688 } else {689 return new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT_NULL);690 }691 }692 private MessageEvent verifyElementInElement(TestCaseExecution tCExecution, String element, String childElement) {693 LOG.debug("Control: verifyElementInElement on: '{}' is child of '{}'", element, childElement);694 MessageEvent mes;695 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)696 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)) {697 if (!StringUtil.isNull(element) && !StringUtil.isNull(childElement)) {698 try {699 Identifier identifier = identifierService.convertStringToIdentifier(element);700 Identifier childIdentifier = identifierService.convertStringToIdentifier(childElement);701 if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {702 if (this.webdriverService.isElementInElement(tCExecution.getSession(), identifier, childIdentifier)) {703 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTINELEMENT);704 } else {705 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTINELEMENT);706 }707 mes.resolveDescription("STRING2", element);708 mes.resolveDescription("STRING1", childElement);709 } else {710 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NO_SUCH_ELEMENT);711 mes.resolveDescription("SELEX", new NoSuchElementException("").toString());712 mes.resolveDescription("ELEMENT", element);713 }714 } catch (WebDriverException exception) {715 return parseWebDriverException(exception);716 }717 } else {718 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTINELEMENT);719 mes.resolveDescription("STRING2", element);720 mes.resolveDescription("STRING1", childElement);721 }722 } else {723 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);724 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTINELEMENT);725 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());726 }727 return mes;728 }729 private MessageEvent verifyElementVisible(TestCaseExecution tCExecution, String html) {730 LOG.debug("Control: verifyElementVisible on: {}", html);731 MessageEvent mes;732 if (!StringUtil.isNull(html)) {733 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)734 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)735 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {736 try {737 Identifier identifier = identifierService.convertStringToIdentifier(html);738 if (this.webdriverService.isElementVisible(tCExecution.getSession(), identifier)) {739 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_VISIBLE);740 } else {741 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VISIBLE);742 }743 mes.resolveDescription("STRING1", html);744 } catch (WebDriverException exception) {745 return parseWebDriverException(exception);746 }747 } else {748 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);749 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTVISIBLE);750 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());751 }752 } else {753 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VISIBLE_NULL);754 }755 return mes;756 }757 private MessageEvent verifyElementNotVisible(TestCaseExecution tCExecution, String html) {758 LOG.debug("Control: verifyElementNotVisible on: {}", html);759 MessageEvent mes;760 if (!StringUtil.isNull(html)) {761 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)762 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)763 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {764 try {765 Identifier identifier = identifierService.convertStringToIdentifier(html);766 if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {767 if (this.webdriverService.isElementNotVisible(tCExecution.getSession(), identifier)) {768 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTVISIBLE);769 } else {770 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTVISIBLE);771 }772 mes.resolveDescription("STRING1", html);773 } else {774 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);775 }776 mes.resolveDescription("STRING1", html);777 } catch (WebDriverException exception) {778 return parseWebDriverException(exception);779 }780 } else {781 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);782 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTVISIBLE);783 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());784 }785 } else {786 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTVISIBLE_NULL);787 }788 return mes;789 }790 private MessageEvent verifyElementEquals(TestCaseExecution tCExecution, String xpath, String expectedElement) {791 LOG.debug("Control: verifyElementEquals on: {} expected Element: {}", xpath, expectedElement);792 MessageEvent mes;793 // If case of not compatible application then exit with error794 if (!tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {795 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);796 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTEQUALS);797 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());798 } else if (tCExecution.getLastServiceCalled() != null) {799 // Check if element on the given xpath is equal to the given expected element800 String xmlResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();801 if (AppService.RESPONSEHTTPBODYCONTENTTYPE_XML.equals(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType())) {802 mes = xmlUnitService.isElementEquals(xmlResponse, xpath, expectedElement) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTEQUALS) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTEQUALS);803 mes.resolveDescription("XPATH", xpath);804 mes.resolveDescription("EXPECTED_ELEMENT", expectedElement);805 } else {806 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);807 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());808 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTEQUALS);809 }810 } else {811 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);812 }813 return mes;814 }815 private MessageEvent verifyElementDifferent(TestCaseExecution tCExecution, String xpath, String differentElement) {816 LOG.debug("Control: verifyElementDifferent on: {} expected Element: {}", xpath, differentElement);817 MessageEvent mes = null;818 // If case of not compatible application then exit with error819 if (!tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {820 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);821 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTDIFFERENT);822 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());823 } else if (tCExecution.getLastServiceCalled() != null) {824 //Check if element on the given xpath is different from the given different element825 if (AppService.RESPONSEHTTPBODYCONTENTTYPE_XML.equals(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType())) {826 String xmlResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();827 mes = xmlUnitService.isElementEquals(xmlResponse, xpath, differentElement) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTDIFFERENT);828 mes.resolveDescription("XPATH", xpath);829 mes.resolveDescription("DIFFERENT_ELEMENT", differentElement);830 } else {831 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);832 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());833 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTDIFFERENT);834 }835 } else {836 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);837 }838 return mes;839 }840 @Override841 public MessageEvent verifyElementXXX(String control, TestCaseExecution tCExecution, String path, String expected, String isCaseSensitive) {842 LOG.debug("Control: verifyElementXXX ({}) on {} element against value: {} AppType: {}", control, path, expected, tCExecution.getAppTypeEngine());843 MessageEvent mes;844 // Get value from the path element according to the application type845 String actual;846 try {847 Identifier identifier = identifierService.convertStringToIdentifier(path);848 String applicationType = tCExecution.getAppTypeEngine();849 switch (applicationType) {850 case Application.TYPE_GUI:851 case Application.TYPE_APK:852 case Application.TYPE_IPA:853 actual = webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);854 // In case of null actual value then we alert user855 if (actual == null) {856 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NULL);857 mes.resolveDescription("STRING1", path);858 return mes;859 }860 // Get the result depending on the control required.861 mes = switchControl(control, path, actual, expected, isCaseSensitive);862 return mes;863 case Application.TYPE_SRV:864 if (tCExecution.getLastServiceCalled() != null) {865 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();866 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {867 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:868 if (!xmlUnitService.isElementPresent(responseBody, path)) {869 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);870 mes.resolveDescription("ELEMENT", path);871 return mes;872 }873 String newPath = StringUtil.addSuffixIfNotAlready(path, "/text()");874 actual = xmlUnitService.getFromXml(responseBody, newPath);875 // In case of null actual value then we alert user876 if (actual == null) {877 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NULL);878 mes.resolveDescription("ELEMENT", path);879 return mes;880 }881 // Get the result depending on the control required.882 mes = switchControl(control, path, actual, expected, isCaseSensitive);883 return mes;884 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {885 try {886 actual = jsonService.getFromJson(responseBody, null, path);887 } catch (Exception ex) {888 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);889 mes.resolveDescription("ERROR", ex.toString());890 return mes;891 }892 }893 // In case of null actual value then we alert user894 if (actual == null) {895 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);896 mes.resolveDescription("ELEMENT", path);897 return mes;898 }899 // Get the result depending on the control required.900 mes = switchControl(control, path, actual, expected, isCaseSensitive);901 return mes;902 default:903 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);904 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());905 mes.resolveDescription("CONTROL", control);906 return mes;907 }908 } else {909 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);910 return mes;911 }912 default:913 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);914 mes.resolveDescription("CONTROL", control);915 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());916 return mes;917 }918 } catch (NoSuchElementException exception) {919 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);920 mes.resolveDescription("ELEMENT", path);921 return mes;922 } catch (WebDriverException exception) {923 return parseWebDriverException(exception);924 }925 }926 private MessageEvent switchControl(String control, String path, String actual, String expected, String isCaseSensitive) {927 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);928 mes.resolveDescription("CONTROL", "switchControl-" + control);929 switch (control) {930 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTEQUAL:931 mes = verifyElementTextEqualCaseSensitiveCheck(actual, expected, isCaseSensitive);932 break;933 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTDIFFERENT:934 mes = verifyElementTextDifferentCaseSensitiveCheck(actual, expected, isCaseSensitive);935 break;936 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTCONTAINS:937 mes = verifyElementTextContainsCaseSensitiveCheck(actual, expected, isCaseSensitive);938 break;939 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:940 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:941 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:942 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:943 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:944 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:945 double value1;946 try {947 value1 = Double.parseDouble(actual);948 } catch (NumberFormatException nfe) {949 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);950 mes.resolveDescription("COND", control);951 mes.resolveDescription("STRINGVALUE", actual);952 return mes;953 }954 // We try to convert the strings value2 to numeric.955 double value2;956 try {957 value2 = Double.parseDouble(expected);958 } catch (NumberFormatException nfe) {959 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);960 mes.resolveDescription("COND", control);961 mes.resolveDescription("STRINGVALUE", expected);962 return mes;963 }964 mes = checkNumericVerifyElement(control, value1, value2);965 break;966 }967 mes.resolveDescription("ELEMENT", path);968 mes.resolveDescription("ELEMENTVALUE", actual);969 mes.resolveDescription("VALUE", expected);970 mes.resolveDescription("CASESENSITIVE", caseSensitiveMessageValue(isCaseSensitive));971 return mes;972 }973 private MessageEvent verifyElementTextEqualCaseSensitiveCheck(String actual, String expected, String isCaseSensitive) {974 MessageEvent mes;975 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {976 mes = actual.equals(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTEQUAL) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTEQUAL);977 } else {978 mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTEQUAL) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTEQUAL);979 }980 return mes;981 }982 private MessageEvent verifyElementTextDifferentCaseSensitiveCheck(String actual, String expected, String isCaseSensitive) {983 MessageEvent mes;984 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {985 mes = actual.equals(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTDIFFERENT);986 } else {987 mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTDIFFERENT);988 }989 return mes;990 }991 private MessageEvent verifyElementTextContainsCaseSensitiveCheck(String text, String textToSearch, String isCaseSensitive) {992 MessageEvent mes;993 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {994 mes = text.contains(textToSearch) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTCONTAINS) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTCONTAINS);995 } else {996 mes = text.toLowerCase().contains(textToSearch.toLowerCase()) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTCONTAINS) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTCONTAINS);997 }998 return mes;999 }1000 private MessageEvent checkNumericVerifyElement(String control, Double actual, Double expected) {1001 switch (control) {1002 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:1003 return actual.equals(expected)1004 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICEQUAL)1005 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICEQUAL);1006 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:1007 return !actual.equals(expected)1008 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICDIFFERENT)1009 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICDIFFERENT);1010 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:1011 return actual > expected1012 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICGREATER)1013 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICGREATER);1014 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:1015 return actual >= expected1016 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICGREATEROREQUAL)1017 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICGREATEROREQUAL);1018 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:1019 return actual < expected1020 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICMINOR)1021 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICMINOR);1022 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:1023 return actual <= expected1024 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICMINOROREQUAL)1025 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICMINOROREQUAL);1026 default:1027 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1028 return mes.resolveDescription("CONTROL", "checkNumericVerifyElement-" + control);1029 }1030 }1031 private MessageEvent verifyElementTextMatchRegex(TestCaseExecution tCExecution, String path, String regex) {1032 LOG.debug("Control: VerifyElementTextMatchRegex on: {} element against value: {}", path, regex);1033 MessageEvent mes;1034 String pathContent;1035 try {1036 Identifier identifier = identifierService.convertStringToIdentifier(path);1037 String applicationType = tCExecution.getAppTypeEngine();1038 // Get value from the path element according to the application type1039 if (Application.TYPE_GUI.equalsIgnoreCase(applicationType)1040 || Application.TYPE_APK.equalsIgnoreCase(applicationType)1041 || Application.TYPE_IPA.equalsIgnoreCase(applicationType)) {1042 pathContent = this.webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);1043 } else if (Application.TYPE_SRV.equalsIgnoreCase(applicationType)) {1044 if (tCExecution.getLastServiceCalled() != null) {1045 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();1046 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {1047 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:1048 if (!xmlUnitService.isElementPresent(responseBody, path)) {1049 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);1050 mes.resolveDescription("ELEMENT", path);1051 return mes;1052 }1053 String newPath = StringUtil.addSuffixIfNotAlready(path, "/text()");1054 pathContent = xmlUnitService.getFromXml(responseBody, newPath);1055 break;1056 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:1057 try {1058 pathContent = jsonService.getFromJson(responseBody, null, path);1059 } catch (Exception ex) {1060 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);1061 mes.resolveDescription("ERROR", ex.toString());1062 return mes;1063 }1064 break;1065 default:1066 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);1067 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());1068 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTMATCHREGEX);1069 return mes;1070 }1071 // TODO Give the actual element found into the description.1072 } else {1073 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);1074 return mes;1075 }1076 } else {1077 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1078 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTMATCHREGEX);1079 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1080 return mes;1081 }1082 LOG.debug("Control: VerifyElementMatchRegex element: {} has value: {}", path, StringUtil.sanitize(pathContent));1083 if (path != null && pathContent != null) {1084 try {1085 Pattern pattern = Pattern.compile(regex);1086 Matcher matcher = pattern.matcher(pathContent);1087 if (matcher.find()) {1088 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_REGEXINELEMENT);1089 } else {1090 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT);1091 }1092 mes.resolveDescription("STRING1", path);1093 mes.resolveDescription("STRING2", StringUtil.sanitize(pathContent));1094 mes.resolveDescription("STRING3", regex);1095 } catch (PatternSyntaxException e) {1096 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_INVALIDPATTERN);1097 mes.resolveDescription("PATTERN", regex);1098 mes.resolveDescription("ERROR", e.getMessage());1099 }1100 } else if (pathContent != null) {1101 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NULL);1102 } else {1103 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NO_SUCH_ELEMENT);1104 mes.resolveDescription("ELEMENT", path);1105 }1106 } catch (NoSuchElementException exception) {1107 LOG.debug(exception.toString());1108 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NO_SUCH_ELEMENT);1109 mes.resolveDescription("ELEMENT", path);1110 } catch (WebDriverException exception) {1111 return parseWebDriverException(exception);1112 }1113 return mes;1114 }1115 private MessageEvent verifyTextInDialog(TestCaseExecution tCExecution, String property, String value) {1116 LOG.debug("Control: verifyTextInDialog against value: {}", value);1117 MessageEvent mes;1118 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1119 try {1120 String str = this.webdriverService.getAlertText(tCExecution.getSession());1121 LOG.debug("Control: verifyTextInAlertPopup has value: {}", str);1122 if (str != null) {1123 String valueToTest = property;1124 if (valueToTest == null || "".equals(valueToTest.trim())) {1125 valueToTest = value;1126 }1127 if (str.trim().equalsIgnoreCase(valueToTest)) {1128 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTINALERT);1129 } else {1130 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINALERT);1131 }1132 mes.resolveDescription("STRING1", str);1133 mes.resolveDescription("STRING2", valueToTest);1134 } else {1135 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINALERT_NULL);1136 }1137 } catch (WebDriverException exception) {1138 return parseWebDriverException(exception);1139 }1140 } else {1141 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1142 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYTEXTINDIALOG);1143 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1144 }1145 return mes;1146 }1147 private MessageEvent verifyTextInPage(TestCaseExecution tCExecution, String regex) {1148 LOG.debug("Control: verifyTextInPage on : {}", regex);1149 MessageEvent mes;1150 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())1151 || Application.TYPE_APK.equalsIgnoreCase(tCExecution.getAppTypeEngine())1152 || Application.TYPE_IPA.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1153 String pageSource;1154 try {1155 pageSource = this.webdriverService.getPageSource(tCExecution.getSession());1156 LOG.debug(pageSource);1157 Pattern pattern = Pattern.compile(regex);1158 Matcher matcher = pattern.matcher(pageSource);1159 if (matcher.find()) {1160 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTINPAGE);1161 } else {1162 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINPAGE);1163 }1164 mes.resolveDescription("STRING1", Pattern.quote(regex));1165 } catch (PatternSyntaxException e) {1166 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINPAGE_INVALIDPATTERN);1167 mes.resolveDescription("PATTERN", Pattern.quote(regex));1168 mes.resolveDescription("ERROR", e.getMessage());1169 } catch (WebDriverException exception) {1170 return parseWebDriverException(exception);1171 }1172 } else if (Application.TYPE_FAT.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1173 mes = sikuliService.doSikuliVerifyTextInPage(tCExecution.getSession(), regex);1174 } else {1175 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1176 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYTEXTINPAGE);1177 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1178 }1179 return mes;1180 }1181 private MessageEvent verifyTextNotInPage(TestCaseExecution tCExecution, String regex) {1182 LOG.debug("Control: VerifyTextNotInPage on: {}", regex);1183 MessageEvent mes;1184 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())1185 || Application.TYPE_APK.equalsIgnoreCase(tCExecution.getAppTypeEngine())1186 || Application.TYPE_IPA.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1187 String pageSource;1188 try {1189 pageSource = this.webdriverService.getPageSource(tCExecution.getSession());1190 LOG.debug(pageSource);1191 Pattern pattern = Pattern.compile(regex);1192 Matcher matcher = pattern.matcher(pageSource);1193 if (!(matcher.find())) {1194 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTNOTINPAGE);1195 } else {1196 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINPAGE);1197 }1198 mes.resolveDescription("STRING1", Pattern.quote(regex));1199 } catch (PatternSyntaxException e) {1200 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINPAGE_INVALIDPATTERN);1201 mes.resolveDescription("PATTERN", Pattern.quote(regex));1202 mes.resolveDescription("ERROR", e.getMessage());1203 } catch (WebDriverException exception) {1204 return parseWebDriverException(exception);1205 }1206 } else {1207 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1208 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYTEXTNOTINPAGE);1209 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1210 }1211 return mes;1212 }1213 private MessageEvent verifyUrl(TestCaseExecution tCExecution, String value1) throws CerberusEventException {1214 LOG.debug("Control: verifyUrl on: {}", value1);1215 MessageEvent mes;1216 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1217 String url;1218 // Control is made forcing the / at the beginning of URL. getCurrentUrl from Selenium1219 // already have that control but value1 is specified by user and could miss it.1220 final String controlUrl = StringUtil.addPrefixIfNotAlready(value1, "/");1221 try {1222 LOG.debug("Before wait: {}", System.currentTimeMillis());1223 WebDriverWait wait = new WebDriverWait(tCExecution.getSession().getDriver(),1224 TimeUnit.MILLISECONDS.toSeconds(tCExecution.getSession().getCerberus_selenium_wait_element()));1225 //Wait until the url is the expected one1226 wait.until(new Function<WebDriver, Boolean>() {1227 final String expectedValue = controlUrl;1228 @Override1229 public Boolean apply(WebDriver driver) {1230 String value = "";1231 try {1232 value = webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());1233 LOG.debug("Get new url: {} >> Expected url: {}", value, expectedValue);1234 } catch (CerberusEventException ex) {1235 LOG.warn(ex.getMessageError().getDescription());1236 }1237 return value.equalsIgnoreCase(expectedValue);1238 }1239 });1240 LOG.debug("After wait: {}", System.currentTimeMillis());1241 url = this.webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());1242 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_URL);1243 mes.resolveDescription("STRING1", url);1244 } catch (TimeoutException exception) {1245 url = this.webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());1246 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_URL);1247 mes.resolveDescription("STRING1", url);1248 } catch (WebDriverException exception) {1249 return parseWebDriverException(exception);1250 }1251 mes.resolveDescription("STRING2", controlUrl);1252 } else {1253 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1254 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYURL);1255 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1256 }1257 return mes;1258 }1259 private MessageEvent verifyTitle(TestCaseExecution tCExecution, String title, String isCaseSensitive) {1260 LOG.debug("Control: verifyTitle on: {}", title);1261 MessageEvent mes;1262 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1263 String pageTitle = this.webdriverService.getTitle(tCExecution.getSession());1264 try {1265 LOG.debug("Before wait {}", System.currentTimeMillis());1266 WebDriverWait wait = new WebDriverWait(tCExecution.getSession().getDriver(),1267 TimeUnit.MILLISECONDS.toSeconds(tCExecution.getSession().getCerberus_selenium_wait_element()));1268 //Wait until the title is the expected one1269 wait.until(new Function<WebDriver, Boolean>() {1270 final String expectedValue = title;1271 @Override1272 public Boolean apply(WebDriver driver) {1273 String value = webdriverService.getTitle(tCExecution.getSession());1274 LOG.debug("Get new title: {} >> Expected title: {}", value, expectedValue);1275 return ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? expectedValue.equals(value) : expectedValue.equalsIgnoreCase(value);1276 }1277 });1278 LOG.debug("After wait {}", System.currentTimeMillis());1279 pageTitle = this.webdriverService.getTitle(tCExecution.getSession());1280 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TITLE);1281 } catch (TimeoutException exception) {1282 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TITLE);1283 } catch (WebDriverException exception) {1284 return parseWebDriverException(exception);1285 }1286 mes.resolveDescription("STRING1", pageTitle);1287 mes.resolveDescription("STRING2", title);1288 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));1289 } else {1290 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1291 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYTITLE);1292 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1293 }1294 return mes;1295 }1296 private MessageEvent verifyXmlTreeStructure(TestCaseExecution tCExecution, String controlProperty, String controlValue) {1297 LOG.debug("Control: verifyXmlTreeStructure on: {}", controlProperty);1298 MessageEvent mes;1299 if (Application.TYPE_SRV.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1300 try {1301 if (tCExecution.getLastServiceCalled() != null) {1302 if (AppService.RESPONSEHTTPBODYCONTENTTYPE_XML.equals(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType())) {1303 String xmlResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();1304 if (this.xmlUnitService.isSimilarTree(xmlResponse, controlProperty, controlValue)) {1305 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_SIMILARTREE);1306 } else {1307 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_SIMILARTREE);1308 }1309 mes.resolveDescription("STRING1", StringUtil.sanitize(controlProperty));1310 mes.resolveDescription("STRING2", StringUtil.sanitize(controlValue));1311 } else {1312 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);1313 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());1314 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYXMLTREESTRUCTURE);1315 }1316 } else {1317 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);1318 }1319 } catch (Exception exception) {1320 LOG.fatal(exception.toString());1321 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED);1322 }1323 } else {1324 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1325 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYXMLTREESTRUCTURE);1326 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1327 }1328 return mes;1329 }1330 private MessageEvent verifyElementClickable(TestCaseExecution tCExecution, String html) {1331 LOG.debug("Control: verifyElementClickable: {}", html);1332 MessageEvent mes;1333 if (!StringUtil.isNull(html)) {1334 Identifier identifier = identifierService.convertStringToIdentifier(html);1335 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1336 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)) {1337 try {1338 if (this.webdriverService.isElementClickable(tCExecution.getSession(), identifier)) {1339 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_CLICKABLE);1340 } else {1341 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CLICKABLE);1342 }1343 mes.resolveDescription("ELEMENT", html);1344 } catch (WebDriverException exception) {1345 return parseWebDriverException(exception);1346 }1347 } else {1348 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1349 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTCLICKABLE);1350 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1351 }1352 } else {1353 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CLICKABLE_NULL);1354 }1355 return mes;1356 }1357 private MessageEvent verifyElementNotClickable(TestCaseExecution tCExecution, String html) {1358 LOG.debug("Control: verifyElementNotClickable on: {}", html);1359 MessageEvent mes;1360 if (!StringUtil.isNull(html)) {1361 Identifier identifier = identifierService.convertStringToIdentifier(html);1362 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1363 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)) {1364 try {1365 if (this.webdriverService.isElementNotClickable(tCExecution.getSession(), identifier)) {1366 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTCLICKABLE);1367 } else {1368 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCLICKABLE);1369 }1370 mes.resolveDescription("ELEMENT", html);1371 } catch (WebDriverException exception) {1372 return parseWebDriverException(exception);1373 }1374 } else {1375 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1376 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTCLICKABLE);1377 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1378 }1379 } else {...

Full Screen

Full Screen

Source:ConditionService.java Github

copy

Full Screen

...73 // Define Options74 HashMap<String, String> optionsMap = robotServerService.getMapFromOptions(options);75 if (optionsMap.containsKey(RobotServerService.OPTIONS_TIMEOUT_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX).isEmpty()) {76 Integer newTimeout = Integer.valueOf(optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX));77 robotServerService.setOptionsTimeout(execution.getSession(), newTimeout);78 }79 if (optionsMap.containsKey(RobotServerService.OPTIONS_HIGHLIGHTELEMENT_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_HIGHLIGHTELEMENT_SYNTAX).isEmpty()) {80 Integer newHighlightElement = Integer.valueOf(optionsMap.get(RobotServerService.OPTIONS_HIGHLIGHTELEMENT_SYNTAX));81 robotServerService.setOptionsHighlightElement(execution.getSession(), newHighlightElement);82 }83 if (optionsMap.containsKey(RobotServerService.OPTIONS_MINSIMILARITY_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_MINSIMILARITY_SYNTAX).isEmpty()) {84 String minSimilarity = optionsMap.get(RobotServerService.OPTIONS_MINSIMILARITY_SYNTAX);85 robotServerService.setOptionsMinSimilarity(execution.getSession(), minSimilarity);86 }87 if (optionsMap.containsKey(RobotServerService.OPTIONS_TYPEDELAY_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_TYPEDELAY_SYNTAX).isEmpty()) {88 String typeDelay = optionsMap.get(RobotServerService.OPTIONS_TYPEDELAY_SYNTAX);89 robotServerService.setOptionsTypeDelay(execution.getSession(), typeDelay);90 }91 /*92 * CONDITION Management is treated here. Checking if the93 * action/control/step/execution can be execued here depending on the94 * condition operator and value.95 */96 switch (Objects.requireNonNull(conditionToEvaluate)) {97 case CONDITIONOPERATOR_ALWAYS:98 case CONDITIONOPERATOR_UNDEFINED: // In case condition is not defined, it is considered as always.99 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_ALWAYS);100 break;101 case CONDITIONOPERATOR_IFELEMENTPRESENT:102 ans = evaluateCondition_ifElementPresent(conditionToEvaluate.getCondition(), conditionValue1, execution);103 mes = ans.getResultMessage();104 break;105 case CONDITIONOPERATOR_IFELEMENTNOTPRESENT:106 ans = evaluateCondition_ifElementNotPresent(conditionToEvaluate.getCondition(), conditionValue1, execution);107 mes = ans.getResultMessage();108 break;109 case CONDITIONOPERATOR_IFELEMENTVISIBLE:110 ans = evaluateCondition_ifElementVisible(conditionToEvaluate.getCondition(), conditionValue1, execution);111 mes = ans.getResultMessage();112 break;113 case CONDITIONOPERATOR_IFELEMENTNOTVISIBLE:114 ans = evaluateCondition_ifElementNotVisible(conditionToEvaluate.getCondition(), conditionValue1, execution);115 mes = ans.getResultMessage();116 break;117 case CONDITIONOPERATOR_IFPROPERTYEXIST:118 ans = evaluateCondition_ifPropertyExist(conditionToEvaluate.getCondition(), conditionValue1, execution);119 mes = ans.getResultMessage();120 break;121 case CONDITIONOPERATOR_IFPROPERTYNOTEXIST:122 ans = evaluateCondition_ifPropertyNotExist(conditionToEvaluate.getCondition(), conditionValue1, execution);123 mes = ans.getResultMessage();124 break;125 case CONDITIONOPERATOR_IFNUMERICEQUAL:126 case CONDITIONOPERATOR_IFNUMERICDIFFERENT:127 case CONDITIONOPERATOR_IFNUMERICGREATER:128 case CONDITIONOPERATOR_IFNUMERICGREATEROREQUAL:129 case CONDITIONOPERATOR_IFNUMERICMINOR:130 case CONDITIONOPERATOR_IFNUMERICMINOROREQUAL:131 ans = evaluateCondition_ifNumericXXX(conditionToEvaluate.getCondition(), conditionValue1, conditionValue2);132 mes = ans.getResultMessage();133 break;134 case CONDITIONOPERATOR_IFSTRINGEQUAL:135 ans = evaluateCondition_ifStringEqual(conditionToEvaluate.getCondition(), conditionValue1, conditionValue2, conditionValue3);136 mes = ans.getResultMessage();137 break;138 case CONDITIONOPERATOR_IFSTRINGDIFFERENT:139 ans = evaluateCondition_ifStringDifferent(conditionToEvaluate.getCondition(), conditionValue1, conditionValue2, conditionValue3);140 mes = ans.getResultMessage();141 break;142 case CONDITIONOPERATOR_IFSTRINGGREATER:143 ans = evaluateCondition_ifStringGreater(conditionToEvaluate.getCondition(), conditionValue1, conditionValue2);144 mes = ans.getResultMessage();145 break;146 case CONDITIONOPERATOR_IFSTRINGMINOR:147 ans = evaluateCondition_ifStringMinor(conditionToEvaluate.getCondition(), conditionValue1, conditionValue2);148 mes = ans.getResultMessage();149 break;150 case CONDITIONOPERATOR_IFSTRINGCONTAINS:151 ans = evaluateCondition_ifStringContains(conditionToEvaluate.getCondition(), conditionValue1, conditionValue2, conditionValue3);152 mes = ans.getResultMessage();153 break;154 case CONDITIONOPERATOR_IFSTRINGNOTCONTAINS:155 ans = evaluateCondition_ifStringNotContains(conditionToEvaluate.getCondition(), conditionValue1, conditionValue2, conditionValue3);156 mes = ans.getResultMessage();157 break;158 case CONDITIONOPERATOR_NEVER:159 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_NEVER);160 mes.setDescription(mes.getDescription().replace("%COND%", conditionToEvaluate.getCondition()));161 break;162 case CONDITIONOPERATOR_IFTEXTINELEMENT:163 ans = evaluateCondition_ifTextInElement(execution, conditionValue1, conditionValue2, conditionValue3);164 mes = ans.getResultMessage();165 break;166 case CONDITIONOPERATOR_IFTEXTNOTINELEMENT:167 ans = evaluateCondition_ifTextNotInElement(execution, conditionValue1, conditionValue2, conditionValue3);168 mes = ans.getResultMessage();169 break;170 default:171 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_UNKNOWNCONDITION);172 mes.setDescription(mes.getDescription().replace("%COND%", conditionToEvaluate.getCondition()));173 }174 LOG.debug("Finished Evaluation condition : {}", mes.getCodeString());175 // Reset Timeout to default176 robotServerService.setOptionsToDefault(execution.getSession());177 // the decision whether we execute the action/control/step is taken from the codeString of the message.178 isOperationToBeExecuted = mes.getCodeString().equals("OK");179 ans.setItem(isOperationToBeExecuted);180 ans.setResultMessage(mes);181 return ans;182 }183 private AnswerItem<Boolean> evaluateCondition_ifTextInElement(TestCaseExecution tCExecution, String path, String expected, String isCaseSensitive) {184 LOG.debug("Checking ifTextInElement on {} element against value: {}", path, expected);185 AnswerItem<Boolean> ans = new AnswerItem<>();186 MessageEvent resultControlMes;187 isCaseSensitive = defaultIsSensitiveValue(isCaseSensitive);188 if (tCExecution.getManualExecution().equals("Y")) {189 resultControlMes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUEMANUAL_TEXTINELEMENT);190 resultControlMes.resolveDescription("STRING1", path);191 resultControlMes.resolveDescription("STRING2", expected);192 resultControlMes.resolveDescription("STRING3", isCaseSensitive);193 } else {194 resultControlMes = new MessageEvent(MessageEventEnum.ACTION_SUCCESS);195 // TODO AJOUTER DANS CONDITION OPERATOR ENUM = TRUE + nouveau message196 resultControlMes = controlService.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTEQUAL, tCExecution, path, expected, isCaseSensitive);197 MessageEvent resultCondMes;198 if ("OK".equals(resultControlMes.getCodeString())) {199 resultCondMes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_TEXTINELEMENT);200 ans.setItem(true);201 } else {202 resultCondMes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_TEXTINELEMENT);203 resultCondMes.setDescription(resultCondMes.getDescription().replace("%ERRORMESS%", resultControlMes.getDescription()));204 ans.setItem(false);205 }206 ans.setResultMessage(resultCondMes);207 return ans;208 }209 ans.setResultMessage(resultControlMes);210 return ans;211 }212 private AnswerItem<Boolean> evaluateCondition_ifTextNotInElement(TestCaseExecution tCExecution, String path, String expected, String isCaseSensitive) {213 LOG.debug("Checking ifTextInElement on {} element against value: {}", path, expected);214 AnswerItem<Boolean> ans = new AnswerItem<>();215 MessageEvent resultMes;216 isCaseSensitive = defaultIsSensitiveValue(isCaseSensitive);217 if (tCExecution.getManualExecution().equals("Y")) {218 resultMes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUEMANUAL_TEXTNOTINELEMENT);219 resultMes.resolveDescription("STRING1", path);220 resultMes.resolveDescription("STRING2", expected);221 resultMes.resolveDescription("STRING3", isCaseSensitive);222 } else {223 resultMes = controlService.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTDIFFERENT, tCExecution, path, expected, isCaseSensitive);224 MessageEvent resultCondMes;225 if ("OK".equals(resultMes.getCodeString())) {226 resultCondMes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_TEXTNOTINELEMENT);227 ans.setItem(true);228 } else {229 resultCondMes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_TEXTNOTINELEMENT);230 resultCondMes.setDescription(resultCondMes.getDescription().replace("%ERRORMESS%", resultMes.getDescription()));231 ans.setItem(false);232 }233 ans.setResultMessage(resultCondMes);234 return ans;235 }236 ans.setResultMessage(resultMes);237 return ans;238 }239 private AnswerItem<Boolean> evaluateCondition_ifPropertyExist(String conditionOperator, String conditionValue1, TestCaseExecution tCExecution) {240 LOG.debug("Checking if property Exist");241 AnswerItem<Boolean> ans = new AnswerItem<>();242 MessageEvent mes;243 if (StringUtil.isNullOrEmpty(conditionValue1)) {244 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFPROPERTYEXIST_MISSINGPARAMETER);245 mes.setDescription(mes.getDescription().replace("%COND%", conditionOperator));246 } else {247 String myCountry = tCExecution.getCountry();248 boolean doExecuteAction = false;249 for (TestCaseCountryProperties prop : tCExecution.getTestCaseCountryPropertyList()) {250 LOG.debug("{} - {} - {} - {}", prop.getCountry(), myCountry, prop.getProperty(), conditionValue1);251 if ((prop.getCountry().equals(myCountry)) && (prop.getProperty().equals(conditionValue1))) {252 doExecuteAction = true;253 }254 }255 if (!doExecuteAction) {256 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFPROPERTYEXIST);257 } else {258 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFPROPERTYEXIST);259 }260 mes.setDescription(mes.getDescription().replace("%COND%", conditionOperator));261 mes.setDescription(mes.getDescription().replace("%PROP%", conditionValue1));262 mes.setDescription(mes.getDescription().replace("%COUNTRY%", tCExecution.getCountry()));263 }264 ans.setResultMessage(mes);265 return ans;266 }267 private AnswerItem<Boolean> evaluateCondition_ifPropertyNotExist(String conditionOperator, String conditionValue1, TestCaseExecution tCExecution) {268 LOG.debug("Checking if property Does not Exist");269 AnswerItem<Boolean> ans = new AnswerItem<>();270 MessageEvent mes;271 if (StringUtil.isNullOrEmpty(conditionValue1)) {272 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFPROPERTYNOTEXIST_MISSINGPARAMETER);273 mes.setDescription(mes.getDescription().replace("%COND%", conditionOperator));274 } else {275 String myCountry = tCExecution.getCountry();276 boolean doExecuteAction = true;277 for (TestCaseCountryProperties prop : tCExecution.getTestCaseCountryPropertyList()) {278 LOG.debug("{} - {} - {} - {}", prop.getCountry(), myCountry, prop.getProperty(), conditionValue1);279 if ((prop.getCountry().equals(myCountry)) && (prop.getProperty().equals(conditionValue1))) {280 doExecuteAction = false;281 }282 }283 if (!doExecuteAction) {284 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFPROPERTYNOTEXIST);285 } else {286 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFPROPERTYNOTEXIST);287 }288 mes.setDescription(mes.getDescription().replace("%COND%", conditionOperator));289 mes.setDescription(mes.getDescription().replace("%PROP%", conditionValue1));290 mes.setDescription(mes.getDescription().replace("%COUNTRY%", tCExecution.getCountry()));291 }292 ans.setResultMessage(mes);293 return ans;294 }295 private AnswerItem<Boolean> evaluateCondition_ifElementPresent(String conditionOperator, String conditionValue1, TestCaseExecution tCExecution) {296 LOG.debug("Checking if Element Present");297 AnswerItem<Boolean> ans = new AnswerItem<>();298 MessageEvent mes;299 if (tCExecution.getManualExecution().equals("Y")) {300 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUEMANUAL_IFELEMENTPRESENT);301 mes.resolveDescription("ELEMENT", conditionValue1);302 } else if (StringUtil.isNullOrEmpty(conditionValue1)) {303 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFELEMENTPRESENT_MISSINGPARAMETER);304 mes.setDescription(mes.getDescription().replace("%COND%", conditionOperator));305 } else {306 boolean conditionResult = false;307 Identifier identifier = identifierService.convertStringToIdentifier(conditionValue1);308 switch (tCExecution.getApplicationObj().getType()) {309 case Application.TYPE_GUI:310 case Application.TYPE_APK:311 case Application.TYPE_IPA:312 try {313 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {314 mes = sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator(), null);315 if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT))) {316 conditionResult = true;317 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);318 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));319 } else if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT))) {320 conditionResult = false;321 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTPRESENT);322 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));323 }324 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {325 mes = sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), null, identifier.getLocator());326 if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT))) {327 conditionResult = true;328 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);329 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));330 } else if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT))) {331 conditionResult = false;332 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTPRESENT);333 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));334 }335 } else if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {336 conditionResult = true;337 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);338 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));339 } else {340 conditionResult = false;341 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTPRESENT);342 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));343 }344 } catch (WebDriverException exception) {345 conditionResult = false;346 mes = parseWebDriverException(exception);347 }348 break;349 case Application.TYPE_FAT:350 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {351 mes = sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator(), null);352 LOG.debug("Sikuli : {}", mes.getCode());353 if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT))) {354 conditionResult = true;355 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);356 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));357 } else if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT))) {358 conditionResult = false;359 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTPRESENT);360 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));361 }362 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {363 mes = sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), null, identifier.getLocator());364 LOG.debug("Sikuli : {}", mes.getCode());365 if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT))) {366 conditionResult = true;367 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);368 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));369 } else if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT))) {370 conditionResult = false;371 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTPRESENT);372 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));373 }374 } else {375 conditionResult = false;376 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_GENERIC);377 mes.resolveDescription("ERROR", "Element must start by picture=");378 }379 break;380 case Application.TYPE_SRV:381 if (tCExecution.getLastServiceCalled() != null) {382 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();383 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {384 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:385 if (LOG.isDebugEnabled()) {386 LOG.debug("Checking if Element Present - XML");387 }388 if (xmlUnitService.isElementPresent(responseBody, conditionValue1)) {389 conditionResult = true;390 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);391 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));392 } else {393 conditionResult = false;394 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTPRESENT);395 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));396 }397 break;398 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:399 if (LOG.isDebugEnabled()) {400 LOG.debug("Checking if Element Present - JSON");401 }402 try {403 if (jsonService.getFromJson(responseBody, null, conditionValue1) != null) {404 conditionResult = true;405 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);406 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));407 } else {408 conditionResult = false;409 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTPRESENT);410 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));411 }412 } catch (Exception ex) {413 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_GENERIC);414 mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));415 }416 break;417 default:418 conditionResult = false;419 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOTSUPPORTED_FOR_MESSAGETYPE);420 mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));421 mes.setDescription(mes.getDescription().replace("%CONDITION%", conditionOperator));422 }423 } else {424 conditionResult = false;425 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOOBJECTINMEMORY);426 }427 break;428 default:429 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOTSUPPORTED_FOR_APPLICATION);430 mes.setDescription(mes.getDescription().replace("%CONDITION%", conditionOperator));431 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));432 }433 }434 ans.setResultMessage(mes);435 return ans;436 }437 private AnswerItem<Boolean> evaluateCondition_ifElementNotPresent(String conditionOperator, String conditionValue1, TestCaseExecution tCExecution) {438 LOG.debug("Checking if Element is Not Present");439 AnswerItem<Boolean> ans = new AnswerItem<>();440 MessageEvent mes;441 if (tCExecution.getManualExecution().equals("Y")) {442 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUEMANUAL_IFELEMENTNOTPRESENT);443 mes.resolveDescription("ELEMENT", conditionValue1);444 } else if (StringUtil.isNullOrEmpty(conditionValue1)) {445 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFELEMENTNOTPRESENT_MISSINGPARAMETER);446 mes.setDescription(mes.getDescription().replace("%COND%", conditionOperator));447 } else {448 boolean conditionResult = false;449 Identifier identifier = identifierService.convertStringToIdentifier(conditionValue1);450 switch (tCExecution.getApplicationObj().getType()) {451 case Application.TYPE_GUI:452 case Application.TYPE_APK:453 case Application.TYPE_IPA:454 try {455 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {456 mes = sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator(), null);457 if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT))) {458 conditionResult = true;459 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTNOTPRESENT);460 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));461 } else if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT))) {462 conditionResult = false;463 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTPRESENT);464 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));465 }466 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {467 mes = sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), null, identifier.getLocator());468 if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT))) {469 conditionResult = true;470 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTNOTPRESENT);471 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));472 } else if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT))) {473 conditionResult = false;474 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTPRESENT);475 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));476 }477 } else if (!this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {478 conditionResult = true;479 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTNOTPRESENT);480 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));481 } else {482 conditionResult = false;483 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTPRESENT);484 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));485 }486 } catch (WebDriverException exception) {487 conditionResult = false;488 mes = parseWebDriverException(exception);489 }490 break;491 case Application.TYPE_FAT:492 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {493 mes = sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator(), null);494 LOG.debug("Sikuli : {}", mes.getCode());495 if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT))) {496 conditionResult = true;497 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTNOTPRESENT);498 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));499 } else if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT))) {500 conditionResult = false;501 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTPRESENT);502 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));503 }504 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {505 mes = sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), null, identifier.getLocator());506 LOG.debug("Sikuli : {}", mes.getCode());507 if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT))) {508 conditionResult = true;509 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTNOTPRESENT);510 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));511 } else if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT))) {512 conditionResult = false;513 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTPRESENT);514 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));515 }516 } else {517 conditionResult = false;518 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_GENERIC);519 mes.resolveDescription("ERROR", "Element must start by picture=");520 }521 break;522 case Application.TYPE_SRV:523 if (tCExecution.getLastServiceCalled() != null) {524 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();525 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {526 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:527 if (!xmlUnitService.isElementPresent(responseBody, conditionValue1)) {528 conditionResult = true;529 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTNOTPRESENT);530 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));531 } else {532 conditionResult = false;533 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTPRESENT);534 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));535 }536 break;537 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:538 try {539 if (jsonService.getFromJson(responseBody, null, conditionValue1) == null) {540 conditionResult = true;541 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTNOTPRESENT);542 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));543 } else {544 conditionResult = false;545 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTPRESENT);546 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));547 }548 } catch (Exception ex) {549 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_GENERIC);550 mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));551 }552 break;553 default:554 conditionResult = false;555 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOTSUPPORTED_FOR_MESSAGETYPE);556 mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));557 mes.setDescription(mes.getDescription().replace("%CONDITION%", conditionOperator));558 }559 } else {560 conditionResult = false;561 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOOBJECTINMEMORY);562 }563 break;564 default:565 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOTSUPPORTED_FOR_APPLICATION);566 mes.setDescription(mes.getDescription().replace("%CONDITION%", conditionOperator));567 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));568 }569 }570 ans.setResultMessage(mes);571 return ans;572 }573 private AnswerItem<Boolean> evaluateCondition_ifElementVisible(String conditionOperator, String conditionValue1, TestCaseExecution tCExecution) {574 LOG.debug("Checking if Element Visible");575 AnswerItem<Boolean> ans = new AnswerItem<>();576 MessageEvent mes;577 if (tCExecution.getManualExecution().equals("Y")) {578 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUEMANUAL_IFELEMENTVISIBLE);579 mes.resolveDescription("ELEMENT", conditionValue1);580 } else if (StringUtil.isNullOrEmpty(conditionValue1)) {581 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFELEMENTVISIBLE_MISSINGPARAMETER);582 mes.setDescription(mes.getDescription().replace("%COND%", conditionOperator));583 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)584 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)585 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {586 try {587 Identifier identifier = identifierService.convertStringToIdentifier(conditionValue1);588 if (this.webdriverService.isElementVisible(tCExecution.getSession(), identifier)) {589 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTVISIBLE);590 mes.setDescription(mes.getDescription().replace("%STRING1%", conditionValue1));591 } else {592 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTVISIBLE);593 mes.setDescription(mes.getDescription().replace("%STRING1%", conditionValue1));594 }595 } catch (WebDriverException exception) {596 mes = parseWebDriverException(exception);597 }598 } else {599 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOTSUPPORTED_FOR_MESSAGETYPE);600 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementVisible"));601 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));602 }603 ans.setResultMessage(mes);604 return ans;605 }606 private AnswerItem<Boolean> evaluateCondition_ifElementNotVisible(String conditionOperator, String conditionValue1, TestCaseExecution tCExecution) {607 LOG.debug("Checking if Element is Not Visible");608 AnswerItem<Boolean> ans = new AnswerItem<>();609 MessageEvent mes;610 if (tCExecution.getManualExecution().equals("Y")) {611 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUEMANUAL_IFELEMENTNOTVISIBLE);612 mes.resolveDescription("ELEMENT", conditionValue1);613 } else if (StringUtil.isNullOrEmpty(conditionValue1)) {614 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFELEMENTNOTVISIBLE_MISSINGPARAMETER);615 mes.setDescription(mes.getDescription().replace("%COND%", conditionOperator));616 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)617 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)618 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {619 try {620 Identifier identifier = identifierService.convertStringToIdentifier(conditionValue1);621 if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {622 if (this.webdriverService.isElementNotVisible(tCExecution.getSession(), identifier)) {623 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTNOTVISIBLE);624 mes.setDescription(mes.getDescription().replace("%STRING1%", conditionValue1));625 } else {626 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTVISIBLE);627 mes.setDescription(mes.getDescription().replace("%STRING1%", conditionValue1));628 }629 } else {630 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTVISIBLE);631 mes.setDescription(mes.getDescription().replace("%STRING1%", conditionValue1));632 }633 } catch (WebDriverException exception) {634 mes = parseWebDriverException(exception);635 }636 } else {...

Full Screen

Full Screen

getSession

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.execution.impl.RobotServerService;2import org.cerberus.engine.execution.impl.RobotServerService_Service;3{4public static void main(String[] args)5{6RobotServerService_Service service = new RobotServerService_Service();7RobotServerService port = service.getRobotServerServicePort();8String session = port.getSession("test", "test");9System.out.println(session);10}11}12import org.cerberus.engine.execution.impl.RobotServerService;13import org.cerberus.engine.execution.impl.RobotServerService_Service;14{15public static void main(String[] args)16{17RobotServerService_Service service = new RobotServerService_Service();18RobotServerService port = service.getRobotServerServicePort();19String session = port.getSession("test", "test");20System.out.println(session);21String robotList = port.getRobotList(session);22System.out.println(robotList);23}24}25import org.cerberus.engine.execution.impl.RobotServerService;26import org.cerberus.engine.execution.impl.RobotServerService_Service;27{28public static void main(String[] args)29{30RobotServerService_Service service = new RobotServerService_Service();31RobotServerService port = service.getRobotServerServicePort();32String session = port.getSession("test", "test");33System.out.println(session);34String robotList = port.getRobotList(session);35System.out.println(robotList);36String robot = port.getRobot(session, "Robot1");37System.out.println(robot);38}39}40import org.cerberus.engine.execution.impl.RobotServerService;41import org.cerberus.engine.execution.impl.RobotServerService_Service;42{43public static void main(String[] args)44{45RobotServerService_Service service = new RobotServerService_Service();46RobotServerService port = service.getRobotServerServicePort();47String session = port.getSession("test", "test");48System.out.println(session);49String robotList = port.getRobotList(session);50System.out.println(robotList);

Full Screen

Full Screen

getSession

Using AI Code Generation

copy

Full Screen

1package com.mycompany.myapp;2import org.cerberus.engine.execution.impl.RobotServerService;3public class 3 {4 public static void main(String[] args) {5 RobotServerService robotServerService = new RobotServerService();6 }7}8package com.mycompany.myapp;9import org.cerberus.engine.execution.impl.RobotServerService;10public class 4 {11 public static void main(String[] args) {12 RobotServerService robotServerService = new RobotServerService();13 }14}15package com.mycompany.myapp;16import org.cerberus.engine.execution.impl.RobotServerService;17public class 5 {18 public static void main(String[] args) {19 RobotServerService robotServerService = new RobotServerService();20 }21}22package com.mycompany.myapp;23import org.cerberus.engine.execution.impl.RobotServerService;24public class 6 {25 public static void main(String[] args) {26 RobotServerService robotServerService = new RobotServerService();27 }28}29package com.mycompany.myapp;30import org.cerberus.engine.execution.impl.RobotServerService;31public class 7 {32 public static void main(String[] args) {33 RobotServerService robotServerService = new RobotServerService();34 }35}

Full Screen

Full Screen

getSession

Using AI Code Generation

copy

Full Screen

1package org.cerberus.engine.execution.impl;2import org.cerberus.engine.entity.Session;3import org.cerberus.engine.entity.Test;4import org.cerberus.engine.execution.IRobotServerService;5public class RobotServerService implements IRobotServerService {6 public Session getSession(Test test) {7 Session session = new Session();8 session.setSessionId("sessionId");9 session.setSessionKey("sessionKey");10 return session;11 }12}13package org.cerberus.engine.execution.impl;14import org.cerberus.engine.entity.Session;15import org.cerberus.engine.entity.Test;16import org.cerberus.engine.execution.IRobotServerService;17public class RobotServerService implements IRobotServerService {18 public Session getSession(Test test) {19 Session session = new Session();20 session.setSessionId("sessionId");21 session.setSessionKey("sessionKey");22 return session;23 }24 public void runTest(Session session, Test test) {25 }26}27package org.cerberus.engine.execution.impl;28import org.cerberus.engine.entity.Session;29import org.cerberus.engine.entity.Test;30import org.cerberus.engine.execution.IRobotServerService;31public class RobotServerService implements IRobotServerService {32 public Session getSession(Test test) {33 Session session = new Session();34 session.setSessionId("sessionId");35 session.setSessionKey("sessionKey");36 return session;37 }38 public void runTest(Session session, Test test) {39 }40 public void stopTest(Session session, Test test) {41 }42}

Full Screen

Full Screen

getSession

Using AI Code Generation

copy

Full Screen

1package org.cerberus.jar;2import org.cerberus.engine.execution.impl.RobotServerService;3public class RobotServerServiceTest {4 public static void main(String[] args) {5 RobotServerService robotServerService = new RobotServerService();6 robotServerService.getSession();7 }8}9package org.cerberus.jar;10import org.cerberus.engine.execution.impl.RobotServerService;11public class RobotServerServiceTest {12 public static void main(String[] args) {13 RobotServerService robotServerService = new RobotServerService();14 robotServerService.getSession();15 }16}17package org.cerberus.jar;18import org.cerberus.engine.execution.impl.RobotServerService;19public class RobotServerServiceTest {20 public static void main(String[] args) {21 RobotServerService robotServerService = new RobotServerService();22 robotServerService.getSession();23 }24}25package org.cerberus.jar;26import org.cerberus.engine.execution.impl.RobotServerService;27public class RobotServerServiceTest {28 public static void main(String[] args) {29 RobotServerService robotServerService = new RobotServerService();30 robotServerService.getSession();31 }32}33package org.cerberus.jar;34import org.cerberus.engine.execution.impl.RobotServerService;35public class RobotServerServiceTest {36 public static void main(String[] args) {37 RobotServerService robotServerService = new RobotServerService();38 robotServerService.getSession();39 }40}41package org.cerberus.jar;42import org.cerberus.engine.execution.impl.RobotServerService;43public class RobotServerServiceTest {44 public static void main(String[] args) {45 RobotServerService robotServerService = new RobotServerService();

Full Screen

Full Screen

getSession

Using AI Code Generation

copy

Full Screen

1package org.cerberus.engine.execution.impl;2import org.cerberus.engine.execution.ISession;3import org.cerberus.engine.execution.impl.RobotServerService;4import org.cerberus.engine.execution.impl.Session;5public class RobotServerService {6public ISession getSession() throws Exception {7 return new Session();8 }9}10package org.cerberus.engine.execution.impl;11import org.cerberus.engine.execution.ISession;12import org.cerberus.engine.execution.impl.Session;13import org.cerberus.engine.execution.impl.Robot;14public class Session implements ISession {15public Robot getRobot() throws Exception {16 return new Robot();17 }18}19package org.cerberus.engine.execution.impl;20import org.cerberus.engine.execution.ISession;21import org.cerberus.engine.execution.impl.Session;22import org.cerberus.engine.execution.impl.Robot;23import org.cerberus.engine.execution.impl.RobotServerService;24public class Session implements ISession {25public Robot getRobot() throws Exception {26 return new Robot();27 }28}29package org.cerberus.engine.execution.impl;30import org.cerberus.engine.execution.ISession;31import org.cerberus.engine.execution.impl.Session;32import org.cerberus.engine.execution.impl.Robot;33import org.cerberus.engine.execution.impl.RobotServerService;34import org.cerberus.engine.execution.impl.RobotServerService;35public class Session implements ISession {36public Robot getRobot() throws Exception {37 return new Robot();38 }39}40package org.cerberus.engine.execution.impl;41import org.cerberus.engine.execution.ISession;42import org.cerberus.engine.execution.impl.Session;43import org.cerberus.engine.execution.impl.Robot;44import org.cerberus.engine.execution.impl.RobotServerService;45import org.cerberus.engine.execution.impl.RobotServerService;46import org.cerberus.engine.execution.impl.Robot

Full Screen

Full Screen

getSession

Using AI Code Generation

copy

Full Screen

1package com.cerberus;2import org.cerberus.engine.execution.impl.RobotServerService;3public class CerberusRobotServer {4 public static void main(String[] args) {5 RobotServerService robotServerService = new RobotServerService();6 robotServerService.getSession();7 }8}9package com.cerberus;10import org.cerberus.engine.execution.impl.RobotServerService;11public class CerberusRobotServer {12 public static void main(String[] args) {13 RobotServerService robotServerService = new RobotServerService();14 robotServerService.executeTest("Test", "TestCase");15 }16}17package com.cerberus;18import org.cerberus.engine.execution.impl.RobotServerService;19public class CerberusRobotServer {20 public static void main(String[] args) {21 RobotServerService robotServerService = new RobotServerService();22 robotServerService.executeTest("Test", "TestCase", "tag1,tag2");23 }24}25package com.cerberus;26import org.cerberus.engine.execution.impl.RobotServerService;27public class CerberusRobotServer {28 public static void main(String[] args) {29 RobotServerService robotServerService = new RobotServerService();30 robotServerService.executeTest("Test", "TestCase", "tag1,tag2", "en_US");31 }32}33package com.cerberus;34import org.cerberus.engine.execution.impl.RobotServerService;35public class CerberusRobotServer {36 public static void main(String[] args) {37 RobotServerService robotServerService = new RobotServerService();38 robotServerService.executeTest("Test", "TestCase", "tag1,tag2", "en_US", "MyRobotServer");39 }40}

Full Screen

Full Screen

getSession

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.execution.impl.RobotServerService;2import org.cerberus.engine.execution.impl.RobotSession;3import org.cerberus.engine.execution.impl.RobotSessionImpl;4import org.cerberus.engine.entity.impl.RobotTest;5import org.cerberus.engine.entity.impl.RobotTestImpl;6import org.cerberus.engine.entity.impl.RobotTestList;7import org.cerberus.engine.entity.impl.RobotTestListImpl;8import org.cerberus.engine.entity.impl.RobotTestListResult;9import org.cerberus.engine.entity.impl.RobotTestListResultImpl;10import org.cerberus.engine.entity.impl.RobotTestResult;11import org.cerberus.engine.entity.impl.RobotTestResultImpl;12import org.cerberus.engine.execution.impl.RobotServerService;13import org.cerberus.engine.execution.impl.RobotSession;14import org.cerberus.engine.execution.impl.RobotSessionImpl;15import org.cerberus.engine.entity.impl.RobotTest;16import org.cerberus.engine.entity.impl.RobotTestImpl;17import org.cerberus.engine.entity.impl.RobotTestList;18import org.cerberus.engine.entity.impl.RobotTestListImpl;19import org.cerberus.engine.entity.impl.RobotTestListResult;20import org.cerberus.engine.entity.impl.RobotTestListResultImpl;21import org.cerberus.engine.entity.impl.RobotTestResult;22import org.cerberus.engine.entity.impl.RobotTestResultImpl;23public class 3 {24public static void main(String[] args) {25RobotServerService serverService = new RobotServerService();26RobotSession session = serverService.getSession();27RobotTest test = new RobotTestImpl();28test.setTestName("Test1");29RobotTestList testList = new RobotTestListImpl();30testList.addTest(test);31RobotTestListResult testListResult = new RobotTestListResultImpl();32RobotTestResult testResult = new RobotTestResultImpl();

Full Screen

Full Screen

getSession

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.execution.impl.RobotServerService;2import org.cerberus.engine.execution.impl.RobotServerServiceFactory;3import org.cerberus.engine.execution.impl.RobotServerSession;4import org.cerberus.engine.execution.impl.RobotServerSessionFactory;5import org.cerberus.engine.execution.impl.RobotServerSessionFactory;6import org.cerberus.engine.execution.impl.RobotServerService;7import org.cerberus.engine.execution.impl.RobotServerServiceFactory;8import org.cerberus.engine.execution.impl.RobotServerSession;9import org.cerberus.engine.execution.impl.RobotServerSessionFactory;10import org.cerberus.engine.execution.impl.RobotServerSessionFactory;11{12public static void main(String[] args)13{14RobotServerSessionFactory factory = RobotServerServiceFactory.getInstance();15}16}17import org.cerberus.engine.execution.impl.RobotServerService;18import org.cerberus.engine.execution.impl.RobotServerServiceFactory;19import org.cerberus.engine.execution.impl.RobotServerSession;20import org.cerberus.engine.execution.impl.RobotServerSessionFactory;21import org.cerberus.engine.execution.impl.RobotServerSessionFactory;22import org.cerberus.engine.execution.impl.RobotServerService;23import org.cerberus.engine.execution.impl.RobotServerServiceFactory;24import org.cerberus.engine.execution.impl.RobotServerSession;25import org.cerberus.engine.execution.impl.RobotServerSessionFactory;26import org.cerberus.engine.execution.impl.RobotServerSessionFactory;27{28public static void main(String[] args)29{30RobotServerSessionFactory factory = RobotServerServiceFactory.getInstance();31RobotServerResult result = session.executeScript("script");32}33}

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