Best Cerberus-source code snippet using org.cerberus.engine.execution.impl.IdentifierService.convertStringToIdentifier
Source:ActionService.java
...411 MessageEvent message;412 try {413 Identifier identifier = null;414 if (!StringUtil.isNullOrEmpty(element)) {415 identifier = identifierService.convertStringToIdentifier(element);416 }417 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {418 return androidAppiumService.scrollTo(tCExecution.getSession(), identifier, text);419 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {420 return iosAppiumService.scrollTo(tCExecution.getSession(), identifier, text);421 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {422 return webdriverService.scrollTo(tCExecution.getSession(), identifier, text);423 }424 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);425 message.setDescription(message.getDescription().replace("%ACTION%", "scrollTo"));426 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));427 return message;428 } catch (Exception e) {429 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC);430 String messageString = e.getMessage().split("\n")[0];431 message.setDescription(message.getDescription().replace("%DETAIL%", messageString));432 LOG.debug("Exception Running scroll to :" + messageString, e);433 return message;434 }435 }436 private MessageEvent doActionExecuteCommand(TestCaseExecution tCExecution, String command, String args) {437 MessageEvent message;438 try {439 return androidAppiumService.executeCommand(tCExecution.getSession(), command, args);440 } catch (Exception e) {441 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTECOMMAND);442 String messageString = e.getMessage().split("\n")[0];443 message.setDescription(message.getDescription().replace("%EXCEPTION%", messageString));444 LOG.debug("Exception Running Shell :" + messageString, e);445 return message;446 }447 }448 private MessageEvent doActionExecuteCerberusCommand(TestCaseExecution tCExecution, String command) {449 MessageEvent message;450 try {451 return cerberusCommand.executeCerberusCommand(command);452 } catch (CerberusEventException e) {453 message = e.getMessageError();454 LOG.debug("Exception Running Shell :" + message.getMessage().getDescription());455 return message;456 }457 }458 private MessageEvent doActionClick(TestCaseExecution tCExecution, String value1, String value2) {459 String element;460 try {461 /**462 * Get element to use String object if not empty, String property if463 * object empty, throws Exception if both empty)464 */465 element = getElementToUse(value1, value2, TestCaseStepAction.ACTION_CLICK, tCExecution);466 /**467 * Get Identifier (identifier, locator) and check it's valid468 */469 Identifier identifier = identifierService.convertStringToIdentifier(element);470 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {471 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {472 identifierService.checkWebElementIdentifier(identifier.getIdentifier());473 return webdriverService.doSeleniumActionClick(tCExecution.getSession(), identifier, false, false);474 } else {475 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {476 return sikuliService.doSikuliActionClick(tCExecution.getSession(), identifier.getLocator(), "");477 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {478 return sikuliService.doSikuliActionClick(tCExecution.getSession(), "", identifier.getLocator());479 } else {480 identifierService.checkWebElementIdentifier(identifier.getIdentifier());481 return webdriverService.doSeleniumActionClick(tCExecution.getSession(), identifier, true, true);482 }483 }484 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {485 identifierService.checkWebElementIdentifier(identifier.getIdentifier());486 return androidAppiumService.click(tCExecution.getSession(), identifier);487 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {488 identifierService.checkWebElementIdentifier(identifier.getIdentifier());489 return iosAppiumService.click(tCExecution.getSession(), identifier);490 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {491 identifierService.checkSikuliIdentifier(identifier.getIdentifier());492 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {493 return sikuliService.doSikuliActionClick(tCExecution.getSession(), identifier.getLocator(), "");494 } else {495 return sikuliService.doSikuliActionClick(tCExecution.getSession(), "", identifier.getLocator());496 }497 } else {498 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)499 .resolveDescription("ACTION", "Click")500 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());501 }502 } catch (CerberusEventException ex) {503 LOG.fatal("Error doing Action Click :" + ex, ex);504 return ex.getMessageError();505 }506 }507 private MessageEvent doActionExecuteJS(TestCaseExecution tCExecution, String value1, String value2) {508 MessageEvent message;509 String script = value1;510 String valueFromJS;511 try {512 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {513 valueFromJS = this.webdriverService.getValueFromJS(tCExecution.getSession(), script);514 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_EXECUTEJS);515 message.setDescription(message.getDescription().replace("%SCRIPT%", script));516 message.setDescription(message.getDescription().replace("%VALUE%", valueFromJS));517 return message;518 }519 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);520 message.setDescription(message.getDescription().replace("%ACTION%", "executeJS"));521 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));522 return message;523 } catch (Exception e) {524 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTEJS);525 String messageString = e.getMessage().split("\n")[0];526 message.setDescription(message.getDescription().replace("%EXCEPTION%", messageString));527 LOG.debug("Exception Running JS Script :" + messageString);528 return message;529 }530 }531 private MessageEvent doActionMouseLeftButtonPress(TestCaseExecution tCExecution, String object, String property) {532 MessageEvent message;533 String element;534 try {535 /**536 * Get element to use String object if not empty, String property if537 * object empty, throws Exception if both empty)538 */539 element = getElementToUse(object, property, "mouseLeftButtonPress", tCExecution);540 /**541 * Get Identifier (identifier, locator)542 */543 Identifier identifier = identifierService.convertStringToIdentifier(element);544 identifierService.checkWebElementIdentifier(identifier.getIdentifier());545 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {546 return webdriverService.doSeleniumActionMouseDown(tCExecution.getSession(), identifier, true, true);547 }548 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);549 message.setDescription(message.getDescription().replace("%ACTION%", "MouseDown"));550 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));551 return message;552 } catch (CerberusEventException ex) {553 LOG.fatal("Error doing Action MouseDown :" + ex);554 return ex.getMessageError();555 }556 }557 private MessageEvent doActionRightClick(TestCaseExecution tCExecution, String object, String property) {558 MessageEvent message;559 String element;560 try {561 /**562 * Get element to use String object if not empty, String property if563 * object empty, throws Exception if both empty)564 */565 element = getElementToUse(object, property, "rightClick", tCExecution);566 /**567 * Get Identifier (identifier, locator)568 */569 Identifier identifier = identifierService.convertStringToIdentifier(element);570 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {571 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {572 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), identifier.getLocator(), "");573 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {574 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), "", identifier.getLocator());575 } else {576 identifierService.checkWebElementIdentifier(identifier.getIdentifier());577 return webdriverService.doSeleniumActionRightClick(tCExecution.getSession(), identifier);578 }579 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {580 identifierService.checkSikuliIdentifier(identifier.getIdentifier());581 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {582 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), identifier.getLocator(), "");583 } else {584 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), "", identifier.getLocator());585 }586 }587 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);588 message.setDescription(message.getDescription().replace("%ACTION%", "rightClick"));589 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));590 return message;591 } catch (CerberusEventException ex) {592 LOG.fatal("Error doing Action RightClick :" + ex);593 return ex.getMessageError();594 }595 }596 private MessageEvent doActionMouseLeftButtonRelease(TestCaseExecution tCExecution, String object, String property) {597 MessageEvent message;598 String element;599 try {600 /**601 * Get element to use String object if not empty, String property if602 * object empty, throws Exception if both empty)603 */604 element = getElementToUse(object, property, "mouseLeftButtonRelease", tCExecution);605 /**606 * Get Identifier (identifier, locator)607 */608 Identifier identifier = identifierService.convertStringToIdentifier(element);609 identifierService.checkWebElementIdentifier(identifier.getIdentifier());610 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {611 return webdriverService.doSeleniumActionMouseUp(tCExecution.getSession(), identifier, true, true);612 }613 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);614 message.setDescription(message.getDescription().replace("%ACTION%", "MouseUp"));615 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));616 return message;617 } catch (CerberusEventException ex) {618 LOG.fatal("Error doing Action MouseUp :" + ex);619 return ex.getMessageError();620 }621 }622 private MessageEvent doActionSwitchToWindow(TestCaseExecution tCExecution, String object, String property) {623 String element;624 try {625 /**626 * Get element to use String object if not empty, String property if627 * object empty, throws Exception if both empty)628 */629 element = getElementToUse(object, property, "switchToWindow", tCExecution);630 /**631 * Get Identifier (identifier, locator)632 */633 Identifier identifier = identifierService.convertStringToIdentifier(element);634 //identifierService.checkWebElementIdentifier(identifier.getIdentifier());635 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {636 return webdriverService.doSeleniumActionSwitchToWindow(tCExecution.getSession(), identifier);637 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {638 return androidAppiumService.switchToContext(tCExecution.getSession(), identifier);639 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {640 return iosAppiumService.switchToContext(tCExecution.getSession(), identifier);641 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {642 return sikuliService.doSikuliActionSwitchApp(tCExecution.getSession(), identifier.getLocator());643 } else {644 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)645 .resolveDescription("ACTION", "SwitchToWindow")646 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());647 }648 } catch (CerberusEventException ex) {649 LOG.fatal("Error doing Action SwitchToWindow :" + ex);650 return ex.getMessageError();651 }652 }653 private MessageEvent doActionManageDialog(TestCaseExecution tCExecution, String value1, String value2) {654 MessageEvent message;655 String element;656 try {657 /**658 * Get element to use String object if not empty, String property if659 * object empty, throws Exception if both empty)660 */661 element = getElementToUse(value1, value2, "manageDialog", tCExecution);662 /**663 * Get Identifier (identifier, locator)664 */665 Identifier identifier = identifierService.convertStringToIdentifier(element);666 identifierService.checkWebElementIdentifier(identifier.getIdentifier());667 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {668 return webdriverService.doSeleniumActionManageDialog(tCExecution.getSession(), identifier);669 }670 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);671 message.setDescription(message.getDescription().replace("%ACTION%", "ManageDialog"));672 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));673 return message;674 } catch (CerberusEventException ex) {675 LOG.fatal("Error doing Action ManageDialog :" + ex);676 return ex.getMessageError();677 }678 }679 private MessageEvent doActionManageDialogKeyPress(TestCaseExecution tCExecution, String value1) {680 MessageEvent message;681 String element;682 try {683 /**684 * Get element to use String object if not empty, String property if685 * object empty, throws Exception if both empty)686 */687 element = getElementToUse(value1, "", "manageDialogKeyPress", tCExecution);688 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {689 return webdriverService.doSeleniumActionManageDialogKeyPress(tCExecution.getSession(), element);690 }691 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);692 message.setDescription(message.getDescription().replace("%ACTION%", "ManageDialogKeypress"));693 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));694 return message;695 } catch (CerberusEventException ex) {696 LOG.fatal("Error doing Action ManageDialogKeypress :" + ex);697 return ex.getMessageError();698 }699 }700 private MessageEvent doActionDoubleClick(TestCaseExecution tCExecution, String object, String property) {701 MessageEvent message;702 String element;703 try {704 /**705 * Get element to use String object if not empty, String property if706 * object empty, throws Exception if both empty)707 */708 element = getElementToUse(object, property, "doubleClick", tCExecution);709 /**710 * Get Identifier (identifier, locator)711 */712 Identifier identifier = identifierService.convertStringToIdentifier(element);713 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {714 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {715 identifierService.checkWebElementIdentifier(identifier.getIdentifier());716 return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, false, false);717 } else {718 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {719 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");720 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {721 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());722 } else {723 identifierService.checkWebElementIdentifier(identifier.getIdentifier());724 return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, true);725 }726 }727 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)728 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {729 identifierService.checkWebElementIdentifier(identifier.getIdentifier());730 return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, false);731 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {732 identifierService.checkSikuliIdentifier(identifier.getIdentifier());733 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {734 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");735 } else {736 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());737 }738 }739 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);740 message.setDescription(message.getDescription().replace("%ACTION%", "doubleClick"));741 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));742 return message;743 } catch (CerberusEventException ex) {744 LOG.fatal("Error doing Action DoubleClick :" + ex);745 return ex.getMessageError();746 }747 }748 private MessageEvent doActionType(TestCaseExecution tCExecution, String object, String property, String propertyName) {749 try {750 /**751 * Check object and property are not null for GUI/APK/IPA Check752 * property is not null for FAT Application753 */754 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)755 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)756 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {757 if (object == null || property == null) {758 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);759 }760 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {761 if (property == null) {762 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);763 }764 }765 /**766 * Get Identifier (identifier, locator) if object not null767 */768 Identifier identifier = new Identifier();769 if (object != null) {770 identifier = identifierService.convertStringToIdentifier(object);771 }772 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {773 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {774 identifierService.checkWebElementIdentifier(identifier.getIdentifier());775 return webdriverService.doSeleniumActionType(tCExecution.getSession(), identifier, property, propertyName, false, false);776 } else {777 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {778 return sikuliService.doSikuliActionType(tCExecution.getSession(), identifier.getLocator(), property);779 } else {780 identifierService.checkWebElementIdentifier(identifier.getIdentifier());781 return webdriverService.doSeleniumActionType(tCExecution.getSession(), identifier, property, propertyName, true, true);782 }783 }784 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {785 return androidAppiumService.type(tCExecution.getSession(), identifier, property, propertyName);786 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {787 return iosAppiumService.type(tCExecution.getSession(), identifier, property, propertyName);788 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {789 String locator = "";790 if (!StringUtil.isNullOrEmpty(object)) {791 identifierService.checkSikuliIdentifier(identifier.getIdentifier());792 locator = identifier.getLocator();793 }794 return sikuliService.doSikuliActionType(tCExecution.getSession(), locator, property);795 } else {796 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)797 .resolveDescription("ACTION", "Type")798 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());799 }800 } catch (CerberusEventException ex) {801 LOG.fatal("Error doing Action Type : " + ex);802 return ex.getMessageError();803 }804 }805 private MessageEvent doActionMouseOver(TestCaseExecution tCExecution, String object, String property) {806 MessageEvent message;807 String element;808 try {809 /**810 * Get element to use String object if not empty, String property if811 * object empty, throws Exception if both empty)812 */813 element = getElementToUse(object, property, "mouseOver", tCExecution);814 /**815 * Get Identifier (identifier, locator)816 */817 Identifier identifier = identifierService.convertStringToIdentifier(element);818 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {819 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {820 identifierService.checkWebElementIdentifier(identifier.getIdentifier());821 return webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier, false, false);822 } else {823 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {824 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");825 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {826 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());827 } else {828 identifierService.checkWebElementIdentifier(identifier.getIdentifier());829 return webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier, true, true);830 }831 }832 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {833 identifierService.checkSikuliIdentifier(identifier.getIdentifier());834 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {835 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");836 } else {837 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());838 }839 }840 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);841 message.setDescription(message.getDescription().replace("%ACTION%", "mouseOver"));842 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));843 return message;844 } catch (CerberusEventException ex) {845 LOG.fatal("Error doing Action MouseOver :" + ex);846 return ex.getMessageError();847 }848 }849 private MessageEvent doActionMouseOverAndWait(TestCaseExecution tCExecution, String object, String property) {850 MessageEvent message;851 try {852 /**853 * Check object is not null854 */855 if (object == null) {856 return new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVERANDWAIT_GENERIC);857 }858 /**859 * Get Identifier (identifier, locator)860 */861 Identifier identifier = identifierService.convertStringToIdentifier(object);862 identifierService.checkWebElementIdentifier(identifier.getIdentifier());863 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {864 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {865 message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");866 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {867 message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());868 } else {869 message = webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier, true, true);870 }871 if (message.getCodeString().equals("OK")) {872 message = this.doActionWait(tCExecution, property, null);873 }874 return message;875 }876 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);877 message.setDescription(message.getDescription().replace("%ACTION%", "mouseOverAndWait"));878 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));879 return message;880 } catch (CerberusEventException ex) {881 LOG.fatal("Error doing Action MouseOverAndWait :" + ex);882 return ex.getMessageError();883 }884 }885 private MessageEvent doActionWait(TestCaseExecution tCExecution, String object, String property) {886 MessageEvent message;887 String element;888 long timeToWaitInMs = 0;889 Identifier identifier = null;890 try {891 /**892 * Get element to use String object if not empty, String property if893 * object empty, null if both are empty894 */895 element = getElementToUse(object, property, "wait", tCExecution);896 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)897 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)898 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)899 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) { // If application are Selenium or appium based, we have a session and can use it to wait.900 /**901 * if element is integer, set time to that value else Get902 * Identifier (identifier, locator)903 */904 if (StringUtil.isNullOrEmpty(element)) {905 timeToWaitInMs = tCExecution.getCerberus_action_wait_default();906 } else if (StringUtil.isInteger(element)) {907 timeToWaitInMs = Long.valueOf(element);908 } else {909 identifier = identifierService.convertStringToIdentifier(element);910 }911 if (identifier != null && identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {912 return sikuliService.doSikuliActionWait(tCExecution.getSession(), identifier.getLocator(), "");913 } else if (identifier != null && identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {914 return sikuliService.doSikuliActionWait(tCExecution.getSession(), "", identifier.getLocator());915 } else if (identifier != null) {916 identifierService.checkWebElementIdentifier(identifier.getIdentifier());917 return webdriverService.doSeleniumActionWait(tCExecution.getSession(), identifier);918 } else {919 return this.waitTime(timeToWaitInMs);920 }921 } else { // For any other application we wait for the integer value.922 if (StringUtil.isNullOrEmpty(element)) {923 // Get default wait from parameter924 timeToWaitInMs = tCExecution.getCerberus_action_wait_default();925 } else if (StringUtil.isInteger(element)) {926 timeToWaitInMs = Long.valueOf(element);927 }928 return this.waitTime(timeToWaitInMs);929 }930 } catch (CerberusEventException ex) {931 LOG.fatal("Error doing Action Wait :" + ex);932 return ex.getMessageError();933 }934 }935 private MessageEvent doActionKeyPress(TestCaseExecution tCExecution, String value1, String value2) {936 try {937 String appType = tCExecution.getApplicationObj().getType();938 /**939 * Check value1 and value2 are not null For IPA and APK, only value2940 * (key to press) is mandatory For GUI and FAT, both parameters are941 * mandatory942 */943 if (StringUtil.isNullOrEmpty(value2)) {944 return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_MISSINGKEY).resolveDescription("APPLICATIONTYPE", appType);945 }946 /**947 * Get Identifier (identifier, locator)948 */949 if (StringUtil.isNullOrEmpty(value1) && appType.equalsIgnoreCase(Application.TYPE_GUI)) {950 value1 = "xpath=//body";951 }952 Identifier objectIdentifier = identifierService.convertStringToIdentifier(value1);953 if (appType.equalsIgnoreCase(Application.TYPE_GUI)) {954 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.MAC.toString())955 || tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.IOS.toString())) {956 return iosAppiumService.keyPress(tCExecution.getSession(), value2);957 } else if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {958 return webdriverService.doSeleniumActionKeyPress(tCExecution.getSession(), objectIdentifier, value2, false, false);959 }960 if (objectIdentifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {961 return sikuliService.doSikuliActionKeyPress(tCExecution.getSession(), objectIdentifier.getLocator(), value2);962 } else {963 identifierService.checkWebElementIdentifier(objectIdentifier.getIdentifier());964 return webdriverService.doSeleniumActionKeyPress(tCExecution.getSession(), objectIdentifier, value2, true, true);965 }966 } else if (appType.equalsIgnoreCase(Application.TYPE_APK)) {967 return androidAppiumService.keyPress(tCExecution.getSession(), value2);968 } else if (appType.equalsIgnoreCase(Application.TYPE_IPA)) {969 return iosAppiumService.keyPress(tCExecution.getSession(), value2);970 } else if (appType.equalsIgnoreCase(Application.TYPE_FAT)) {971 return sikuliService.doSikuliActionKeyPress(tCExecution.getSession(), objectIdentifier.getLocator(), value2);972 } else {973 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)974 .resolveDescription("ACTION", "KeyPress")975 .resolveDescription("APPLICATIONTYPE", appType);976 }977 } catch (CerberusEventException ex) {978 LOG.debug("Error doing Action KeyPress :" + ex);979 return ex.getMessageError();980 } catch (Exception ex) {981 LOG.debug("Error doing Action KeyPress :" + ex);982 return new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC)983 .resolveDescription("DETAIL", ex.toString());984 }985 }986 private MessageEvent doActionOpenURL(TestCaseExecution tCExecution, String object, String property, boolean withBase) {987 MessageEvent message;988 String element;989 try {990 /**991 * Get element to use String object if not empty, String property if992 * object empty, throws Exception if both empty)993 */994 element = getElementToUse(object, property, "openUrl[WithBase]", tCExecution);995 /**996 * Get Identifier (identifier, locator)997 */998 Identifier identifier = new Identifier();999 identifier.setIdentifier("url");1000 identifier.setLocator(element);1001 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1002 return webdriverService.doSeleniumActionOpenURL(tCExecution.getSession(), tCExecution.getUrl(), identifier, withBase);1003 }1004 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1005 message.setDescription(message.getDescription().replace("%ACTION%", "OpenURL[WithBase]"));1006 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1007 return message;1008 } catch (CerberusEventException ex) {1009 LOG.fatal("Error doing Action OpenUrl :" + ex);1010 return ex.getMessageError();1011 }1012 }1013 private MessageEvent doActionOpenApp(TestCaseExecution tCExecution, String value1, String value2) {1014 MessageEvent message;1015 /**1016 * Check value1 is not null or empty1017 */1018 if (value1 == null || "".equals(value1)) {1019 return new MessageEvent(MessageEventEnum.ACTION_FAILED_OPENAPP);1020 }1021 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)1022 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1023 return sikuliService.doSikuliActionOpenApp(tCExecution.getSession(), value1);1024 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {1025 return androidAppiumService.openApp(tCExecution.getSession(), value1, value2);1026 }1027 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1028 message.setDescription(message.getDescription().replace("%ACTION%", "OpenApp"));1029 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1030 return message;1031 }1032 private MessageEvent doActionCloseApp(TestCaseExecution tCExecution, String value1) {1033 MessageEvent message;1034 /**1035 * Check value1 is not null or empty1036 */1037 if (value1 == null || "".equals(value1)) {1038 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLOSEAPP);1039 }1040 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)1041 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1042 return sikuliService.doSikuliActionCloseApp(tCExecution.getSession(), value1);1043 }1044 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1045 message.setDescription(message.getDescription().replace("%ACTION%", "CloseApp"));1046 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1047 return message;1048 }1049 private MessageEvent doActionWaitVanish(TestCaseExecution tCExecution, String value1) {1050 try {1051 /**1052 * Check value1 is not null or empty1053 */1054 if (value1 == null || "".equals(value1)) {1055 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLOSEAPP);1056 }1057 /**1058 * Get Identifier (identifier, locator)1059 */1060 Identifier identifier = identifierService.convertStringToIdentifier(value1);1061 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1062 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {1063 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), identifier.getLocator(), "");1064 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {1065 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), "", identifier.getLocator());1066 } else {1067 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1068 return webdriverService.doSeleniumActionWaitVanish(tCExecution.getSession(), identifier);1069 }1070 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)1071 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1072 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1073 return webdriverService.doSeleniumActionWaitVanish(tCExecution.getSession(), identifier);1074 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {1075 identifierService.checkSikuliIdentifier(identifier.getIdentifier());1076 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {1077 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), identifier.getLocator(), "");1078 } else {1079 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), "", identifier.getLocator());1080 }1081 } else {1082 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1083 .resolveDescription("ACTION", "WaitVanish")1084 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());1085 }1086 } catch (CerberusEventException ex) {1087 LOG.fatal("Error doing Action KeyPress :" + ex);1088 return ex.getMessageError();1089 }1090 }1091 private MessageEvent doActionSelect(TestCaseExecution tCExecution, String value1, String value2) {1092 MessageEvent message;1093 try {1094 /**1095 * Check object and property are not null1096 */1097 if (StringUtil.isNullOrEmpty(value1) || StringUtil.isNullOrEmpty(value2)) {1098 return new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT);1099 }1100 /**1101 * Get Identifier (identifier, locator)1102 */1103 Identifier identifierObject = identifierService.convertStringToIdentifier(value1);1104 Identifier identifierValue = identifierService.convertStringToSelectIdentifier(value2);1105 identifierService.checkWebElementIdentifier(identifierObject.getIdentifier());1106 identifierService.checkSelectOptionsIdentifier(identifierValue.getIdentifier());1107 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)1108 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)1109 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1110 if (tCExecution.getRobotObj().getPlatform().equalsIgnoreCase(Platform.ANDROID.toString())) {1111 return webdriverService.doSeleniumActionSelect(tCExecution.getSession(), identifierObject, identifierValue, false, false);1112 }1113 return webdriverService.doSeleniumActionSelect(tCExecution.getSession(), identifierObject, identifierValue, true, true);1114 }1115 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1116 message.setDescription(message.getDescription().replace("%ACTION%", "Select"));1117 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1118 return message;1119 } catch (CerberusEventException ex) {1120 LOG.fatal("Error doing Action Select :" + ex);1121 return ex.getMessageError();1122 }1123 }1124 private MessageEvent doActionUrlLogin(TestCaseExecution tCExecution) {1125 MessageEvent message;1126 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1127 return webdriverService.doSeleniumActionUrlLogin(tCExecution.getSession(), tCExecution.getUrl(), tCExecution.getCountryEnvironmentParameters().getUrlLogin());1128 }1129 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1130 message.setDescription(message.getDescription().replace("%ACTION%", "UrlLogin"));1131 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1132 return message;1133 }1134 private MessageEvent doActionFocusToIframe(TestCaseExecution tCExecution, String object, String property) {1135 MessageEvent message;1136 String element;1137 try {1138 /**1139 * Get element to use String object if not empty, String property if1140 * object empty, throws Exception if both empty)1141 */1142 element = getElementToUse(object, property, "focusToIframe", tCExecution);1143 /**1144 * Get Identifier (identifier, locator)1145 */1146 Identifier identifier = identifierService.convertStringToIdentifier(element);1147 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1148 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1149 return webdriverService.doSeleniumActionFocusToIframe(tCExecution.getSession(), identifier);1150 }1151 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1152 message.setDescription(message.getDescription().replace("%ACTION%", "FocusToIframe"));1153 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1154 return message;1155 } catch (CerberusEventException ex) {1156 LOG.fatal("Error doing Action FocusToIframe :" + ex);1157 return ex.getMessageError();1158 }1159 }1160 private MessageEvent doActionFocusDefaultIframe(TestCaseExecution tCExecution) {1161 MessageEvent message;1162 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1163 return webdriverService.doSeleniumActionFocusDefaultIframe(tCExecution.getSession());1164 }1165 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1166 message.setDescription(message.getDescription().replace("%ACTION%", "FocusDefaultIframe"));1167 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1168 return message;1169 }1170 public MessageEvent doActionDragAndDrop(TestCaseExecution tCExecution, String value1, String value2) throws IOException {1171 MessageEvent message;1172 try {1173 /**1174 * Check source and target are not null1175 */1176 if (StringUtil.isNullOrEmpty(value1)) {1177 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DRAGANDDROP);1178 message.setDescription(message.getDescription().replace("%ELEMENT%", value1));1179 return message;1180 } else if (StringUtil.isNullOrEmpty(value2)) {1181 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DRAGANDDROP);1182 message.setDescription(message.getDescription().replace("%ELEMENT%", value2));1183 return message;1184 }1185 Identifier identifierDrag = identifierService.convertStringToIdentifier(value1);1186 Identifier identifierDrop = identifierService.convertStringToIdentifier(value2);1187 identifierService.checkWebElementIdentifier(identifierDrag.getIdentifier());1188 identifierService.checkWebElementIdentifier(identifierDrop.getIdentifier());1189 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1190 return webdriverService.doSeleniumActionDragAndDrop(tCExecution.getSession(), identifierDrag, identifierDrop, true, true);1191 }1192 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1193 message.setDescription(message.getDescription().replace("%ACTION%", "Select"));1194 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1195 return message;1196 } catch (CerberusEventException ex) {1197 LOG.fatal("Error doing Action DragAndDrop :" + ex);1198 return ex.getMessageError();1199 }1200 }1201 private MessageEvent doActionCallService(TestCaseStepActionExecution testCaseStepActionExecution, String value1, String value2, String value3) {1202 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);1203 TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();1204 AnswerItem lastServiceCalledAnswer;1205 lastServiceCalledAnswer = serviceService.callService(value1, value2, value3, null, null, null, null, tCExecution);1206 message = lastServiceCalledAnswer.getResultMessage();1207 if (lastServiceCalledAnswer.getItem() != null) {1208 AppService lastServiceCalled = (AppService) lastServiceCalledAnswer.getItem();1209 tCExecution.setLastServiceCalled(lastServiceCalled);1210 /**1211 * Record the Request and Response in filesystem.1212 */1213 testCaseStepActionExecution.addFileList(recorderService.recordServiceCall(tCExecution, testCaseStepActionExecution, 0, null, lastServiceCalled));1214 }1215 return message;1216 }1217 private MessageEvent doActionRemoveDifference(TestCaseStepActionExecution testCaseStepActionExecution, String object, String property) {1218 // Filters differences from the given object pattern1219 String filteredDifferences = xmlUnitService.removeDifference(object, property);1220 // If filtered differences are null then service has returned with errors1221 if (filteredDifferences == null) {1222 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_REMOVEDIFFERENCE);1223 message.setDescription(message.getDescription().replace("%DIFFERENCE%", object));1224 message.setDescription(message.getDescription().replace("%DIFFERENCES%", property));1225 return message;1226 }1227 // Sets the property value to the new filtered one1228 for (TestCaseExecutionData data : testCaseStepActionExecution.getTestCaseExecutionDataList()) {1229 if (data.getProperty().equals(testCaseStepActionExecution.getPropertyName())) {1230 data.setValue(filteredDifferences);1231 break;1232 }1233 }1234 // Sends success1235 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_REMOVEDIFFERENCE);1236 message.setDescription(message.getDescription().replace("%DIFFERENCE%", object));1237 message.setDescription(message.getDescription().replace("%DIFFERENCES%", property));1238 return message;1239 }1240 private MessageEvent doActionCalculateProperty(TestCaseStepActionExecution testCaseStepActionExecution, String value1, String value2) {1241 MessageEvent message;1242 AnswerItem<String> answerDecode = new AnswerItem<>();1243 if (StringUtil.isNullOrEmpty(value1)) {1244 // Value1 is a mandatory parameter.1245 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_MISSINGPROPERTY);1246 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY));1247 } else {1248 try {1249 TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();1250 // Getting the Country property definition.1251 TestCaseCountryProperties tccp = null;1252 boolean propertyExistOnAnyCountry = false;1253 for (TestCaseCountryProperties object : tCExecution.getTestCaseCountryPropertyList()) {1254 if ((object.getProperty().equalsIgnoreCase(value1)) && (object.getCountry().equalsIgnoreCase(tCExecution.getCountry()))) {1255 tccp = object;1256 }1257 if ((object.getProperty().equalsIgnoreCase(value1))) {1258 propertyExistOnAnyCountry = true;1259 }1260 }1261 if (tccp == null) { // Could not find a country property inside the existing execution.1262 if (propertyExistOnAnyCountry) {1263 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NO_PROPERTY_DEFINITION);1264 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY)1265 .replace("%PROP%", value1)1266 .replace("%COUNTRY%", tCExecution.getCountry()));1267 return message;1268 } else {1269 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_PROPERTYNOTFOUND);1270 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY)1271 .replace("%PROP%", value1)1272 .replace("%COUNTRY%", tCExecution.getCountry()));1273 return message;1274 }1275 } else {1276 if (!(StringUtil.isNullOrEmpty(value2))) {1277 // If value2 is fed with something, we control here that value is a valid property name and gets its defintion.1278 tccp = null;1279 propertyExistOnAnyCountry = false;1280 for (TestCaseCountryProperties object : tCExecution.getTestCaseCountryPropertyList()) {1281 if ((object.getProperty().equalsIgnoreCase(value2)) && (object.getCountry().equalsIgnoreCase(tCExecution.getCountry()))) {1282 tccp = object;1283 }1284 if ((object.getProperty().equalsIgnoreCase(value2))) {1285 propertyExistOnAnyCountry = true;1286 }1287 }1288 if (tccp == null) { // Could not find a country property inside the existing execution.1289 if (propertyExistOnAnyCountry) {1290 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NO_PROPERTY_DEFINITION);1291 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY)1292 .replace("%PROP%", value2)1293 .replace("%COUNTRY%", tCExecution.getCountry()));1294 return message;1295 } else {1296 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_PROPERTYNOTFOUND);1297 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY)1298 .replace("%PROP%", value2)1299 .replace("%COUNTRY%", tCExecution.getCountry()));1300 return message;1301 }1302 }1303 }1304 // We calculate the property here.1305 long now = new Date().getTime();1306 TestCaseExecutionData tcExeData;1307 tcExeData = factoryTestCaseExecutionData.create(tCExecution.getId(), tccp.getProperty(), 1, tccp.getDescription(), null, tccp.getType(),1308 tccp.getRank(), tccp.getValue1(), tccp.getValue2(), null, null, now, now, now, now, new MessageEvent(MessageEventEnum.PROPERTY_PENDING),1309 tccp.getRetryNb(), tccp.getRetryPeriod(), tccp.getDatabase(), tccp.getValue1(), tccp.getValue2(), tccp.getLength(), tccp.getLength(),1310 tccp.getRowLimit(), tccp.getNature(), "", "", "", "", "", "N");1311 tcExeData.setTestCaseCountryProperties(tccp);1312 propertyService.calculateProperty(tcExeData, tCExecution, testCaseStepActionExecution, tccp, true);1313 // Property message goes to Action message.1314 message = tcExeData.getPropertyResultMessage();1315 if (message.getCodeString().equals("OK")) {1316 // If Property calculated successfully we summarize the message to a shorter version.1317 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CALCULATEPROPERTY);1318 message.setDescription(message.getDescription()1319 .replace("%PROP%", value1)1320 .replace("%VALUE%", tcExeData.getValue()));1321 if (tcExeData.getDataLibRawData() != null) {1322 message.setDescription(message.getDescription() + " %NBROWS% row(s) with %NBSUBDATA% Subdata(s) calculated."1323 .replace("%NBROWS%", String.valueOf(tcExeData.getDataLibRawData().size()))1324 .replace("%NBSUBDATA%", String.valueOf(tcExeData.getDataLibRawData().get(0).size())));1325 }1326 }1327 if (!(StringUtil.isNullOrEmpty(value2))) {1328 // If value2 is fed we force the result to value1.1329 tcExeData.setProperty(value1);1330 }1331 //saves the result1332 try {1333 testCaseExecutionDataService.save(tcExeData);1334 LOG.debug("Adding into Execution data list. Property : '" + tcExeData.getProperty() + "' Index : '" + tcExeData.getIndex() + "' Value : '" + tcExeData.getValue() + "'");1335 tCExecution.getTestCaseExecutionDataMap().put(tcExeData.getProperty(), tcExeData);1336 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.1337 for (int i = 1; i < (tcExeData.getDataLibRawData().size()); i++) {1338 now = new Date().getTime();1339 TestCaseExecutionData tcedS = factoryTestCaseExecutionData.create(tcExeData.getId(), tcExeData.getProperty(), (i + 1),1340 tcExeData.getDescription(), tcExeData.getDataLibRawData().get(i).get(""), tcExeData.getType(), tcExeData.getRank(), "", "",1341 tcExeData.getRC(), "", now, now, now, now, null, 0, 0, "", "", "", "", "", 0, "", "", "", "", "", "", "N");1342 testCaseExecutionDataService.save(tcedS);1343 }1344 }1345 } catch (CerberusException cex) {1346 LOG.error(cex.getMessage(), cex);1347 }1348 }1349 } catch (Exception ex) {1350 LOG.error(ex.toString(), ex);1351 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC).resolveDescription("DETAIL", ex.toString());1352 }1353 }1354 return message;1355 }1356 private String getElementToUse(String value1, String value2, String action, TestCaseExecution tCExecution) throws CerberusEventException {1357 if (!StringUtil.isNullOrEmpty(value1)) {1358 return value1;1359 } else if (!StringUtil.isNullOrEmpty(value2)) {1360 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 : ['" + tCExecution.getTest() + "'|'" + tCExecution.getTestCase() + "'] Property : " + value2);1361 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 : ['" + tCExecution.getTest() + "'|'" + tCExecution.getTestCase() + "'] Property : " + value2);1362 return value2;1363 }1364 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.1365 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_NO_ELEMENT_TO_PERFORM_ACTION);1366 message.setDescription(message.getDescription().replace("%ACTION%", action));1367 throw new CerberusEventException(message);1368 }1369 return null;1370 }1371 private MessageEvent waitTime(Long timeToWaitMs) {1372 MessageEvent message;1373 /**1374 * if timeToWait is null, throw CerberusException1375 */1376 if (timeToWaitMs == 0) {1377 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_INVALID_FORMAT);1378 return message;1379 }1380 try {1381 LOG.debug("TIME TO WAIT = " + timeToWaitMs);1382 Thread.sleep(timeToWaitMs);1383 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_TIME);1384 message.setDescription(message.getDescription().replace("%TIME%", String.valueOf(timeToWaitMs)));1385 return message;1386 } catch (InterruptedException exception) {1387 LOG.warn(exception.toString());1388 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_TIME_WITHWARNINGS);1389 message.setDescription(message.getDescription()1390 .replace("%TIME%", String.valueOf(timeToWaitMs))1391 .replace("%MESSAGE%", exception.toString()));1392 return message;1393 }1394 }1395 private MessageEvent doActionExecuteSQLUpdate(TestCaseExecution tCExecution, String object, String property) {1396 return sqlService.executeUpdate(tCExecution.getApplicationObj().getSystem(),1397 tCExecution.getCountry(), tCExecution.getEnvironment(), object, property);1398 }1399 private MessageEvent doActionExecuteSQLStoredProcedure(TestCaseExecution tCExecution, String object, String property) {1400 return sqlService.executeCallableStatement(tCExecution.getApplicationObj().getSystem(),1401 tCExecution.getCountry(), tCExecution.getEnvironment(), object, property);1402 }1403 private MessageEvent doActionHideKeyboard(TestCaseExecution tCExecution) {1404 // Check argument1405 if (tCExecution == null) {1406 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);1407 }1408 // Hide keyboard according to application type1409 String applicationType = tCExecution.getApplicationObj().getType();1410 if (Application.TYPE_APK.equals(applicationType)) {1411 return androidAppiumService.hideKeyboard(tCExecution.getSession());1412 }1413 if (Application.TYPE_IPA.equals(applicationType)) {1414 return iosAppiumService.hideKeyboard(tCExecution.getSession());1415 }1416 // Else we are faced with a non supported application1417 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1418 .resolveDescription("ACTION", "Hide keyboard")1419 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());1420 }1421 private MessageEvent doActionSwipe(TestCaseExecution tCExecution, String object, String property) {1422 // Check arguments1423 if (tCExecution == null || object == null) {1424 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);1425 }1426 // Create the associated swipe action to the given arguments1427 SwipeAction action = null;1428 try {1429 action = SwipeAction.fromStrings(object, property);1430 } catch (Exception e) {1431 return new MessageEvent(MessageEventEnum.ACTION_FAILED_SWIPE)1432 .resolveDescription("DIRECTION", action == null ? "Unknown" : action.getActionType().name())1433 .resolveDescription("REASON", e.getMessage());1434 }1435 // Swipe screen according to the application type1436 String applicationType = tCExecution.getApplicationObj().getType();1437 if (Application.TYPE_APK.equals(applicationType)) {1438 return androidAppiumService.swipe(tCExecution.getSession(), action);1439 }1440 if (Application.TYPE_IPA.equals(applicationType)) {1441 return iosAppiumService.swipe(tCExecution.getSession(), action);1442 }1443 // Else we are faced with a non supported application1444 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1445 .resolveDescription("ACTION", "Swipe screen")1446 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());1447 }1448 private MessageEvent doActionLongPress(TestCaseExecution tCExecution, String value1, String value2) {1449 String element;1450 try {1451 /**1452 * Get element to use String object if not empty, String property if1453 * object empty, throws Exception if both empty)1454 */1455 element = getElementToUse(value1, value2, TestCaseStepAction.ACTION_LONGPRESS, tCExecution);1456 /**1457 * Get Identifier (identifier, locator) and check it's valid1458 */1459 Integer longPressTime = 8000;1460 try {1461 longPressTime = Integer.parseInt(value2);1462 } catch (NumberFormatException e) {1463 // do nothing1464 }1465 Identifier identifier = identifierService.convertStringToIdentifier(element);1466 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {1467 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1468 return androidAppiumService.longPress(tCExecution.getSession(), identifier, longPressTime);1469 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1470 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1471 return iosAppiumService.longPress(tCExecution.getSession(), identifier, longPressTime);1472 } else {1473 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1474 .resolveDescription("ACTION", "Long Click")1475 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());1476 }1477 } catch (CerberusEventException ex) {1478 LOG.fatal("Error doing Action Click :" + ex, ex);1479 return ex.getMessageError();1480 }1481 }1482 private MessageEvent doActionClearField(TestCaseExecution tCExecution, String value1) {1483 String element;1484 try {1485 /**1486 * Check object and property are not null for GUI/APK/IPA Check1487 * property is not null for FAT Application1488 */1489 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)1490 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1491 if (value1 == null) {1492 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLEARFIELD);1493 }1494 }1495 /**1496 * Get Identifier (identifier, locator) if object not null1497 */1498 Identifier identifier = new Identifier();1499 if (value1 != null) {1500 identifier = identifierService.convertStringToIdentifier(value1);1501 }1502 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {1503 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1504 return androidAppiumService.clearField(tCExecution.getSession(), identifier);1505 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1506 identifierService.checkWebElementIdentifier(identifier.getIdentifier());1507 return iosAppiumService.clearField(tCExecution.getSession(), identifier);1508 } else {1509 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1510 .resolveDescription("ACTION", "ClearField")1511 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());1512 }1513 } catch (CerberusEventException ex) {1514 LOG.fatal("Error doing Action Type : " + ex);...
convertStringToIdentifier
Using AI Code Generation
1String identifier = identifierService.convertStringToIdentifier("My Identifier");2String identifier = identifierService.convertStringToIdentifier("My Identifier", "My Default Value");3String identifier = identifierService.convertStringToIdentifier("My Identifier", "My Default Value", "My Prefix");4String identifier = identifierService.convertStringToIdentifier("My Identifier", "My Default Value", "My Prefix", "My Suffix");5String identifier = identifierService.convertStringToIdentifier("My Identifier", "My Default Value", "My Prefix", "My Suffix", "My Separator");6String identifier = identifierService.convertStringToIdentifier("My Identifier", "My Default Value", "My Prefix", "My Suffix", "My Separator", true);7String identifier = identifierService.convertStringToIdentifier("My Identifier", "My Default Value", "My Prefix", "My Suffix", "My Separator", true, true);8String identifier = identifierService.convertStringToIdentifier("My Identifier", "My Default Value", "My Prefix", "My Suffix", "My Separator", true, true, true);9String identifier = identifierService.convertStringToIdentifier("My Identifier", "My Default Value", "My Prefix", "My Suffix", "My Separator", true, true, true, true);10String identifier = identifierService.convertStringToIdentifier("My Identifier", "My Default Value", "My Prefix", "My Suffix", "My Separator", true, true, true, true, true);
convertStringToIdentifier
Using AI Code Generation
1import org.cerberus.engine.execution.impl.IdentifierService;2import org.cerberus.util.StringUtil;3String str = "String to convert";4String convertedStr = IdentifierService.convertStringToIdentifier(str);5System.out.println(convertedStr);6String str = "String to convert";7String convertedStr = StringUtil.convertStringToIdentifier(str);8System.out.println(convertedStr);9import org.cerberus.engine.execution.impl.IdentifierService;10import org.cerberus.util.StringUtil;11String str = "String to convert";12String convertedStr = IdentifierService.convertStringToIdentifier(str);13System.out.println(convertedStr);14String str = "String to convert";15String convertedStr = StringUtil.convertStringToIdentifier(str);16System.out.println(convertedStr);17import org.cerberus.engine.execution.impl.IdentifierService;18import org.cerberus.util.StringUtil;19String str = "String to convert";20String convertedStr = IdentifierService.convertStringToIdentifier(str);21System.out.println(convertedStr);22String str = "String to convert";23String convertedStr = StringUtil.convertStringToIdentifier(str);24System.out.println(convertedStr);25import org.cerberus.engine.execution.impl.IdentifierService;26import org.cerberus.util.StringUtil;27String str = "String to convert";
convertStringToIdentifier
Using AI Code Generation
1import org.cerberus.engine.execution.impl.IdentifierService2def identifierService = new IdentifierService()3def id = identifierService.convertStringToIdentifier("Cerberus")4def id = identifierService.convertStringToIdentifier("Cerberus", true)5def id = identifierService.convertStringToIdentifier("Cerberus", false)6def id = identifierService.convertStringToIdentifier("Cerberus", true, true)7def id = identifierService.convertStringToIdentifier("Cerberus", false, true)8def id = identifierService.convertStringToIdentifier("Cerberus", false, false)9def id = identifierService.convertStringToIdentifier("Cerberus", true, false)10def id = identifierService.convertStringToIdentifier("Cerberus", true, true, true)11def id = identifierService.convertStringToIdentifier("Cerberus", true, true, false)12def id = identifierService.convertStringToIdentifier("Cerberus", true, false, true)13def id = identifierService.convertStringToIdentifier("Cerberus", true, false, false)14def id = identifierService.convertStringToIdentifier("Cerberus", false, true, true)15def id = identifierService.convertStringToIdentifier("Cerberus", false, true, false)16def id = identifierService.convertStringToIdentifier("Cerberus", false, false, true)17def id = identifierService.convertStringToIdentifier("Cerberus", false, false, false)18def id = identifierService.convertStringToIdentifier("Cerberus", true, true, true, true)
convertStringToIdentifier
Using AI Code Generation
1import org.cerberus.engine.execution.impl.IdentifierService2def identifierService = new IdentifierService()3identifierService.convertStringToIdentifier("Hello World")4import org.cerberus.engine.execution.impl.IdentifierService5def identifierService = new IdentifierService()6identifierService.convertStringToIdentifier("Hello World")7import org.cerberus.engine.execution.impl.IdentifierService8def identifierService = new IdentifierService()9identifierService.convertStringToIdentifier("Hello World")10import org.cerberus.engine.execution.impl.IdentifierService11def identifierService = new IdentifierService()12identifierService.convertStringToIdentifier("Hello World")
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!