How to use parseWebDriverException method of org.cerberus.engine.gwt.impl.ControlService class

Best Cerberus-source code snippet using org.cerberus.engine.gwt.impl.ControlService.parseWebDriverException

Source:ControlService.java Github

copy

Full Screen

...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 {1380 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCLICKABLE_NULL);1381 }1382 return mes;1383 }1384 private String caseSensitiveMessageValue(String isCaseSensitive) {1385 return (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false))1386 ? "(case sensitive)"1387 : "(case insensitive)";1388 }1389 private MessageEvent takeScreenshot(TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution, String cropValues) {1390 MessageEvent message;1391 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1392 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)1393 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)1394 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_FAT)) {1395 List<TestCaseExecutionFile> file = recorderService.recordScreenshot(tCExecution, testCaseStepActionExecution, testCaseStepActionControlExecution.getControlId(), cropValues);1396 testCaseStepActionControlExecution.addFileList(file);1397 message = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TAKESCREENSHOT);1398 return message;1399 }1400 message = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1401 message.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_TAKESCREENSHOT);1402 message.resolveDescription("APPLICATIONTYPE", testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getAppTypeEngine());1403 return message;1404 }1405 private MessageEvent getPageSource(TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution) {1406 MessageEvent message;1407 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1408 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)1409 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {1410 TestCaseExecutionFile file = recorderService.recordPageSource(tCExecution, testCaseStepActionExecution, testCaseStepActionControlExecution.getControlId());1411 if (file != null) {1412 List<TestCaseExecutionFile> fileList = new ArrayList<>();1413 fileList.add(file);1414 testCaseStepActionControlExecution.setFileList(fileList);1415 }1416 message = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GETPAGESOURCE);1417 return message;1418 }1419 message = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1420 message.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_TAKESCREENSHOT);1421 message.resolveDescription("APPLICATIONTYPE", testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getAppTypeEngine());1422 return message;1423 }1424 /**1425 * @param exception the exception need to be parsed by Cerberus1426 * @return A new Event Message with selenium related description1427 * @author memiks1428 */1429 private MessageEvent parseWebDriverException(WebDriverException exception) {1430 MessageEvent mes;1431 LOG.error(exception.toString(), exception);1432 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_SELENIUM_CONNECTIVITY);1433 mes.resolveDescription("ERROR", exception.getMessage().split("\n")[0]);1434 return mes;1435 }1436}...

Full Screen

Full Screen

Source:ConditionService.java Github

copy

Full Screen

...295 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));296 }297 } catch (WebDriverException exception) {298 condition_result = false;299 mes = parseWebDriverException(exception);300 }301 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_SRV)) {302 if (tCExecution.getLastServiceCalled() != null) {303 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();304 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {305 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:306 if (LOG.isDebugEnabled()) {307 LOG.debug("Checking if Element Present - XML");308 }309 if (xmlUnitService.isElementPresent(responseBody, conditionValue1)) {310 condition_result = true;311 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);312 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));313 } else {314 condition_result = false;315 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTPRESENT);316 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));317 }318 break;319 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:320 if (LOG.isDebugEnabled()) {321 LOG.debug("Checking if Element Present - JSON");322 }323 try {324 if (jsonService.getFromJson(responseBody, null, conditionValue1) != null) {325 condition_result = true;326 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);327 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));328 } else {329 condition_result = false;330 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTPRESENT);331 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));332 }333 } catch (Exception ex) {334 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_GENERIC);335 mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));336 }337 break;338 default:339 condition_result = false;340 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOTSUPPORTED_FOR_MESSAGETYPE);341 mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));342 mes.setDescription(mes.getDescription().replace("%CONDITION%", conditionOper));343 }344 } else {345 condition_result = false;346 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOOBJECTINMEMORY);347 }348 } else {349 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOTSUPPORTED_FOR_APPLICATION);350 mes.setDescription(mes.getDescription().replace("%CONDITION%", conditionOper));351 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));352 }353 }354 ans.setResultMessage(mes);355 return ans;356 }357 private AnswerItem<Boolean> evaluateCondition_ifElementNotPresent(String conditionOper, String conditionValue1, TestCaseExecution tCExecution) {358 if (LOG.isDebugEnabled()) {359 LOG.debug("Checking if Element is Not Present");360 }361 AnswerItem<Boolean> ans = new AnswerItem<>();362 MessageEvent mes;363 if (tCExecution.getManualExecution().equals("Y")) {364 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_NOTPOSSIBLE);365 } else if (StringUtil.isNullOrEmpty(conditionValue1)) {366 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFELEMENTNOTPRESENT_MISSINGPARAMETER);367 mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));368 } else {369 boolean condition_result = false;370 Identifier identifier = identifierService.convertStringToIdentifier(conditionValue1);371 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)372 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)373 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {374 try {375 if (identifier.getIdentifier().equals("picture")) {376 mes = sikuliService.doSikuliVerifyElementNotPresent(tCExecution.getSession(), identifier.getLocator());377 if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT))) {378 condition_result = true;379 } else {380 condition_result = false;381 }382 } else if (!this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {383 condition_result = true;384 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTNOTPRESENT);385 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));386 } else {387 condition_result = false;388 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTPRESENT);389 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));390 }391 } catch (WebDriverException exception) {392 condition_result = false;393 mes = parseWebDriverException(exception);394 }395 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_SRV)) {396 if (tCExecution.getLastServiceCalled() != null) {397 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();398 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {399 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:400 if (!xmlUnitService.isElementPresent(responseBody, conditionValue1)) {401 condition_result = true;402 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTNOTPRESENT);403 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));404 } else {405 condition_result = false;406 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTPRESENT);407 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));408 }409 break;410 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:411 try {412 if (jsonService.getFromJson(responseBody, null, conditionValue1) == null) {413 condition_result = true;414 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTNOTPRESENT);415 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));416 } else {417 condition_result = false;418 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTPRESENT);419 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));420 }421 } catch (Exception ex) {422 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_GENERIC);423 mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));424 }425 break;426 default:427 condition_result = false;428 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOTSUPPORTED_FOR_MESSAGETYPE);429 mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));430 mes.setDescription(mes.getDescription().replace("%CONDITION%", conditionOper));431 }432 } else {433 condition_result = false;434 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOOBJECTINMEMORY);435 }436 } else {437 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOTSUPPORTED_FOR_APPLICATION);438 mes.setDescription(mes.getDescription().replace("%CONDITION%", conditionOper));439 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));440 }441 }442 ans.setResultMessage(mes);443 return ans;444 }445 private AnswerItem<Boolean> evaluateCondition_ifStringEqual(String conditionOper, String conditionValue1, String conditionValue2, String isCaseSensitive) {446 if (LOG.isDebugEnabled()) {447 LOG.debug("Checking if String Equal");448 }449 AnswerItem<Boolean> ans = new AnswerItem<>();450 MessageEvent mes;451 isCaseSensitive = defaultIsSensitiveValue(isCaseSensitive);452 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? conditionValue1.equals(conditionValue2) : conditionValue1.equalsIgnoreCase(conditionValue2)) {453 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_STRINGEQUAL);454 mes.setDescription(mes.getDescription()455 .replace("%COND%", conditionOper)456 .replace("%STR1%", conditionValue1)457 .replace("%STR2%", conditionValue2)458 .replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive))459 );460 } else {461 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_STRINGEQUAL);462 mes.setDescription(mes.getDescription()463 .replace("%COND%", conditionOper)464 .replace("%STR1%", conditionValue1)465 .replace("%STR2%", conditionValue2)466 .replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive))467 );468 }469 ans.setResultMessage(mes);470 return ans;471 }472 private AnswerItem<Boolean> evaluateCondition_ifStringDifferent(String conditionOper, String conditionValue1, String conditionValue2, String isCaseSensitive) {473 if (LOG.isDebugEnabled()) {474 LOG.debug("Checking if String Different");475 }476 AnswerItem<Boolean> ans = new AnswerItem<>();477 MessageEvent mes;478 isCaseSensitive = defaultIsSensitiveValue(isCaseSensitive);479 boolean execute_Action = true;480 if (!(ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? conditionValue1.equals(conditionValue2) : conditionValue1.equalsIgnoreCase(conditionValue2))) {481 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_STRINGDIFFERENT);482 mes.setDescription(mes.getDescription()483 .replace("%COND%", conditionOper)484 .replace("%STR1%", conditionValue1)485 .replace("%STR2%", conditionValue2)486 .replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive))487 );488 } else {489 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_STRINGDIFFERENT);490 mes.setDescription(mes.getDescription()491 .replace("%COND%", conditionOper)492 .replace("%STR1%", conditionValue1)493 .replace("%STR2%", conditionValue2)494 .replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive))495 );496 }497 ans.setItem(execute_Action);498 ans.setResultMessage(mes);499 return ans;500 }501 private AnswerItem<Boolean> evaluateCondition_ifStringGreater(String conditionOper, String conditionValue1, String conditionValue2) {502 if (LOG.isDebugEnabled()) {503 LOG.debug("Checking if String Greater");504 }505 AnswerItem<Boolean> ans = new AnswerItem<>();506 MessageEvent mes;507 boolean execute_Action = true;508 if ((conditionValue1.compareToIgnoreCase(conditionValue2) > 0)) {509 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_STRINGGREATER);510 mes.setDescription(mes.getDescription()511 .replace("%COND%", conditionOper)512 .replace("%STR1%", conditionValue1).replace("%STR2%", conditionValue2)513 );514 } else {515 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_STRINGGREATER);516 mes.setDescription(mes.getDescription()517 .replace("%COND%", conditionOper)518 .replace("%STR1%", conditionValue1).replace("%STR2%", conditionValue2)519 );520 }521 ans.setItem(execute_Action);522 ans.setResultMessage(mes);523 return ans;524 }525 private AnswerItem<Boolean> evaluateCondition_ifStringMinor(String conditionOper, String conditionValue1, String conditionValue2) {526 if (LOG.isDebugEnabled()) {527 LOG.debug("Checking if String Minor");528 }529 AnswerItem<Boolean> ans = new AnswerItem<>();530 MessageEvent mes;531 boolean execute_Action = true;532 if ((conditionValue1.compareToIgnoreCase(conditionValue2) < 0)) {533 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_STRINGMINOR);534 mes.setDescription(mes.getDescription()535 .replace("%COND%", conditionOper)536 .replace("%STR1%", conditionValue1).replace("%STR2%", conditionValue2)537 );538 } else {539 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_STRINGMINOR);540 mes.setDescription(mes.getDescription()541 .replace("%COND%", conditionOper)542 .replace("%STR1%", conditionValue1).replace("%STR2%", conditionValue2)543 );544 }545 ans.setItem(execute_Action);546 ans.setResultMessage(mes);547 return ans;548 }549 private AnswerItem<Boolean> evaluateCondition_ifStringContains(String conditionOper, String conditionValue1, String conditionValue2, String isCaseSensitive) {550 if (LOG.isDebugEnabled()) {551 LOG.debug("Checking if String Contains");552 }553 AnswerItem<Boolean> ans = new AnswerItem<>();554 MessageEvent mes;555 isCaseSensitive = defaultIsSensitiveValue(isCaseSensitive);556 boolean execute_Action = true;557 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? conditionValue1.contains(conditionValue2) : conditionValue1.toLowerCase().contains(conditionValue2.toLowerCase())) {558 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_STRINGCONTAINS);559 mes.setDescription(mes.getDescription()560 .replace("%COND%", conditionOper)561 .replace("%STR1%", conditionValue1)562 .replace("%STR2%", conditionValue2)563 .replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive))564 );565// execute_Action = true;566 } else {567 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_STRINGCONTAINS);568 mes.setDescription(mes.getDescription()569 .replace("%COND%", conditionOper)570 .replace("%STR1%", conditionValue1)571 .replace("%STR2%", conditionValue2)572 .replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive))573 );574// execute_Action = false;575 }576 ans.setItem(execute_Action);577 ans.setResultMessage(mes);578 return ans;579 }580 private AnswerItem<Boolean> evaluateCondition_ifStringNotContains(String conditionOper, String conditionValue1, String conditionValue2, String isCaseSensitive) {581 if (LOG.isDebugEnabled()) {582 LOG.debug("Checking if String Does Not Contains");583 }584 AnswerItem<Boolean> ans = new AnswerItem<>();585 MessageEvent mes;586 isCaseSensitive = defaultIsSensitiveValue(isCaseSensitive);587 boolean execute_Action = true;588 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? conditionValue1.contains(conditionValue2) : conditionValue1.toLowerCase().contains(conditionValue2.toLowerCase())) {589 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_STRINGCONTAINS);590 mes.setDescription(mes.getDescription()591 .replace("%COND%", conditionOper)592 .replace("%STR1%", conditionValue1)593 .replace("%STR2%", conditionValue2)594 .replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive))595 );596// execute_Action = true;597 } else {598 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_STRINGCONTAINS);599 mes.setDescription(mes.getDescription()600 .replace("%COND%", conditionOper)601 .replace("%STR1%", conditionValue1)602 .replace("%STR2%", conditionValue2)603 .replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive))604 );605// execute_Action = false;606 }607 ans.setItem(execute_Action);608 ans.setResultMessage(mes);609 return ans;610 }611 private AnswerItem<Boolean> evaluateCondition_ifNumericXXX(String conditionOper, String conditionValue1, String conditionValue2) {612 if (LOG.isDebugEnabled()) {613 LOG.debug("Checking if Numeric Equals");614 }615 AnswerItem<Boolean> ans = new AnswerItem<>();616 MessageEvent mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_PENDING);617 // We first prepare the string for nueric conversion to replace , by .618 String newConditionValue1 = StringUtil.prepareToNumeric(conditionValue1);619 String newConditionValue2 = StringUtil.prepareToNumeric(conditionValue2);620 // We try to convert the strings value1 to numeric.621 Double value1 = 0.0;622 try {623 value1 = Double.valueOf(newConditionValue1);624 } catch (NumberFormatException nfe) {625 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFNUMERIC_GENERICCONVERSIONERROR);626 mes.setDescription(mes.getDescription()627 .replace("%COND%", conditionOper)628 .replace("%STRINGVALUE%", newConditionValue1));629 ans.setItem(false);630 ans.setResultMessage(mes);631 return ans;632 }633 // We try to convert the strings value2 to numeric.634 Double value2 = 0.0;635 try {636 value2 = Double.valueOf(newConditionValue2);637 } catch (NumberFormatException nfe) {638 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFNUMERIC_GENERICCONVERSIONERROR);639 mes.setDescription(mes.getDescription()640 .replace("%COND%", conditionOper)641 .replace("%STRINGVALUE%", newConditionValue2));642 ans.setItem(false);643 ans.setResultMessage(mes);644 return ans;645 }646 // Now that both values are converted to double we ceck the operator here.647 boolean execute_Action = true;648 switch (conditionOper) {649 case TestCaseStepAction.CONDITIONOPER_IFNUMERICEQUAL:650 if (Objects.equals(value1, value2)) {651 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_NUMERICEQUAL);652 mes.setDescription(mes.getDescription()653 .replace("%COND%", conditionOper)654 .replace("%STR1%", value1.toString()).replace("%STR2%", value2.toString())655 );656 } else {657 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_NUMERICEQUAL);658 mes.setDescription(mes.getDescription()659 .replace("%COND%", conditionOper)660 .replace("%STR1%", value1.toString()).replace("%STR2%", value2.toString())661 );662 }663 break;664 case TestCaseStepAction.CONDITIONOPER_IFNUMERICDIFFERENT:665 if (!(Objects.equals(value1, value2))) {666 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_NUMERICDIFFERENT);667 mes.setDescription(mes.getDescription()668 .replace("%COND%", conditionOper)669 .replace("%STR1%", value1.toString()).replace("%STR2%", value2.toString())670 );671 } else {672 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_NUMERICDIFFERENT);673 mes.setDescription(mes.getDescription()674 .replace("%COND%", conditionOper)675 .replace("%STR1%", value1.toString()).replace("%STR2%", value2.toString())676 );677 }678 break;679 case TestCaseStepAction.CONDITIONOPER_IFNUMERICGREATER:680 if (value1 > value2) {681 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_NUMERICGREATER);682 mes.setDescription(mes.getDescription()683 .replace("%COND%", conditionOper)684 .replace("%STR1%", value1.toString()).replace("%STR2%", value2.toString())685 );686 } else {687 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_NUMERICGREATER);688 mes.setDescription(mes.getDescription()689 .replace("%COND%", conditionOper)690 .replace("%STR1%", value1.toString()).replace("%STR2%", value2.toString())691 );692 }693 break;694 case TestCaseStepAction.CONDITIONOPER_IFNUMERICGREATEROREQUAL:695 if (value1 >= value2) {696 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_NUMERICGREATEROREQUAL);697 mes.setDescription(mes.getDescription()698 .replace("%COND%", conditionOper)699 .replace("%STR1%", value1.toString()).replace("%STR2%", value2.toString())700 );701 } else {702 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_NUMERICGREATEROREQUAL);703 mes.setDescription(mes.getDescription()704 .replace("%COND%", conditionOper)705 .replace("%STR1%", value1.toString()).replace("%STR2%", value2.toString())706 );707 }708 break;709 case TestCaseStepAction.CONDITIONOPER_IFNUMERICMINOR:710 if (value1 < value2) {711 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_NUMERICMINOR);712 mes.setDescription(mes.getDescription()713 .replace("%COND%", conditionOper)714 .replace("%STR1%", value1.toString()).replace("%STR2%", value2.toString())715 );716 } else {717 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_NUMERICMINOR);718 mes.setDescription(mes.getDescription()719 .replace("%COND%", conditionOper)720 .replace("%STR1%", value1.toString()).replace("%STR2%", value2.toString())721 );722 }723 break;724 case TestCaseStepAction.CONDITIONOPER_IFNUMERICMINOROREQUAL:725 if (value1 <= value2) {726 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_NUMERICMINOROREQUAL);727 mes.setDescription(mes.getDescription()728 .replace("%COND%", conditionOper)729 .replace("%STR1%", value1.toString()).replace("%STR2%", value2.toString())730 );731 } else {732 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_NUMERICMINOROREQUAL);733 mes.setDescription(mes.getDescription()734 .replace("%COND%", conditionOper)735 .replace("%STR1%", value1.toString()).replace("%STR2%", value2.toString())736 );737 }738 break;739 }740 ans.setItem(execute_Action);741 ans.setResultMessage(mes);742 return ans;743 }744 private String caseSensitiveMessageValue(String isCaseSensitive) {745 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {746 return "case sensitive";747 } else {748 return "case insensitive";749 }750 }751 /**752 * @author memiks753 * @param exception the exception need to be parsed by Cerberus754 * @return A new Event Message with selenium related description755 */756 private MessageEvent parseWebDriverException(WebDriverException exception) {757 MessageEvent mes;758 LOG.fatal(exception.toString());759 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_SELENIUM_CONNECTIVITY);760 mes.setDescription(mes.getDescription().replace("%ERROR%", exception.getMessage().split("\n")[0]));761 return mes;762 }763 private String defaultIsSensitiveValue(String isCaseSensitive) {764 if (StringUtil.isNullOrEmpty(isCaseSensitive)) {765 isCaseSensitive = "N";766 }767 return isCaseSensitive;768 }769}...

Full Screen

Full Screen

parseWebDriverException

Using AI Code Generation

copy

Full Screen

1package org.cerberus.engine.gwt.impl;2import org.apache.log4j.Logger;3import org.cerberus.engine.entity.MessageEvent;4import org.cerberus.engine.entity.MessageGeneral;5import org.cerberus.engine.entity.MessageGeneralEnum;6import org.openqa.selenium.WebDriverException;7public class ControlService {8 private static final Logger LOG = Logger.getLogger(ControlService.class);9 public MessageEvent parseWebDriverException(WebDriverException exception) {10 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WEBDRIVER);11 message.setDescription(message.getDescription().replace("%ERROR%", exception.getMessage()));12 LOG.debug(message.getDescription());13 return message;14 }15}16package org.cerberus.engine.gwt.impl;17import org.cerberus.engine.entity.MessageEvent;18import org.cerberus.engine.entity.MessageGeneral;19import org.cerberus.engine.entity.MessageGeneralEnum;20import org.openqa.selenium.WebDriverException;21public class ControlService {22 private static final Logger LOG = Logger.getLogger(ControlService.class);23 public MessageEvent parseWebDriverException(WebDriverException exception) {24 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WEBDRIVER);25 message.setDescription(message.getDescription().replace("%ERROR%", exception.getMessage()));26 LOG.debug(message.getDescription());27 return message;28 }29}30package org.cerberus.engine.gwt.impl;31import org.cerberus.engine.entity.MessageEvent;32import org.cerberus.engine.entity.MessageGeneral;33import org.cerberus.engine.entity.MessageGeneralEnum;34import org.openqa.selenium.WebDriverException;35public class ControlService {36 private static final Logger LOG = Logger.getLogger(ControlService.class);37 public MessageEvent parseWebDriverException(WebDriverException exception) {38 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WEBDRIVER);39 message.setDescription(message.getDescription().replace("%ERROR%", exception.getMessage()));40 LOG.debug(message.getDescription());41 return message;42 }43}44package org.cerberus.engine.gwt.impl;45import org.cerberus.engine.entity.MessageEvent;46import org.cerberus.engine.entity.MessageGeneral;47import org

Full Screen

Full Screen

parseWebDriverException

Using AI Code Generation

copy

Full Screen

1package com.cerberus;2import java.io.IOException;3import java.net.MalformedURLException;4import java.net.URL;5import java.util.HashMap;6import java.util.Map;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.remote.DesiredCapabilities;9import org.openqa.selenium.remote.RemoteWebDriver;10public class parseWebDriverException {11 public static void main(String[] args) throws MalformedURLException, IOException {12 DesiredCapabilities capability = DesiredCapabilities.firefox();13 driver.quit();14 }15}

Full Screen

Full Screen

parseWebDriverException

Using AI Code Generation

copy

Full Screen

1package com.cerberus;2import org.cerberus.engine.gwt.impl.ControlService;3public class ParseWebDriverException {4 public static void main(String[] args) {5 ControlService controlService = new ControlService();6 System.out.println(controlService.parseWebDriverException(exceptionMessage));7 }8}9package com.cerberus;10import org.cerberus.engine.gwt.impl.ControlService;11public class ParseWebDriverException {12 public static void main(String[] args) {13 ControlService controlService = new ControlService();14 System.out.println(controlService.parseWebDriverException(exceptionMessage));15 }16}17package com.cerberus;18import org.cerberus.engine.gwt.impl.ControlService;19public class ParseWebDriverException {20 public static void main(String[] args) {21 ControlService controlService = new ControlService();22 System.out.println(controlService.parseWebDriverException(exceptionMessage));23 }24}25package com.cerberus;26import org.cerberus.engine.gwt.impl.ControlService;27public class ParseWebDriverException {28 public static void main(String[] args) {29 ControlService controlService = new ControlService();30 System.out.println(controlService.parseWebDriverException(exceptionMessage));31 }32}33package com.cerberus;34import org.c

Full Screen

Full Screen

parseWebDriverException

Using AI Code Generation

copy

Full Screen

1package org.cerberus.engine.gwt.impl;2import org.cerberus.engine.gwt.IControlService;3import org.cerberus.exception.CerberusException;4import org.cerberus.util.StringUtil;5import org.openqa.selenium.WebDriverException;6public class ControlService implements IControlService {7 public void parseWebDriverException(WebDriverException exception, String message) throws CerberusException {8 String exceptionMessage = exception.getMessage();9 if (exceptionMessage.contains("Element is not clickable at point")) {10 throw new CerberusException(message + " : " + StringUtil.getExceptionMessage(exception));11 }12 }13}14package org.cerberus.engine.gwt.impl;15import org.cerberus.engine.gwt.IControlService;16import org.cerberus.exception.CerberusException;17import org.cerberus.util.StringUtil;18import org.openqa.selenium.WebDriverException;19public class ControlService implements IControlService {20 public void parseWebDriverException(WebDriverException exception, String message) throws CerberusException {21 String exceptionMessage = exception.getMessage();22 if (exceptionMessage.contains("Element is not clickable at point")) {23 throw new CerberusException(message + " : " + StringUtil.getExceptionMessage(exception));24 }25 }26}27package org.cerberus.engine.gwt.impl;28import org.cerberus.engine.gwt.IControlService;29import org.cerberus.exception.CerberusException;30import org.cerberus.util.StringUtil;31import org.openqa.selenium.WebDriverException;32public class ControlService implements IControlService {33 public void parseWebDriverException(WebDriverException exception, String message) throws CerberusException {34 String exceptionMessage = exception.getMessage();35 if (exceptionMessage.contains("Element is not clickable at point")) {36 throw new CerberusException(message + " : " + StringUtil.getExceptionMessage(exception));37 }38 }39}

Full Screen

Full Screen

parseWebDriverException

Using AI Code Generation

copy

Full Screen

1package com.cerberus;2import org.cerberus.engine.gwt.impl.ControlService;3import org.openqa.selenium.WebDriverException;4public class ParseWebDriverException {5 public static void main(String[] args) {6 ControlService controlService = new ControlService();7 WebDriverException exception = new WebDriverException("WebDriverException");8 String message = controlService.parseWebDriverException(exception);9 System.out.println(message);10 }11}

Full Screen

Full Screen

parseWebDriverException

Using AI Code Generation

copy

Full Screen

1ControlService controlService = new ControlService();2String errorMessage = controlService.parseWebDriverException(ex);3ControlService controlService = new ControlService();4String errorMessage = controlService.parseWebDriverException(ex);5ControlService controlService = new ControlService();6String errorMessage = controlService.parseWebDriverException(ex);7ControlService controlService = new ControlService();8String errorMessage = controlService.parseWebDriverException(ex);9ControlService controlService = new ControlService();10String errorMessage = controlService.parseWebDriverException(ex);11ControlService controlService = new ControlService();12String errorMessage = controlService.parseWebDriverException(ex);13ControlService controlService = new ControlService();14String errorMessage = controlService.parseWebDriverException(ex);15ControlService controlService = new ControlService();16String errorMessage = controlService.parseWebDriverException(ex);17ControlService controlService = new ControlService();18String errorMessage = controlService.parseWebDriverException(ex);

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