Best Cerberus-source code snippet using org.cerberus.engine.execution.impl.ConditionService.evaluateCondition_ifElementNotPresent
Source:ConditionService.java
...85 ans = evaluateCondition_ifElementPresent(conditionOper, conditionValue1, tCExecution);86 mes = ans.getResultMessage();87 break;88 case TestCaseStepAction.CONDITIONOPER_IFELEMENTNOTPRESENT:89 ans = evaluateCondition_ifElementNotPresent(conditionOper, conditionValue1, tCExecution);90 mes = ans.getResultMessage();91 break;92 case TestCaseStepAction.CONDITIONOPER_IFPROPERTYEXIST:93 ans = evaluateCondition_ifPropertyExist(conditionOper, conditionValue1, tCExecution);94 mes = ans.getResultMessage();95 break;96 case TestCaseStepAction.CONDITIONOPER_IFPROPERTYNOTEXIST:97 ans = evaluateCondition_ifPropertyNotExist(conditionOper, conditionValue1, tCExecution);98 mes = ans.getResultMessage();99 break;100 case TestCaseStepAction.CONDITIONOPER_IFNUMERICEQUAL:101 case TestCaseStepAction.CONDITIONOPER_IFNUMERICDIFFERENT:102 case TestCaseStepAction.CONDITIONOPER_IFNUMERICGREATER:103 case TestCaseStepAction.CONDITIONOPER_IFNUMERICGREATEROREQUAL:104 case TestCaseStepAction.CONDITIONOPER_IFNUMERICMINOR:105 case TestCaseStepAction.CONDITIONOPER_IFNUMERICMINOROREQUAL:106 ans = evaluateCondition_ifNumericXXX(conditionOper, conditionValue1, conditionValue2);107 mes = ans.getResultMessage();108 break;109 case TestCaseStepAction.CONDITIONOPER_IFSTRINGEQUAL:110 ans = evaluateCondition_ifStringEqual(conditionOper, conditionValue1, conditionValue2, conditionValue3);111 mes = ans.getResultMessage();112 break;113 case TestCaseStepAction.CONDITIONOPER_IFSTRINGDIFFERENT:114 ans = evaluateCondition_ifStringDifferent(conditionOper, conditionValue1, conditionValue2, conditionValue3);115 mes = ans.getResultMessage();116 break;117 case TestCaseStepAction.CONDITIONOPER_IFSTRINGGREATER:118 ans = evaluateCondition_ifStringGreater(conditionOper, conditionValue1, conditionValue2);119 mes = ans.getResultMessage();120 break;121 case TestCaseStepAction.CONDITIONOPER_IFSTRINGMINOR:122 ans = evaluateCondition_ifStringMinor(conditionOper, conditionValue1, conditionValue2);123 mes = ans.getResultMessage();124 break;125 case TestCaseStepAction.CONDITIONOPER_IFSTRINGCONTAINS:126 ans = evaluateCondition_ifStringContains(conditionOper, conditionValue1, conditionValue2, conditionValue3);127 mes = ans.getResultMessage();128 break;129 case TestCaseStepAction.CONDITIONOPER_IFSTRINGNOTCONTAINS:130 ans = evaluateCondition_ifStringNotContains(conditionOper, conditionValue1, conditionValue2, conditionValue3);131 mes = ans.getResultMessage();132 break;133 case TestCaseStepAction.CONDITIONOPER_NEVER:134 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_NEVER);135 mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));136 break;137 case TestCaseStepAction.CONDITIONOPER_IFTEXTINELEMENT:138 ans = evaluateCondition_ifTextInElement(tCExecution, conditionValue1, conditionValue2, conditionOper, conditionValue3);139 mes = ans.getResultMessage();140 break;141 case TestCaseStepAction.CONDITIONOPER_IFTEXTNOTINELEMENT:142 ans = evaluateCondition_ifTextNotInElement(tCExecution, conditionValue1, conditionValue2, conditionOper, conditionValue3);143 mes = ans.getResultMessage();144 break;145 default:146 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_UNKNOWNCONDITION);147 mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));148 }149 LOG.debug("Finished Evaluation condition : " + mes.getCodeString());150 // the decision whether we execute the action/control/step is taken from the codeString of the message.151 if (mes.getCodeString().equals("OK")) { // If code is OK, we execute the Operation.152 execute_Operation = true;153 } else { // Any other status and we don't execute anything.154 execute_Operation = false;155 }156 ans.setItem(execute_Operation);157 ans.setResultMessage(mes);158 return ans;159 }160 private AnswerItem<Boolean> evaluateCondition_ifTextInElement(TestCaseExecution tCExecution, String path, String expected, String conditionOper, String isCaseSensitive) {161 if (LOG.isDebugEnabled()) {162 LOG.debug("Checking ifTextInElement on " + path + " element against value: " + expected);163 }164 AnswerItem<Boolean> ans = new AnswerItem<>();165 MessageEvent resultControlMes = new MessageEvent(MessageEventEnum.ACTION_SUCCESS);166 isCaseSensitive = defaultIsSensitiveValue(isCaseSensitive);167 resultControlMes = controlService.verifyTextInElement(tCExecution, path, expected, isCaseSensitive);168 if ("OK".equals(resultControlMes.getCodeString())) {169 MessageEvent resultCondMes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_TEXTINELEMENT);170 ans.setItem(true);171 ans.setResultMessage(resultCondMes);172 return ans;173 } else {174 MessageEvent resultCondMes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_TEXTINELEMENT);175 resultCondMes.setDescription(resultCondMes.getDescription().replace("%ERRORMESS%", resultControlMes.getDescription()));176 ans.setItem(false);177 ans.setResultMessage(resultCondMes);178 return ans;179 }180 }181 private AnswerItem<Boolean> evaluateCondition_ifTextNotInElement(TestCaseExecution tCExecution, String path, String expected, String conditionOper, String isCaseSensitive) {182 if (LOG.isDebugEnabled()) {183 LOG.debug("Checking ifTextInElement on " + path + " element against value: " + expected);184 }185 AnswerItem<Boolean> ans = new AnswerItem<>();186 MessageEvent resultMes = new MessageEvent(MessageEventEnum.ACTION_SUCCESS);187 isCaseSensitive = defaultIsSensitiveValue(isCaseSensitive);188 resultMes = controlService.verifyTextNotInElement(tCExecution, path, expected, isCaseSensitive);189 if ("OK".equals(resultMes.getCodeString())) {190 MessageEvent resultCondMes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_TEXTNOTINELEMENT);191 ans.setItem(true);192 ans.setResultMessage(resultCondMes);193 return ans;194 } else {195 MessageEvent resultCondMes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_TEXTNOTINELEMENT);196 resultCondMes.setDescription(resultCondMes.getDescription().replace("%ERRORMESS%", resultMes.getDescription()));197 ans.setItem(false);198 ans.setResultMessage(resultCondMes);199 return ans;200 }201 }202 private AnswerItem<Boolean> evaluateCondition_ifPropertyExist(String conditionOper, String conditionValue1, TestCaseExecution tCExecution) {203 if (LOG.isDebugEnabled()) {204 LOG.debug("Checking if property Exist");205 }206 AnswerItem<Boolean> ans = new AnswerItem<>();207 MessageEvent mes;208 if (StringUtil.isNullOrEmpty(conditionValue1)) {209 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFPROPERTYEXIST_MISSINGPARAMETER);210 mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));211 } else {212 String myCountry = tCExecution.getCountry();213 String myProperty = conditionValue1;214 boolean execute_Action = false;215 for (TestCaseCountryProperties prop : tCExecution.getTestCaseCountryPropertyList()) {216 LOG.debug(prop.getCountry() + " - " + myCountry + " - " + prop.getProperty() + " - " + myProperty);217 if ((prop.getCountry().equals(myCountry)) && (prop.getProperty().equals(myProperty))) {218 execute_Action = true;219 }220 }221 if (execute_Action == false) {222 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFPROPERTYEXIST);223 mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));224 mes.setDescription(mes.getDescription().replace("%PROP%", conditionValue1));225 mes.setDescription(mes.getDescription().replace("%COUNTRY%", tCExecution.getCountry()));226 } else {227 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFPROPERTYEXIST);228 mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));229 mes.setDescription(mes.getDescription().replace("%PROP%", conditionValue1));230 mes.setDescription(mes.getDescription().replace("%COUNTRY%", tCExecution.getCountry()));231 }232 }233 ans.setResultMessage(mes);234 return ans;235 }236 private AnswerItem<Boolean> evaluateCondition_ifPropertyNotExist(String conditionOper, String conditionValue1, TestCaseExecution tCExecution) {237 if (LOG.isDebugEnabled()) {238 LOG.debug("Checking if property Does not Exist");239 }240 AnswerItem<Boolean> ans = new AnswerItem<>();241 MessageEvent mes;242 if (StringUtil.isNullOrEmpty(conditionValue1)) {243 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFPROPERTYNOTEXIST_MISSINGPARAMETER);244 mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));245 } else {246 String myCountry = tCExecution.getCountry();247 String myProperty = conditionValue1;248 boolean execute_Action = true;249 for (TestCaseCountryProperties prop : tCExecution.getTestCaseCountryPropertyList()) {250 LOG.debug(prop.getCountry() + " - " + myCountry + " - " + prop.getProperty() + " - " + myProperty);251 if ((prop.getCountry().equals(myCountry)) && (prop.getProperty().equals(myProperty))) {252 execute_Action = false;253 }254 }255 if (execute_Action == false) {256 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFPROPERTYNOTEXIST);257 mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));258 mes.setDescription(mes.getDescription().replace("%PROP%", conditionValue1));259 mes.setDescription(mes.getDescription().replace("%COUNTRY%", tCExecution.getCountry()));260 } else {261 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFPROPERTYNOTEXIST);262 mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));263 mes.setDescription(mes.getDescription().replace("%PROP%", conditionValue1));264 mes.setDescription(mes.getDescription().replace("%COUNTRY%", tCExecution.getCountry()));265 }266 }267 ans.setResultMessage(mes);268 return ans;269 }270 private AnswerItem<Boolean> evaluateCondition_ifElementPresent(String conditionOper, String conditionValue1, TestCaseExecution tCExecution) {271 if (LOG.isDebugEnabled()) {272 LOG.debug("Checking if Element Present");273 }274 AnswerItem<Boolean> ans = new AnswerItem<>();275 MessageEvent mes;276 if (tCExecution.getManualExecution().equals("Y")) {277 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_NOTPOSSIBLE);278 } else if (StringUtil.isNullOrEmpty(conditionValue1)) {279 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFELEMENTPRESENT_MISSINGPARAMETER);280 mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));281 } else {282 boolean condition_result = false;283 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)284 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)285 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {286 Identifier identifier = identifierService.convertStringToIdentifier(conditionValue1);287 try {288 if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {289 condition_result = true;290 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);291 mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));292 } else {293 condition_result = false;294 mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTPRESENT);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)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!