Best Cerberus-source code snippet using org.cerberus.crud.entity.TestCaseStepActionControlExecution.getTestCaseStepActionExecution
Source:ControlService.java
...86 private IVariableService variableService;87 @Override88 public TestCaseStepActionControlExecution doControl(TestCaseStepActionControlExecution testCaseStepActionControlExecution) {89 MessageEvent res;90 TestCaseExecution tCExecution = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution();91 AnswerItem<String> answerDecode = new AnswerItem<>();92 /**93 * Decode the step action control description94 */95 try {96 // When starting a new control, we reset the property list that was already calculated.97 tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());98 answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getDescription(),99 tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), false);100 testCaseStepActionControlExecution.setDescription((String) answerDecode.getItem());101 if (!(answerDecode.isCodeStringEquals("OK"))) {102 // If anything wrong with the decode --> we stop here with decode message in the control result.103 testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Description"));104 testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));105 testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());106 testCaseStepActionControlExecution.setEnd(new Date().getTime());107 LOG.debug("Control interupted due to decode 'Description' Error.");108 return testCaseStepActionControlExecution;109 }110 } catch (CerberusEventException cex) {111 testCaseStepActionControlExecution.setControlResultMessage(cex.getMessageError());112 testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));113 return testCaseStepActionControlExecution;114 }115 /**116 * Decode the 2 fields property and values before doing the control.117 */118 try {119 // for both control property and control value120 //if the getvalue() indicates that the execution should stop then we stop it before the doControl or121 //if the property service was unable to decode the property that is specified in the object,122 //then the execution of this control should not performed123 if (testCaseStepActionControlExecution.getValue1() == null) {124 testCaseStepActionControlExecution.setValue1("");125 }126 if (testCaseStepActionControlExecution.getValue1().contains("%")) {127 // When starting a new control, we reset the property list that was already calculated.128 tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());129 answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getValue1(), tCExecution,130 testCaseStepActionControlExecution.getTestCaseStepActionExecution(), false);131 testCaseStepActionControlExecution.setValue1((String) answerDecode.getItem());132 if (!(answerDecode.isCodeStringEquals("OK"))) {133 // If anything wrong with the decode --> we stop here with decode message in the control result.134 testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Value1"));135 testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));136 testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());137 testCaseStepActionControlExecution.setEnd(new Date().getTime());138 LOG.debug("Control interupted due to decode 'Control Value1' Error.");139 return testCaseStepActionControlExecution;140 }141 }142 if (testCaseStepActionControlExecution.getValue2() == null) {143 testCaseStepActionControlExecution.setValue2("");144 }145 if (testCaseStepActionControlExecution.getValue2().contains("%")) {146 // When starting a new control, we reset the property list that was already calculated.147 tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());148 answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getValue2(),149 tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), false);150 testCaseStepActionControlExecution.setValue2((String) answerDecode.getItem());151 if (!(answerDecode.isCodeStringEquals("OK"))) {152 // If anything wrong with the decode --> we stop here with decode message in the control result.153 testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Value2"));154 testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));155 testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());156 testCaseStepActionControlExecution.setEnd(new Date().getTime());157 LOG.debug("Control interupted due to decode 'Control Value2' Error.");158 return testCaseStepActionControlExecution;159 }160 }161 if (testCaseStepActionControlExecution.getValue3() == null) {162 testCaseStepActionControlExecution.setValue3("");163 }164 if (testCaseStepActionControlExecution.getValue3().contains("%")) {165 // When starting a new control, we reset the property list that was already calculated.166 tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());167 answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getValue3(),168 tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), false);169 testCaseStepActionControlExecution.setValue3((String) answerDecode.getItem());170 if (!(answerDecode.isCodeStringEquals("OK"))) {171 // If anything wrong with the decode --> we stop here with decode message in the control result.172 testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Value3"));173 testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));174 testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());175 testCaseStepActionControlExecution.setEnd(new Date().getTime());176 LOG.debug("Control interupted due to decode 'Control Value3' Error.");177 return testCaseStepActionControlExecution;178 }179 }180 } catch (CerberusEventException cex) {181 testCaseStepActionControlExecution.setControlResultMessage(cex.getMessageError());182 testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));183 return testCaseStepActionControlExecution;184 }185 /**186 * Timestamp starts after the decode. TODO protect when property is187 * null.188 */189 testCaseStepActionControlExecution.setStart(new Date().getTime());190 // When starting a new control, we reset the property list that was already calculated.191 tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());192 try {193 switch (testCaseStepActionControlExecution.getControl()) {194 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGEQUAL:195 res = this.verifyStringEqual(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2(), testCaseStepActionControlExecution.getValue3());196 break;197 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGDIFFERENT:198 res = this.verifyStringDifferent(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2(), testCaseStepActionControlExecution.getValue3());199 break;200 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGGREATER:201 res = this.verifyStringGreater(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());202 break;203 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGMINOR:204 res = this.verifyStringMinor(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());205 break;206 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGCONTAINS:207 res = this.verifyStringContains(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2(), testCaseStepActionControlExecution.getValue3());208 break;209 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGNOTCONTAINS:210 res = this.verifyStringNotContains(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2(), testCaseStepActionControlExecution.getValue3());211 break;212 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICEQUALS:213 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICDIFFERENT:214 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATER:215 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATEROREQUAL:216 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOR:217 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOROREQUAL:218 res = this.evaluateControl_ifNumericXXX(testCaseStepActionControlExecution.getControl(), testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());219 break;220 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT:221 //TODO validate properties222 res = this.verifyElementPresent(tCExecution, testCaseStepActionControlExecution.getValue1());223 break;224 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT:225 //TODO validate properties226 res = this.verifyElementNotPresent(tCExecution, testCaseStepActionControlExecution.getValue1());227 break;228 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTVISIBLE:229 //TODO validate properties230 res = this.verifyElementVisible(tCExecution, testCaseStepActionControlExecution.getValue1());231 break;232 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTVISIBLE:233 //TODO validate properties234 res = this.verifyElementNotVisible(tCExecution, testCaseStepActionControlExecution.getValue1());235 break;236 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTEQUALS:237 res = this.verifyElementEquals(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());238 break;239 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTDIFFERENT:240 res = this.verifyElementDifferent(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());241 break;242 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTINELEMENT:243 //TODO validate properties244 res = this.verifyElementInElement(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());245 break;246 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTCLICKABLE:247 res = this.verifyElementClickable(tCExecution, testCaseStepActionControlExecution.getValue1());248 break;249 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTCLICKABLE:250 res = this.verifyElementNotClickable(tCExecution, testCaseStepActionControlExecution.getValue1());251 break;252 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTEQUAL:253 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTEQUAL, tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2(), testCaseStepActionControlExecution.getValue3());254 break;255 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTDIFFERENT:256 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTDIFFERENT, tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2(), testCaseStepActionControlExecution.getValue3());257 break;258 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:259 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL, tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2(), testCaseStepActionControlExecution.getValue3());260 break;261 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:262 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT, tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2(), testCaseStepActionControlExecution.getValue3());263 break;264 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:265 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER, tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2(), testCaseStepActionControlExecution.getValue3());266 break;267 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:268 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL, tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2(), testCaseStepActionControlExecution.getValue3());269 break;270 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:271 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR, tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2(), testCaseStepActionControlExecution.getValue3());272 break;273 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:274 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL, tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2(), testCaseStepActionControlExecution.getValue3());275 break;276 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTMATCHREGEX:277 res = this.VerifyElementTextMatchRegex(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());278 break;279 case TestCaseStepActionControl.CONTROL_VERIFYTEXTINPAGE:280 res = this.VerifyTextInPage(tCExecution, testCaseStepActionControlExecution.getValue1());281 break;282 case TestCaseStepActionControl.CONTROL_VERIFYTEXTNOTINPAGE:283 res = this.VerifyTextNotInPage(tCExecution, testCaseStepActionControlExecution.getValue1());284 break;285 case TestCaseStepActionControl.CONTROL_VERIFYTITLE:286 res = this.verifyTitle(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue3());287 break;288 case TestCaseStepActionControl.CONTROL_VERIFYURL:289 res = this.verifyUrl(tCExecution, testCaseStepActionControlExecution.getValue1());290 break;291 case TestCaseStepActionControl.CONTROL_VERIFYTEXTINDIALOG:292 res = this.verifyTextInDialog(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());293 break;294 case TestCaseStepActionControl.CONTROL_VERIFYXMLTREESTRUCTURE:295 res = this.verifyXmlTreeStructure(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());296 break;297 case TestCaseStepActionControl.CONTROL_TAKESCREENSHOT:298 res = this.takeScreenshot(tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), testCaseStepActionControlExecution, testCaseStepActionControlExecution.getValue1());299 break;300 case TestCaseStepActionControl.CONTROL_GETPAGESOURCE:301 res = this.getPageSource(tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), testCaseStepActionControlExecution);302 break;303 default:304 res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_UNKNOWNCONTROL);305 res.setDescription(res.getDescription().replace("%CONTROL%", testCaseStepActionControlExecution.getControl()));306 }307 } catch (final CerberusEventException exception) {308 res = exception.getMessageError();309 } catch (final Exception unexpected) {310 LOG.debug("Unexpected exception on control!", unexpected);311 res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC).resolveDescription("ERROR", unexpected.getMessage());312 }313 testCaseStepActionControlExecution.setControlResultMessage(res);314 /**315 * Updating Control result message only if control is not successful.316 * This is to keep the last KO information and preventing KO to be317 * transformed to OK.318 */319 if (!(res.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS)))) {320 testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(res.getMessage()));321 }322 /**323 * We only stop the test if Control Event message is in stop status AND324 * the control is FATAL. If control is not fatal, we continue the test325 * but refresh the Execution status.326 */327 if (res.isStopTest()) {328 if (testCaseStepActionControlExecution.getFatal().equals("Y")) {329 testCaseStepActionControlExecution.setStopExecution(true);330 }331 }332 testCaseStepActionControlExecution.setEnd(new Date().getTime());333 return testCaseStepActionControlExecution;334 }335 private MessageEvent verifyStringDifferent(String value1, String value2, String isCaseSensitive) {336 MessageEvent mes;337 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? !value1.equals(value2) : !value1.equalsIgnoreCase(value2)) {338 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_STRINGDIFFERENT);339 mes.setDescription(mes.getDescription().replace("%STRING1%", value1));340 mes.setDescription(mes.getDescription().replace("%STRING2%", value2));341 mes.setDescription(mes.getDescription().replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive)));342 return mes;343 }344 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_DIFFERENT);345 mes.setDescription(mes.getDescription().replace("%STRING1%", value1));346 mes.setDescription(mes.getDescription().replace("%STRING2%", value2));347 mes.setDescription(mes.getDescription().replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive)));348 return mes;349 }350 private MessageEvent verifyStringEqual(String value1, String value2, String isCaseSensitive) {351 MessageEvent mes;352 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? value1.equals(value2) : value1.equalsIgnoreCase(value2)) {353 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_STRINGEQUAL);354 mes.setDescription(mes.getDescription().replace("%STRING1%", value1));355 mes.setDescription(mes.getDescription().replace("%STRING2%", value2));356 mes.setDescription(mes.getDescription().replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive)));357 return mes;358 }359 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_EQUAL);360 mes.setDescription(mes.getDescription().replace("%STRING1%", value1));361 mes.setDescription(mes.getDescription().replace("%STRING2%", value2));362 mes.setDescription(mes.getDescription().replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive)));363 return mes;364 }365 private MessageEvent verifyStringContains(String value1, String value2, String isCaseSensitive) {366 MessageEvent mes;367 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? value1.indexOf(value2) >= 0 : value1.toLowerCase().indexOf(value2.toLowerCase()) >= 0) {368 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_CONTAINS);369 mes.setDescription(mes.getDescription().replace("%STRING1%", value1));370 mes.setDescription(mes.getDescription().replace("%STRING2%", value2));371 mes.setDescription(mes.getDescription().replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive)));372 return mes;373 }374 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CONTAINS);375 mes.setDescription(mes.getDescription().replace("%STRING1%", value1));376 mes.setDescription(mes.getDescription().replace("%STRING2%", value2));377 mes.setDescription(mes.getDescription().replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive)));378 return mes;379 }380 private MessageEvent verifyStringNotContains(String value1, String value2, String isCaseSensitive) {381 MessageEvent mes;382 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? value1.indexOf(value2) >= 0 : value1.toLowerCase().indexOf(value2.toLowerCase()) >= 0) {383 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCONTAINS);384 mes.setDescription(mes.getDescription().replace("%STRING1%", value1));385 mes.setDescription(mes.getDescription().replace("%STRING2%", value2));386 mes.setDescription(mes.getDescription().replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive)));387 return mes;388 }389 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTCONTAINS);390 mes.setDescription(mes.getDescription().replace("%STRING1%", value1));391 mes.setDescription(mes.getDescription().replace("%STRING2%", value2));392 mes.setDescription(mes.getDescription().replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive)));393 return mes;394 }395 private MessageEvent verifyStringGreater(String value1, String value2) {396 MessageEvent mes;397 if (value1.compareToIgnoreCase(value2) > 0) {398 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GREATER);399 mes.setDescription(mes.getDescription().replace("%STRING1%", value1));400 mes.setDescription(mes.getDescription().replace("%STRING2%", value2));401 return mes;402 } else {403 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GREATER);404 mes.setDescription(mes.getDescription().replace("%STRING1%", value1));405 mes.setDescription(mes.getDescription().replace("%STRING2%", value2));406 return mes;407 }408 }409 private MessageEvent verifyStringMinor(String value1, String value2) {410 MessageEvent mes;411 if (value1.compareToIgnoreCase(value2) < 0) {412 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_MINOR);413 mes.setDescription(mes.getDescription().replace("%STRING1%", value1));414 mes.setDescription(mes.getDescription().replace("%STRING2%", value2));415 return mes;416 } else {417 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_MINOR);418 mes.setDescription(mes.getDescription().replace("%STRING1%", value1));419 mes.setDescription(mes.getDescription().replace("%STRING2%", value2));420 return mes;421 }422 }423 private MessageEvent evaluateControl_ifNumericXXX(String control, String controlValue1, String controlValue2) {424 if (LOG.isDebugEnabled()) {425 LOG.debug("Checking if Numeric Equals");426 }427 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_PENDING);428 // We first prepare the string for nueric conversion to replace , by .429 String newControlValue1 = StringUtil.prepareToNumeric(controlValue1);430 String newControlValue2 = StringUtil.prepareToNumeric(controlValue2);431 // We try to convert the strings value1 to numeric.432 Double value1 = 0.0;433 try {434 value1 = Double.valueOf(newControlValue1);435 } catch (NumberFormatException nfe) {436 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);437 mes.setDescription(mes.getDescription()438 .replace("%COND%", control)439 .replace("%STRINGVALUE%", newControlValue1));440 return mes;441 }442 // We try to convert the strings value2 to numeric.443 Double value2 = 0.0;444 try {445 value2 = Double.valueOf(newControlValue2);446 } catch (NumberFormatException nfe) {447 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);448 mes.setDescription(mes.getDescription()449 .replace("%COND%", control)450 .replace("%STRINGVALUE%", newControlValue2));451 return mes;452 }453 // Now that both values are converted to double we ceck the operator here.454 boolean execute_Action = true;455 switch (control) {456 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICEQUALS:457 if (Objects.equals(value1, value2)) {458 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_EQUAL);459 mes.setDescription(mes.getDescription()460 .replace("%COND%", control)461 .replace("%STRING1%", value1.toString()).replace("%STRING2%", value2.toString())462 );463 } else {464 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_EQUAL);465 mes.setDescription(mes.getDescription()466 .replace("%COND%", control)467 .replace("%STRING1%", value1.toString()).replace("%STRING2%", value2.toString())468 );469 }470 break;471 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICDIFFERENT:472 if (!(Objects.equals(value1, value2))) {473 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_DIFFERENT);474 mes.setDescription(mes.getDescription()475 .replace("%COND%", control)476 .replace("%STRING1%", value1.toString()).replace("%STRING2%", value2.toString())477 );478 } else {479 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_DIFFERENT);480 mes.setDescription(mes.getDescription()481 .replace("%COND%", control)482 .replace("%STRING1%", value1.toString()).replace("%STRING2%", value2.toString())483 );484 }485 break;486 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATER:487 if (value1 > value2) {488 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GREATER);489 mes.setDescription(mes.getDescription()490 .replace("%COND%", control)491 .replace("%STRING1%", value1.toString()).replace("%STRING2%", value2.toString())492 );493 } else {494 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GREATER);495 mes.setDescription(mes.getDescription()496 .replace("%COND%", control)497 .replace("%STRING1%", value1.toString()).replace("%STRING2%", value2.toString())498 );499 }500 break;501 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATEROREQUAL:502 if (value1 >= value2) {503 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GREATEROREQUAL);504 mes.setDescription(mes.getDescription()505 .replace("%COND%", control)506 .replace("%STRING1%", value1.toString()).replace("%STRING2%", value2.toString())507 );508 } else {509 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GREATEROREQUAL);510 mes.setDescription(mes.getDescription()511 .replace("%COND%", control)512 .replace("%STRING1%", value1.toString()).replace("%STRING2%", value2.toString())513 );514 }515 break;516 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOR:517 if (value1 < value2) {518 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_MINOR);519 mes.setDescription(mes.getDescription()520 .replace("%COND%", control)521 .replace("%STRING1%", value1.toString()).replace("%STRING2%", value2.toString())522 );523 } else {524 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_MINOR);525 mes.setDescription(mes.getDescription()526 .replace("%COND%", control)527 .replace("%STRING1%", value1.toString()).replace("%STRING2%", value2.toString())528 );529 }530 break;531 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOROREQUAL:532 if (value1 <= value2) {533 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_MINOROREQUAL);534 mes.setDescription(mes.getDescription()535 .replace("%COND%", control)536 .replace("%STRING1%", value1.toString()).replace("%STRING2%", value2.toString())537 );538 } else {539 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_MINOROREQUAL);540 mes.setDescription(mes.getDescription()541 .replace("%COND%", control)542 .replace("%STRING1%", value1.toString()).replace("%STRING2%", value2.toString())543 );544 }545 break;546 }547 return mes;548 }549 private MessageEvent verifyElementPresent(TestCaseExecution tCExecution, String elementPath) {550 LOG.debug("Control : verifyElementPresent on : " + elementPath);551 MessageEvent mes;552 if (!StringUtil.isNull(elementPath)) {553 Identifier identifier = identifierService.convertStringToIdentifier(elementPath);554 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)555 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)556 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {557 try {558 if (identifier.getIdentifier().equals("picture")) {559 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator());560 } else if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {561 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);562 mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));563 return mes;564 } else {565 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);566 mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));567 return mes;568 }569 } catch (WebDriverException exception) {570 return parseWebDriverException(exception);571 }572 } else if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {573 if (tCExecution.getLastServiceCalled() != null) {574 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();575 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {576 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:577 if (xmlUnitService.isElementPresent(responseBody, elementPath)) {578 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);579 mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));580 return mes;581 } else {582 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);583 mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));584 return mes;585 }586 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {587 try {588 if (jsonService.getFromJson(responseBody, null, elementPath) != null) {589 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);590 mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));591 return mes;592 } else {593 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);594 mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));595 return mes;596 }597 } catch (Exception ex) {598 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);599 mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));600 return mes;601 }602 }603 default:604 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);605 mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));606 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementPresent"));607 return mes;608 }609 } else {610 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);611 return mes;612 }613 } else if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_FAT)) {614 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator());615 } else {616 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);617 mes.setDescription(mes.getDescription().replace("%CONTROL%", "VerifyElementPresent"));618 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));619 return mes;620 }621 } else {622 return new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT_NULL);623 }624 }625 private MessageEvent verifyElementNotPresent(TestCaseExecution tCExecution, String elementPath) {626 LOG.debug("Control : verifyElementNotPresent on : " + elementPath);627 MessageEvent mes;628 if (!StringUtil.isNull(elementPath)) {629 Identifier identifier = identifierService.convertStringToIdentifier(elementPath);630 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)631 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)632 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {633 try {634 if (identifier.getIdentifier().equals("picture")) {635 return sikuliService.doSikuliVerifyElementNotPresent(tCExecution.getSession(), identifier.getLocator());636 } else if (!this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {637 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);638 mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));639 return mes;640 } else {641 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);642 mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));643 return mes;644 }645 } catch (WebDriverException exception) {646 return parseWebDriverException(exception);647 }648 } else if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_FAT)) {649 return sikuliService.doSikuliVerifyElementNotPresent(tCExecution.getSession(), identifier.getLocator());650 } else if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {651 if (tCExecution.getLastServiceCalled() != null) {652 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();653 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {654 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:655 if (!(xmlUnitService.isElementPresent(responseBody, elementPath))) {656 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);657 mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));658 return mes;659 } else {660 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);661 mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));662 return mes;663 }664 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {665 try {666 if (jsonService.getFromJson(responseBody, null, elementPath) == null) {667 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);668 mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));669 return mes;670 } else {671 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);672 mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));673 return mes;674 }675 } catch (Exception ex) {676 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);677 mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));678 return mes;679 }680 }681 default:682 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);683 mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));684 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementNotPresent"));685 return mes;686 }687 } else {688 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);689 return mes;690 }691 } else {692 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);693 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementNotPresent"));694 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));695 return mes;696 }697 } else {698 return new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT_NULL);699 }700 }701 private MessageEvent verifyElementInElement(TestCaseExecution tCExecution, String element, String childElement) {702 if (LOG.isDebugEnabled()) {703 LOG.debug("Control : verifyElementInElement on : '" + element + "' is child of '" + childElement + "'");704 }705 MessageEvent mes;706 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)707 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)) {708 if (!StringUtil.isNull(element) && !StringUtil.isNull(childElement)) {709 try {710 Identifier identifier = identifierService.convertStringToIdentifier(element);711 Identifier childIdentifier = identifierService.convertStringToIdentifier(childElement);712 if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {713 if (this.webdriverService.isElementInElement(tCExecution.getSession(), identifier, childIdentifier)) {714 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTINELEMENT);715 mes.setDescription(mes.getDescription().replace("%STRING2%", element).replace("%STRING1%", childElement));716 return mes;717 } else {718 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTINELEMENT);719 mes.setDescription(mes.getDescription().replace("%STRING2%", element).replace("%STRING1%", childElement));720 return mes;721 }722 } else {723 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NO_SUCH_ELEMENT);724 mes.setDescription(mes.getDescription().replace("%SELEX%", new NoSuchElementException("").toString()).replace("%ELEMENT%", element));725 return mes;726 }727 } catch (WebDriverException exception) {728 return parseWebDriverException(exception);729 }730 } else {731 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTINELEMENT);732 mes.setDescription(mes.getDescription().replace("%STRING2%", element).replace("%STRING1%", childElement));733 return mes;734 }735 } else {736 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);737 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementInElement"));738 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));739 return mes;740 }741 }742 private MessageEvent verifyElementVisible(TestCaseExecution tCExecution, String html) {743 LOG.debug("Control : verifyElementVisible on : " + html);744 MessageEvent mes;745 if (!StringUtil.isNull(html)) {746 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)747 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)748 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {749 try {750 Identifier identifier = identifierService.convertStringToIdentifier(html);751 if (this.webdriverService.isElementVisible(tCExecution.getSession(), identifier)) {752 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_VISIBLE);753 mes.setDescription(mes.getDescription().replace("%STRING1%", html));754 return mes;755 } else {756 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VISIBLE);757 mes.setDescription(mes.getDescription().replace("%STRING1%", html));758 return mes;759 }760 } catch (WebDriverException exception) {761 return parseWebDriverException(exception);762 }763 } else {764 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);765 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementVisible"));766 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));767 return mes;768 }769 } else {770 return new MessageEvent(MessageEventEnum.CONTROL_FAILED_VISIBLE_NULL);771 }772 }773 private MessageEvent verifyElementNotVisible(TestCaseExecution tCExecution, String html) {774 LOG.debug("Control : verifyElementNotVisible on : " + html);775 MessageEvent mes;776 if (!StringUtil.isNull(html)) {777 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)778 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)779 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {780 try {781 Identifier identifier = identifierService.convertStringToIdentifier(html);782 if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {783 if (this.webdriverService.isElementNotVisible(tCExecution.getSession(), identifier)) {784 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTVISIBLE);785 mes.setDescription(mes.getDescription().replace("%STRING1%", html));786 return mes;787 } else {788 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTVISIBLE);789 mes.setDescription(mes.getDescription().replace("%STRING1%", html));790 return mes;791 }792 } else {793 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);794 mes.setDescription(mes.getDescription().replace("%STRING1%", html));795 return mes;796 }797 } catch (WebDriverException exception) {798 return parseWebDriverException(exception);799 }800 } else {801 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);802 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementNotVisible"));803 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));804 return mes;805 }806 } else {807 return new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTVISIBLE_NULL);808 }809 }810 private MessageEvent verifyElementEquals(TestCaseExecution tCExecution, String xpath, String expectedElement) {811 LOG.debug("Control : verifyElementEquals on : " + xpath + " expected Element : " + expectedElement);812 MessageEvent mes = null;813 // If case of not compatible application then exit with error814 if (!tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {815 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);816 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementEquals"));817 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));818 return mes;819 }820 // Check if element on the given xpath is equal to the given expected element821 if (tCExecution.getLastServiceCalled() != null) {822 String xmlResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();823 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {824 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:825 mes = xmlUnitService.isElementEquals(xmlResponse, xpath, expectedElement) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTEQUALS) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTEQUALS);826 mes.setDescription(mes.getDescription().replace("%XPATH%", xpath));827 mes.setDescription(mes.getDescription().replace("%EXPECTED_ELEMENT%", expectedElement));828 return mes;829 default:830 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);831 mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));832 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementEquals"));833 return mes;834 }835 // TODO Give the actual element found into the description.836 } else {837 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);838 return mes;839 }840 }841 private MessageEvent verifyElementDifferent(TestCaseExecution tCExecution, String xpath, String differentElement) {842 LOG.debug("Control : verifyElementDifferent on : " + xpath + " expected Element : " + differentElement);843 MessageEvent mes = null;844 // If case of not compatible application then exit with error845 if (!tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {846 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);847 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementDifferent"));848 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));849 return mes;850 }851 // Check if element on the given xpath is different from the given different element852// SOAPExecution lastSoapCalled = (SOAPExecution) tCExecution.getLastSOAPCalled().getItem();853 if (tCExecution.getLastServiceCalled() != null) {854 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {855 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:856 String xmlResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();857 mes = xmlUnitService.isElementEquals(xmlResponse, xpath, differentElement) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTDIFFERENT);858 mes.setDescription(mes.getDescription().replace("%XPATH%", xpath));859 mes.setDescription(mes.getDescription().replace("%DIFFERENT_ELEMENT%", differentElement));860 return mes;861 default:862 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);863 mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));864 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementDifferent"));865 return mes;866 }867 // TODO Give the actual element found into the description.868 } else {869 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);870 return mes;871 }872 }873 @Override874 public MessageEvent verifyElementXXX(String control, TestCaseExecution tCExecution, String path, String expected, String isCaseSensitive) {875 if (LOG.isDebugEnabled()) {876 LOG.debug("Control: verifyElementXXX (" + control + ") on " + path + " element against value: " + expected + " AppType : " + tCExecution.getAppTypeEngine());877 }878 MessageEvent mes;879 // Get value from the path element according to the application type880 String actual = null;881 try {882 Identifier identifier = identifierService.convertStringToIdentifier(path);883 String applicationType = tCExecution.getAppTypeEngine();884 switch (applicationType) {885 case Application.TYPE_GUI:886 case Application.TYPE_APK:887 case Application.TYPE_IPA:888 actual = webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);889 // In case of null actual value then we alert user890 if (actual == null) {891 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NULL);892 mes.setDescription(mes.getDescription().replace("%STRING1%", path));893 return mes;894 }895 // Get the result depending on the control required.896 mes = switchControl(control, path, actual, expected, isCaseSensitive);897 return mes;898 case Application.TYPE_SRV:899 if (tCExecution.getLastServiceCalled() != null) {900 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();901 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {902 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:903 if (!xmlUnitService.isElementPresent(responseBody, path)) {904 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);905 mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));906 return mes;907 }908 String newPath = StringUtil.addSuffixIfNotAlready(path, "/text()");909 actual = xmlUnitService.getFromXml(responseBody, newPath);910 // In case of null actual value then we alert user911 if (actual == null) {912 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NULL);913 mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));914 return mes;915 }916 // Get the result depending on the control required.917 mes = switchControl(control, path, actual, expected, isCaseSensitive);918 return mes;919 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {920 try {921 actual = jsonService.getFromJson(responseBody, null, path);922 } catch (Exception ex) {923 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);924 mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));925 return mes;926 }927 }928 // In case of null actual value then we alert user929 if (actual == null) {930 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);931 mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));932 return mes;933 }934 // Get the result depending on the control required.935 mes = switchControl(control, path, actual, expected, isCaseSensitive);936 return mes;937 default:938 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);939 mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));940 mes.setDescription(mes.getDescription().replace("%CONTROL%", control));941 return mes;942 }943 } else {944 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);945 return mes;946 }947 default:948 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);949 mes.setDescription(mes.getDescription().replace("%CONTROL%", control));950 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));951 return mes;952 }953 } catch (NoSuchElementException exception) {954 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);955 mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));956 return mes;957 } catch (WebDriverException exception) {958 return parseWebDriverException(exception);959 }960 }961 private MessageEvent switchControl(String control, String path, String actual, String expected, String isCaseSensitive) {962 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);963 mes.setDescription(mes.getDescription().replace("%CONTROL%", "switchControl-" + control));964 switch (control) {965 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTEQUAL:966 mes = verifyElementTextEqualCaseSensitiveCheck(actual, expected, isCaseSensitive);967 break;968 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTDIFFERENT:969 mes = verifyElementTextDifferentCaseSensitiveCheck(actual, expected, isCaseSensitive);970 break;971 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:972 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:973 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:974 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:975 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:976 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:977 Double value1 = 0.0;978 try {979 value1 = Double.valueOf(actual);980 } catch (NumberFormatException nfe) {981 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);982 mes.setDescription(mes.getDescription().replace("%COND%", control).replace("%STRINGVALUE%", actual));983 return mes;984 }985 // We try to convert the strings value2 to numeric.986 Double value2 = 0.0;987 try {988 value2 = Double.valueOf(expected);989 } catch (NumberFormatException nfe) {990 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);991 mes.setDescription(mes.getDescription().replace("%COND%", control).replace("%STRINGVALUE%", expected));992 return mes;993 }994 mes = checkNumericVerifyElement(control, value1, value2);995 break;996 }997 mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));998 mes.setDescription(mes.getDescription().replace("%ELEMENTVALUE%", actual));999 mes.setDescription(mes.getDescription().replace("%VALUE%", expected));1000 mes.setDescription(mes.getDescription().replace("%CASESENSITIVE%", caseSensitiveMessageValue(isCaseSensitive)));1001 return mes;1002 }1003 private MessageEvent verifyElementTextEqualCaseSensitiveCheck(String actual, String expected, String isCaseSensitive) {1004 MessageEvent mes;1005 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {1006 mes = actual.equals(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTEQUAL) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTEQUAL);1007 } else {1008 mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTEQUAL) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTEQUAL);1009 }1010 return mes;1011 }1012 private MessageEvent verifyElementTextDifferentCaseSensitiveCheck(String actual, String expected, String isCaseSensitive) {1013 MessageEvent mes;1014 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {1015 mes = actual.equals(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTDIFFERENT);1016 } else {1017 mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTDIFFERENT);1018 }1019 return mes;1020 }1021 private MessageEvent checkNumericVerifyElement(String control, Double actual, Double expected) {1022 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1023 mes.setDescription(mes.getDescription().replace("%CONTROL%", "checkNumericVerifyElement-" + control));1024 switch (control) {1025 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:1026 mes = actual.equals(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICEQUAL) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICEQUAL);1027 return mes;1028 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:1029 mes = !actual.equals(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICDIFFERENT);1030 return mes;1031 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:1032 mes = actual > expected ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICGREATER) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICGREATER);1033 return mes;1034 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:1035 mes = actual >= expected ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICGREATEROREQUAL) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICGREATEROREQUAL);1036 return mes;1037 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:1038 mes = actual < expected ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICMINOR) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICMINOR);1039 return mes;1040 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:1041 mes = actual <= expected ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICMINOROREQUAL) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICMINOROREQUAL);1042 return mes;1043 }1044 return mes;1045 }1046 private MessageEvent VerifyElementTextMatchRegex(TestCaseExecution tCExecution, String path, String regex) {1047 LOG.debug("Control : VerifyElementTextMatchRegex on : " + path + " element against value : " + regex);1048 MessageEvent mes;1049 String pathContent = null;1050 try {1051 Identifier identifier = identifierService.convertStringToIdentifier(path);1052 String applicationType = tCExecution.getAppTypeEngine();1053 // Get value from the path element according to the application type1054 if (Application.TYPE_GUI.equalsIgnoreCase(applicationType)1055 || Application.TYPE_APK.equalsIgnoreCase(applicationType)1056 || Application.TYPE_IPA.equalsIgnoreCase(applicationType)) {1057 pathContent = this.webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);1058 } else if (Application.TYPE_SRV.equalsIgnoreCase(applicationType)) {1059 if (tCExecution.getLastServiceCalled() != null) {1060 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();1061 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {1062 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:1063 if (!xmlUnitService.isElementPresent(responseBody, path)) {1064 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);1065 mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));1066 return mes;1067 }1068 String newPath = StringUtil.addSuffixIfNotAlready(path, "/text()");1069 pathContent = xmlUnitService.getFromXml(responseBody, newPath);1070 break;1071 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:1072 try {1073 pathContent = jsonService.getFromJson(responseBody, null, path);1074 } catch (Exception ex) {1075 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);1076 mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));1077 return mes;1078 }1079 break;1080 default:1081 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);1082 mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));1083 mes.setDescription(mes.getDescription().replace("%CONTROL%", "VerifyElementTextMatchRegex"));1084 return mes;1085 }1086 // TODO Give the actual element found into the description.1087 } else {1088 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);1089 return mes;1090 }1091 } else {1092 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1093 mes.setDescription(mes.getDescription().replace("%CONTROL%", "VerifyElementTextMatchRegex"));1094 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));1095 return mes;1096 }1097 LOG.debug("Control : VerifyElementMatchRegex element : " + path + " has value : " + StringUtil.sanitize(pathContent));1098 if (path != null && pathContent != null) {1099 try {1100 Pattern pattern = Pattern.compile(regex);1101 Matcher matcher = pattern.matcher(pathContent);1102 if (matcher.find()) {1103 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_REGEXINELEMENT);1104 mes.setDescription(mes.getDescription().replace("%STRING1%", path));1105 mes.setDescription(mes.getDescription().replace("%STRING2%", StringUtil.sanitize(pathContent)));1106 mes.setDescription(mes.getDescription().replace("%STRING3%", regex));1107 return mes;1108 } else {1109 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT);1110 mes.setDescription(mes.getDescription().replace("%STRING1%", path));1111 mes.setDescription(mes.getDescription().replace("%STRING2%", StringUtil.sanitize(pathContent)));1112 mes.setDescription(mes.getDescription().replace("%STRING3%", regex));1113 return mes;1114 }1115 } catch (PatternSyntaxException e) {1116 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_INVALIDPATERN);1117 mes.setDescription(mes.getDescription().replace("%PATERN%", regex));1118 mes.setDescription(mes.getDescription().replace("%ERROR%", e.getMessage()));1119 return mes;1120 }1121 } else if (pathContent != null) {1122 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NULL);1123 return mes;1124 } else {1125 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NO_SUCH_ELEMENT);1126 mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));1127 return mes;1128 }1129 } catch (NoSuchElementException exception) {1130 LOG.debug(exception.toString());1131 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NO_SUCH_ELEMENT);1132 mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));1133 return mes;1134 } catch (WebDriverException exception) {1135 return parseWebDriverException(exception);1136 }1137 }1138 private MessageEvent verifyTextInDialog(TestCaseExecution tCExecution, String property, String value) {1139 LOG.debug("Control : verifyTextInDialog against value : " + value);1140 MessageEvent mes;1141 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1142 try {1143 String str = this.webdriverService.getAlertText(tCExecution.getSession());1144 LOG.debug("Control : verifyTextInAlertPopup has value : " + str);1145 if (str != null) {1146 String valueToTest = property;1147 if (valueToTest == null || "".equals(valueToTest.trim())) {1148 valueToTest = value;1149 }1150 if (str.trim().equalsIgnoreCase(valueToTest)) {1151 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTINALERT);1152 mes.setDescription(mes.getDescription().replace("%STRING1%", str));1153 mes.setDescription(mes.getDescription().replace("%STRING2%", valueToTest));1154 return mes;1155 } else {1156 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINALERT);1157 mes.setDescription(mes.getDescription().replace("%STRING1%", str));1158 mes.setDescription(mes.getDescription().replace("%STRING2%", valueToTest));1159 return mes;1160 }1161 } else {1162 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINALERT_NULL);1163 return mes;1164 }1165 } catch (WebDriverException exception) {1166 return parseWebDriverException(exception);1167 }1168 } else {1169 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1170 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyTextInDialog"));1171 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));1172 return mes;1173 }1174 }1175 private MessageEvent VerifyTextInPage(TestCaseExecution tCExecution, String regex) {1176 LOG.debug("Control : verifyTextInPage on : " + regex);1177 MessageEvent mes;1178 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())1179 || Application.TYPE_APK.equalsIgnoreCase(tCExecution.getAppTypeEngine())1180 || Application.TYPE_IPA.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1181 String pageSource;1182 try {1183 pageSource = this.webdriverService.getPageSource(tCExecution.getSession());1184 if (LOG.isDebugEnabled()) {1185 LOG.debug(pageSource);1186 }1187 try {1188 Pattern pattern = Pattern.compile(regex);1189 Matcher matcher = pattern.matcher(pageSource);1190 if (matcher.find()) {1191 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTINPAGE);1192 mes.setDescription(mes.getDescription().replace("%STRING1%", Pattern.quote(regex)));1193 return mes;1194 } else {1195 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINPAGE);1196 mes.setDescription(mes.getDescription().replace("%STRING1%", Pattern.quote(regex)));1197 return mes;1198 }1199 } catch (PatternSyntaxException e) {1200 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINPAGE_INVALIDPATERN);1201 mes.setDescription(mes.getDescription().replace("%PATERN%", Pattern.quote(regex)));1202 mes.setDescription(mes.getDescription().replace("%ERROR%", e.getMessage()));1203 return mes;1204 }1205 } catch (WebDriverException exception) {1206 return parseWebDriverException(exception);1207 }1208 } else if (Application.TYPE_FAT.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1209 return sikuliService.doSikuliVerifyTextInPage(tCExecution.getSession(), regex);1210 } else {1211 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1212 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyTextInPage"));1213 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));1214 return mes;1215 }1216 }1217 private MessageEvent VerifyTextNotInPage(TestCaseExecution tCExecution, String regex) {1218 LOG.debug("Control : VerifyTextNotInPage on : " + regex);1219 MessageEvent mes;1220 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())1221 || Application.TYPE_APK.equalsIgnoreCase(tCExecution.getAppTypeEngine())1222 || Application.TYPE_IPA.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1223 String pageSource;1224 try {1225 pageSource = this.webdriverService.getPageSource(tCExecution.getSession());1226 if (LOG.isDebugEnabled()) {1227 LOG.debug(pageSource);1228 }1229 try {1230 Pattern pattern = Pattern.compile(regex);1231 Matcher matcher = pattern.matcher(pageSource);1232 if (!(matcher.find())) {1233 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTNOTINPAGE);1234 mes.setDescription(mes.getDescription().replace("%STRING1%", Pattern.quote(regex)));1235 return mes;1236 } else {1237 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINPAGE);1238 mes.setDescription(mes.getDescription().replace("%STRING1%", Pattern.quote(regex)));1239 return mes;1240 }1241 } catch (PatternSyntaxException e) {1242 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINPAGE_INVALIDPATERN);1243 mes.setDescription(mes.getDescription().replace("%PATERN%", Pattern.quote(regex)));1244 mes.setDescription(mes.getDescription().replace("%ERROR%", e.getMessage()));1245 return mes;1246 }1247 } catch (WebDriverException exception) {1248 return parseWebDriverException(exception);1249 }1250 } else {1251 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1252 mes.setDescription(mes.getDescription().replace("%CONTROL%", "VerifyTextNotInPage"));1253 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));1254 return mes;1255 }1256 }1257 private MessageEvent verifyUrl(TestCaseExecution tCExecution, String value1) throws CerberusEventException {1258 LOG.debug("Control : verifyUrl on : " + value1);1259 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1260 MessageEvent mes;1261 String url = "";1262 // Control is made forcing the / at the beginning of URL. getCurrentUrl from Selenium1263 // already have that control but value1 is specified by user and could miss it.1264 final String controlUrl = StringUtil.addPrefixIfNotAlready(value1, "/");1265// url = this.webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());1266 try {1267 LOG.debug("Before wait : " + System.currentTimeMillis());1268 WebDriverWait wait = new WebDriverWait(tCExecution.getSession().getDriver(),1269 TimeUnit.MILLISECONDS.toSeconds(tCExecution.getSession().getCerberus_selenium_wait_element()));1270 //Wait until the url is the expected one1271 wait.until(new Function<WebDriver, Boolean>() {1272 String value = "";1273 String expectedValue = controlUrl;1274 public Boolean apply(WebDriver driver) {1275 try {1276 this.value = webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());1277 LOG.debug("Get new url : " + value + " >> Expected url : " + expectedValue);1278 } catch (CerberusEventException ex) {1279 LOG.warn(ex.getMessageError().getDescription());1280 }1281 return value.equalsIgnoreCase(expectedValue);1282 }1283 });1284 LOG.debug("After wait : " + System.currentTimeMillis());1285 url = this.webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());1286 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_URL);1287 mes.setDescription(mes.getDescription().replace("%STRING1%", url));1288 mes.setDescription(mes.getDescription().replace("%STRING2%", controlUrl));1289 return mes;1290 } catch (TimeoutException exception) {1291 url = this.webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());1292 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_URL);1293 mes.setDescription(mes.getDescription().replace("%STRING1%", url));1294 mes.setDescription(mes.getDescription().replace("%STRING2%", controlUrl));1295 return mes;1296 } catch (WebDriverException exception) {1297 return parseWebDriverException(exception);1298 }1299 } else {1300 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1301 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyUrl"));1302 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));1303 return mes;1304 }1305 }1306 private MessageEvent verifyTitle(TestCaseExecution tCExecution, String title, String isCaseSensitive) {1307 LOG.debug("Control : verifyTitle on : " + title);1308 MessageEvent mes;1309 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1310 String pageTitle = this.webdriverService.getTitle(tCExecution.getSession());1311 try {1312 LOG.debug("Before wait" + System.currentTimeMillis());1313 WebDriverWait wait = new WebDriverWait(tCExecution.getSession().getDriver(),1314 TimeUnit.MILLISECONDS.toSeconds(tCExecution.getSession().getCerberus_selenium_wait_element()));1315 //Wait until the title is the expected one1316 wait.until(new Function<WebDriver, Boolean>() {1317 String value;1318 String expectedValue = title;1319 public Boolean apply(WebDriver driver) {1320 this.value = webdriverService.getTitle(tCExecution.getSession());1321 LOG.debug("Get new title : " + value + " >> Expected title : " + expectedValue);1322 return ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? expectedValue.equals(value) : expectedValue.equalsIgnoreCase(value);1323 }1324 });1325 LOG.debug("After wait" + System.currentTimeMillis());1326 pageTitle = this.webdriverService.getTitle(tCExecution.getSession());1327 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TITLE);1328 mes.setDescription(mes.getDescription().replace("%STRING1%", pageTitle));1329 mes.setDescription(mes.getDescription().replace("%STRING2%", title));1330 mes.setDescription(mes.getDescription().replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive)));1331 return mes;1332 } catch (TimeoutException exception) {1333 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TITLE);1334 mes.setDescription(mes.getDescription().replace("%STRING1%", pageTitle));1335 mes.setDescription(mes.getDescription().replace("%STRING2%", title));1336 mes.setDescription(mes.getDescription().replace("%STRING3%", caseSensitiveMessageValue(isCaseSensitive)));1337 return mes;1338 } catch (WebDriverException exception) {1339 return parseWebDriverException(exception);1340 }1341 } else {1342 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1343 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyTitle"));1344 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));1345 return mes;1346 }1347 }1348 private MessageEvent verifyXmlTreeStructure(TestCaseExecution tCExecution, String controlProperty, String controlValue) {1349 LOG.debug("Control : verifyXmlTreeStructure on : " + controlProperty);1350 MessageEvent mes;1351 if (Application.TYPE_SRV.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1352 try {1353 if (tCExecution.getLastServiceCalled() != null) {1354 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {1355 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:1356 String xmlResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();1357 if (this.xmlUnitService.isSimilarTree(xmlResponse, controlProperty, controlValue)) {1358 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_SIMILARTREE);1359 mes.setDescription(mes.getDescription().replace("%STRING1%", StringUtil.sanitize(controlProperty)));1360 mes.setDescription(mes.getDescription().replace("%STRING2%", StringUtil.sanitize(controlValue)));1361 return mes;1362 } else {1363 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_SIMILARTREE);1364 mes.setDescription(mes.getDescription().replace("%STRING1%", StringUtil.sanitize(controlProperty)));1365 mes.setDescription(mes.getDescription().replace("%STRING2%", StringUtil.sanitize(controlValue)));1366 return mes;1367 }1368 default:1369 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);1370 mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));1371 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyXmlTreeStructure"));1372 return mes;1373 }1374 } else {1375 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);1376 return mes;1377 }1378 } catch (Exception exception) {1379 LOG.fatal(exception.toString());1380 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED);1381 return mes;1382 }1383 } else {1384 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1385 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyXmlTreeStructure"));1386 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));1387 return mes;1388 }1389 }1390 private MessageEvent verifyElementClickable(TestCaseExecution tCExecution, String html) {1391 LOG.debug("Control : verifyElementClickable : " + html);1392 MessageEvent mes;1393 if (!StringUtil.isNull(html)) {1394 Identifier identifier = identifierService.convertStringToIdentifier(html);1395 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1396 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)) {1397 try {1398 if (this.webdriverService.isElementClickable(tCExecution.getSession(), identifier)) {1399 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_CLICKABLE);1400 mes.setDescription(mes.getDescription().replace("%ELEMENT%", html));1401 return mes;1402 } else {1403 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CLICKABLE);1404 mes.setDescription(mes.getDescription().replace("%ELEMENT%", html));1405 return mes;1406 }1407 } catch (WebDriverException exception) {1408 return parseWebDriverException(exception);1409 }1410 } else {1411 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1412 mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementClickable"));1413 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));1414 return mes;1415 }1416 } else {1417 return new MessageEvent(MessageEventEnum.CONTROL_FAILED_CLICKABLE_NULL);1418 }1419 }1420 private MessageEvent verifyElementNotClickable(TestCaseExecution tCExecution, String html) {1421 LOG.debug("Control : verifyElementNotClickable on : " + html);1422 MessageEvent mes;1423 if (!StringUtil.isNull(html)) {1424 Identifier identifier = identifierService.convertStringToIdentifier(html);1425 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1426 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)) {1427 try {1428 if (this.webdriverService.isElementNotClickable(tCExecution.getSession(), identifier)) {1429 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTCLICKABLE);1430 mes.setDescription(mes.getDescription().replace("%ELEMENT%", html));1431 return mes;1432 } else {1433 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCLICKABLE);1434 mes.setDescription(mes.getDescription().replace("%ELEMENT%", html));1435 return mes;1436 }1437 } catch (WebDriverException exception) {1438 return parseWebDriverException(exception);1439 }1440 } else {1441 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1442 mes.setDescription(mes.getDescription().replace("%CONTROL%", "VerifyElementNotClickable"));1443 mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getAppTypeEngine()));1444 return mes;1445 }1446 } else {1447 return new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCLICKABLE_NULL);1448 }1449 }1450 private String caseSensitiveMessageValue(String isCaseSensitive) {1451 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {1452 return "case sensitive";1453 } else {1454 return "case insensitive";1455 }1456 }1457 private MessageEvent takeScreenshot(TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution, String cropValues) {1458 MessageEvent message;1459 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1460 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)1461 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)1462 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_FAT)) {1463 TestCaseExecutionFile file = recorderService.recordScreenshot(tCExecution, testCaseStepActionExecution, testCaseStepActionControlExecution.getControlSequence(), cropValues);1464 testCaseStepActionControlExecution.addFileList(file);1465 message = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TAKESCREENSHOT);1466 return message;1467 }1468 message = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1469 message.setDescription(message.getDescription().replace("%CONTROL%", "takeScreenShot"));1470 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getAppTypeEngine()));1471 return message;1472 }1473 private MessageEvent getPageSource(TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution) {1474 MessageEvent message;1475 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1476 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)1477 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {1478 TestCaseExecutionFile file = recorderService.recordPageSource(tCExecution, testCaseStepActionExecution, testCaseStepActionControlExecution.getControlSequence());1479 if (file != null) {1480 List<TestCaseExecutionFile> fileList = new ArrayList<>();1481 fileList.add(file);1482 testCaseStepActionControlExecution.setFileList(fileList);1483 }1484 message = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GETPAGESOURCE);1485 return message;1486 }1487 message = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1488 message.setDescription(message.getDescription().replace("%CONTROL%", "takeScreenShot"));1489 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getAppTypeEngine()));1490 return message;1491 }1492 /**1493 * @author memiks1494 * @param exception the exception need to be parsed by Cerberus1495 * @return A new Event Message with selenium related description1496 */1497 private MessageEvent parseWebDriverException(WebDriverException exception) {1498 MessageEvent mes;1499 LOG.error(exception.toString(), exception);1500 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_SELENIUM_CONNECTIVITY);1501 mes.setDescription(mes.getDescription().replace("%ERROR%", exception.getMessage().split("\n")[0]));1502 return mes;1503 }1504 /**1505 * Updates the test case messages if the control failed to calculate the1506 * property values that it needs.1507 *1508 * @param testCaseStepActionControlExecution1509 * @return false if the property value was not retrieved with success, true1510 * otherwise1511 */1512 private boolean isPropertyGetValueSucceed(TestCaseStepActionControlExecution testCaseStepActionControlExecution) {1513 if (testCaseStepActionControlExecution.getTestCaseStepActionExecution().isStopExecution()1514 || testCaseStepActionControlExecution.getTestCaseStepActionExecution().getActionResultMessage().getCode()1515 == MessageEventEnum.PROPERTY_FAILED_NO_PROPERTY_DEFINITION.getCode()) {1516 testCaseStepActionControlExecution.setStopExecution(testCaseStepActionControlExecution.getTestCaseStepActionExecution().1517 isStopExecution());1518 testCaseStepActionControlExecution.setControlResultMessage(testCaseStepActionControlExecution.getTestCaseStepActionExecution().1519 getActionResultMessage());1520 testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(testCaseStepActionControlExecution.1521 getTestCaseStepActionExecution().getActionResultMessage().getMessage()));1522 return false;1523 }1524 return true;1525 }1526}...
getTestCaseStepActionExecution
Using AI Code Generation
1import org.cerberus.crud.entity.TestCaseStepActionControlExecution;2import org.cerberus.crud.entity.TestCaseStepActionExecution;3import org.cerberus.crud.entity.TestCaseStepExecution;4import java.util.List;5import java.util.ArrayList;6public class Test {7 public static void main(String[] args) {8 List<TestCaseStepExecution> testCaseStepExecutionList = new ArrayList<TestCaseStepExecution>();9 List<TestCaseStepActionExecution> testCaseStepActionExecutionList = new ArrayList<TestCaseStepActionExecution>();10 List<TestCaseStepActionControlExecution> testCaseStepActionControlExecutionList = new ArrayList<TestCaseStepActionControlExecution>();11 List<TestCaseStepActionControlExecution> testCaseStepActionControlExecutionList2 = new ArrayList<TestCaseStepActionControlExecution>();12 TestCaseStepExecution testCaseStepExecution = new TestCaseStepExecution();13 TestCaseStepActionExecution testCaseStepActionExecution = new TestCaseStepActionExecution();14 TestCaseStepActionControlExecution testCaseStepActionControlExecution = new TestCaseStepActionControlExecution();15 testCaseStepExecution.setTestCaseStepActionExecution(testCaseStepActionExecutionList);16 testCaseStepActionExecution.setTestCaseStepActionControlExecution(testCaseStepActionControlExecutionList);17 testCaseStepActionExecutionList.add(testCaseStepActionExecution);18 testCaseStepActionControlExecutionList.add(testCaseStepActionControlExecution);19 testCaseStepActionControlExecutionList2.add(testCaseStepActionControlExecution);20 testCaseStepExecutionList.add(testCaseStepExecution);21 testCaseStepActionExecution.setTestCaseStepExecution(testCaseStepExecution);22 testCaseStepActionControlExecution.setTestCaseStepActionExecution(testCaseStepActionExecution);23 testCaseStepActionControlExecution.setTestCaseStepActionExecution(testCaseStepActionExecution);24 testCaseStepActionExecution.setTestCaseStepActionControlExecution(testCaseStepActionControlExecutionList2);25 System.out.println(testCaseStepActionExecution.getTestCaseStepActionControlExecution());26 }27}28import org.cerberus.crud.entity.TestCaseStepActionExecution;29import org.cerberus.crud.entity.TestCaseStepExecution;30import java.util.ArrayList;31import java.util.List;32public class Test {33 public static void main(String[] args) {34 List<TestCaseStepExecution> testCaseStepExecutionList = new ArrayList<TestCaseStepExecution>();35 List<TestCaseStepActionExecution> testCaseStepActionExecutionList = new ArrayList<TestCaseStepActionExecution>();36 TestCaseStepExecution testCaseStepExecution = new TestCaseStepExecution();
getTestCaseStepActionExecution
Using AI Code Generation
1import org.cerberus.crud.entity.TestCaseStepActionControlExecution;2import org.cerberus.crud.entity.TestCaseStepActionExecution;3import org.cerberus.crud.entity.TestCaseStepExecution;4TestCaseStepExecution testCaseStepExecution = testCaseStepExecutionList.get(0);5TestCaseStepActionExecution testCaseStepActionExecution = testCaseStepExecution.getTestCaseStepActionExecution();6TestCaseStepActionControlExecution testCaseStepActionControlExecution = testCaseStepActionExecution.getTestCaseStepActionControlExecution();7String controlValue = testCaseStepActionControlExecution.getControlValue();8String controlProperty = testCaseStepActionControlExecution.getControlProperty();9String controlPropertyValue = testCaseStepActionControlExecution.getControlPropertyValue();10String controlPropertyValue1 = testCaseStepActionControlExecution.getControlPropertyValue1();11String controlPropertyValue2 = testCaseStepActionControlExecution.getControlPropertyValue2();12String controlPropertyValue3 = testCaseStepActionControlExecution.getControlPropertyValue3();13String controlType = testCaseStepActionControlExecution.getControlType();14String controlValue1 = testCaseStepActionControlExecution.getControlValue1();15String controlValue2 = testCaseStepActionControlExecution.getControlValue2();16String controlValue3 = testCaseStepActionControlExecution.getControlValue3();17String controlValue1Init = testCaseStepActionControlExecution.getControlValue1Init();18String controlValue2Init = testCaseStepActionControlExecution.getControlValue2Init();19String controlValue3Init = testCaseStepActionControlExecution.getControlValue3Init();
getTestCaseStepActionExecution
Using AI Code Generation
1TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();2tcsace = tcsace.getTestCaseStepActionControlExecution(1);3tcsace.setResultMessage("result message");4tcsace.setResult("KO");5tcsace.updateTestCaseStepActionControlExecution();6TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();7tcsace.setTestCaseStepActionControlExecution(1, "result message", "KO");8TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();9tcsace.setTestCaseStepActionControlExecution(1, "result message", "KO");10TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();11tcsace.setTestCaseStepActionControlExecution(1, "result message", "KO");
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!!