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

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

Source:ControlService.java Github

copy

Full Screen

...950 mes = verifyElementTextContainsCaseSensitiveCheck(actual, expected, isCaseSensitive);951 break;952 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTARRAYCONTAINS:953 //We use verifyStringArrayContains because it's the same behaviour. Difference is that here we retrieve array using json path or xpath954 mes = this.verifyElementTextArrayContains(actual, expected, isCaseSensitive);955 break;956 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICARRAYCONTAINS:957 //We use verifyStringArrayContains because it's the same behaviour. Difference is that here we retrieve array using json path or xpath958 mes = this.verifyElementNumericArrayContains(actual, expected);959 break;960 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:961 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:962 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:963 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:964 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:965 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:966 double value1;967 try {968 value1 = Double.parseDouble(actual);969 } catch (NumberFormatException nfe) {970 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);971 mes.resolveDescription("COND", control);972 mes.resolveDescription("STRINGVALUE", actual);973 return mes;974 }975 // We try to convert the strings value2 to numeric.976 double value2;977 try {978 value2 = Double.parseDouble(expected);979 } catch (NumberFormatException nfe) {980 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);981 mes.resolveDescription("COND", control);982 mes.resolveDescription("STRINGVALUE", expected);983 return mes;984 }985 mes = checkNumericVerifyElement(control, value1, value2);986 break;987 }988 mes.resolveDescription("ELEMENT", path);989 mes.resolveDescription("ELEMENTVALUE", actual);990 mes.resolveDescription("VALUE", expected);991 mes.resolveDescription("CASESENSITIVE", caseSensitiveMessageValue(isCaseSensitive));992 return mes;993 }994 private MessageEvent verifyElementTextEqualCaseSensitiveCheck(String actual, String expected, String isCaseSensitive) {995 MessageEvent mes;996 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {997 mes = actual.equals(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTEQUAL) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTEQUAL);998 } else {999 mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTEQUAL) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTEQUAL);1000 }1001 return mes;1002 }1003 private MessageEvent verifyElementTextDifferentCaseSensitiveCheck(String actual, String expected, String isCaseSensitive) {1004 MessageEvent mes;1005 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {1006 mes = actual.equals(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTDIFFERENT);1007 } else {1008 mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTDIFFERENT);1009 }1010 return mes;1011 }1012 private MessageEvent verifyElementTextContainsCaseSensitiveCheck(String text, String textToSearch, String isCaseSensitive) {1013 MessageEvent mes;1014 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {1015 mes = text.contains(textToSearch) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTCONTAINS) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTCONTAINS);1016 } else {1017 mes = text.toLowerCase().contains(textToSearch.toLowerCase()) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTCONTAINS) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTCONTAINS);1018 }1019 return mes;1020 }1021 private MessageEvent checkNumericVerifyElement(String control, Double actual, Double expected) {1022 switch (control) {1023 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:1024 return actual.equals(expected)1025 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICEQUAL)1026 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICEQUAL);1027 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:1028 return !actual.equals(expected)1029 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICDIFFERENT)1030 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICDIFFERENT);1031 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:1032 return actual > expected1033 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICGREATER)1034 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICGREATER);1035 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:1036 return actual >= expected1037 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICGREATEROREQUAL)1038 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICGREATEROREQUAL);1039 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:1040 return actual < expected1041 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICMINOR)1042 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICMINOR);1043 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:1044 return actual <= expected1045 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICMINOROREQUAL)1046 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICMINOROREQUAL);1047 default:1048 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1049 return mes.resolveDescription("CONTROL", "checkNumericVerifyElement-" + control);1050 }1051 }1052 private MessageEvent verifyElementTextMatchRegex(TestCaseExecution tCExecution, String path, String regex) {1053 LOG.debug("Control: VerifyElementTextMatchRegex on: {} element against value: {}", path, regex);1054 MessageEvent mes;1055 String pathContent;1056 try {1057 Identifier identifier = identifierService.convertStringToIdentifier(path);1058 String applicationType = tCExecution.getAppTypeEngine();1059 // Get value from the path element according to the application type1060 if (Application.TYPE_GUI.equalsIgnoreCase(applicationType)1061 || Application.TYPE_APK.equalsIgnoreCase(applicationType)1062 || Application.TYPE_IPA.equalsIgnoreCase(applicationType)) {1063 pathContent = this.webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);1064 } else if (Application.TYPE_SRV.equalsIgnoreCase(applicationType)) {1065 if (tCExecution.getLastServiceCalled() != null) {1066 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();1067 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {1068 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:1069 if (!xmlUnitService.isElementPresent(responseBody, path)) {1070 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);1071 mes.resolveDescription("ELEMENT", path);1072 return mes;1073 }1074 String newPath = StringUtil.addSuffixIfNotAlready(path, "/text()");1075 pathContent = xmlUnitService.getFromXml(responseBody, newPath);1076 break;1077 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:1078 try {1079 pathContent = jsonService.getFromJson(responseBody, null, path);1080 } catch (Exception ex) {1081 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);1082 mes.resolveDescription("ERROR", ex.toString());1083 return mes;1084 }1085 break;1086 default:1087 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);1088 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());1089 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTMATCHREGEX);1090 return mes;1091 }1092 // TODO Give the actual element found into the description.1093 } else {1094 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);1095 return mes;1096 }1097 } else {1098 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1099 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTMATCHREGEX);1100 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1101 return mes;1102 }1103 LOG.debug("Control: VerifyElementMatchRegex element: {} has value: {}", path, StringUtil.sanitize(pathContent));1104 if (path != null && pathContent != null) {1105 try {1106 Pattern pattern = Pattern.compile(regex);1107 Matcher matcher = pattern.matcher(pathContent);1108 if (matcher.find()) {1109 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_REGEXINELEMENT);1110 } else {1111 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT);1112 }1113 mes.resolveDescription("STRING1", path);1114 mes.resolveDescription("STRING2", StringUtil.sanitize(pathContent));1115 mes.resolveDescription("STRING3", regex);1116 } catch (PatternSyntaxException e) {1117 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_INVALIDPATTERN);1118 mes.resolveDescription("PATTERN", regex);1119 mes.resolveDescription("ERROR", e.getMessage());1120 }1121 } else if (pathContent != null) {1122 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NULL);1123 } else {1124 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NO_SUCH_ELEMENT);1125 mes.resolveDescription("ELEMENT", path);1126 }1127 } catch (NoSuchElementException exception) {1128 LOG.debug(exception.toString());1129 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NO_SUCH_ELEMENT);1130 mes.resolveDescription("ELEMENT", path);1131 } catch (WebDriverException exception) {1132 return parseWebDriverException(exception);1133 }1134 return mes;1135 }1136 private MessageEvent verifyStringArrayContains(String array, String valueToSearch, String isCaseSensitive) {1137 MessageEvent mes;1138 try {1139 List<String> strings = StringUtil.convertStringToStringArray(array);1140 //When user choose case sensitive option1141 boolean isContained = ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)1142 ? strings.stream().anyMatch(valueToSearch::equals)1143 : strings.stream().anyMatch(valueToSearch::equalsIgnoreCase);1144 mes = isContained1145 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_STRINGARRAYCONTAINS)1146 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_STRINGARRAYCONTAINS);1147 mes.resolveDescription("ELEMENT", array);1148 mes.resolveDescription("VALUE", valueToSearch);1149 mes.resolveDescription("CASESENSITIVE", caseSensitiveMessageValue(isCaseSensitive));1150 } catch (JsonProcessingException exception) {1151 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);1152 mes.resolveDescription("ERROR", "Incorrect array structure.");1153 }1154 return mes;1155 }1156 private MessageEvent verifyNumericArrayContains(String array, String numberToSearch) {1157 MessageEvent mes;1158 try {1159 List<Double> doubles = StringUtil.convertStringToDoubleArray(array);1160 Double number = Double.parseDouble(numberToSearch);1161 mes = doubles.stream().anyMatch(number::equals)1162 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NUMERICARRAYCONTAINS)1163 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_NUMERICARRAYCONTAINS);1164 mes.resolveDescription("ELEMENT", array);1165 mes.resolveDescription("VALUE", numberToSearch);1166 } catch (JsonProcessingException exception) {1167 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);1168 mes.resolveDescription("ERROR", "Incorrect array structure.");1169 } catch (NumberFormatException exception) {1170 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC)1171 .resolveDescription("ERROR", "Value to search must be a number and the array must be an array of numbers.");1172 }1173 return mes;1174 }1175 private MessageEvent verifyElementTextArrayContains(String array, String valueToSearch, String isCaseSensitive) {1176 //We use verifyStringArrayContains because it's the same behaviour. The difference is that here we have an array retrieved using json path or xpath.1177 MessageEvent mes = this.verifyStringArrayContains(array, valueToSearch, isCaseSensitive);1178 //Change the message event to adapt to this control.1179 if (!mes.getSource().equals(MessageEventEnum.CONTROL_FAILED_GENERIC)) {1180 if (mes.getCodeString().equals("OK")) {1181 mes.setDescription(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTARRAYCONTAINS.getDescription());1182 } else {1183 mes.setDescription(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTARRAYCONTAINS.getDescription());1184 }1185 }1186 return mes;1187 }1188 private MessageEvent verifyElementNumericArrayContains(String array, String numberToSearch) {1189 //We use verifyStringArrayContains because it's the same behaviour. The difference is that here we have an array retrieved using json path or xpath....

Full Screen

Full Screen

verifyElementTextArrayContains

Using AI Code Generation

copy

Full Screen

1public void test() throws Exception {2}3public void test() throws Exception {4}5public void test() throws Exception {6}7public void test() throws Exception {8}9public void test() throws Exception {10}11public void test() throws Exception {

Full Screen

Full Screen

verifyElementTextArrayContains

Using AI Code Generation

copy

Full Screen

1String[] expectedTexts = new String[] {"text 1", "text 2"};2String[] actualTexts = new String[] {"text 1", "text 2", "text 3"};3ControlService controlService = new ControlService();4boolean result = controlService.verifyElementTextArrayContains(expectedTexts, actualTexts);5String[] expectedTexts = new String[] {"text 1", "text 2"};6String[] actualTexts = new String[] {"text 1", "text 3"};7ControlService controlService = new ControlService();8boolean result = controlService.verifyElementTextArrayContains(expectedTexts, actualTexts);9public boolean verifyElementTextArrayContains(String[] expectedTexts, String[] actualTexts) {10 boolean result = true;11 for (String expectedText : expectedTexts) {12 boolean found = false;13 for (String actualText : actualTexts) {14 if (expectedText.equals(actualText)) {15 found = true;16 break;17 }18 }19 if (!found) {20 result = false;21 break;22 }23 }24 return result;25}

Full Screen

Full Screen

verifyElementTextArrayContains

Using AI Code Generation

copy

Full Screen

1verifyElementTextArrayContains("example", "a,b", ",", "example contains a and b")2verifyElementTextArrayContains("example", "a,b,c", ",", "example contains a, b and c")3verifyElementTextArrayContains("example", "a,b,c,d", ",", "example contains a, b, c and d")4verifyElementTextArrayContains("example", "a,b,c,d,e", ",", "example contains a, b, c, d and e")5verifyElementTextArrayContains("example", "a,b,c,d,e,f", ",", "example contains a, b, c, d, e and f")6verifyElementTextArrayContains("example", "a,b,c,d,e,f,g", ",", "example contains a, b, c, d, e, f and g")7verifyElementTextArrayContains("example", "a,b,c,d,e,f,g,h", ",", "example contains a, b, c, d, e, f, g and h")

Full Screen

Full Screen

verifyElementTextArrayContains

Using AI Code Generation

copy

Full Screen

1String[] array = {"value1", "value2"};2String[] array2 = {"value1", "value2", "value3"};3String[] array3 = {"value1", "value2", "value3", "value4"};4String[] array4 = {"value1", "value2", "value3", "value4", "value5"};5String[] array5 = {"value1", "value2", "value3", "value4", "value5", "value6"};6String[] array6 = {"value1", "value2", "value3", "value4", "value5", "value6", "value7"};7String[] array7 = {"value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8"};8String[] array8 = {"value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9"};9String[] array9 = {"value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9", "value10"};10verifyElementTextArrayContains("id=elementId", "value1,value2", ",", "message");11verifyElementTextArrayContains("id=elementId", "value1,value2,value3", ",", "message");12verifyElementTextArrayContains("id=elementId", "value1,value2,value3,value4", ",", "message");13verifyElementTextArrayContains("id=elementId", "value1,value2,value3,value4,value5", ",", "message");14verifyElementTextArrayContains("id=elementId", "value1,value2,value3,value4,value5,value6", ",", "message");15verifyElementTextArrayContains("id=elementId", "value1,value2,value3,value4,value5,value6,value7", ",", "message");16verifyElementTextArrayContains("id=elementId", "value1

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