Best Cerberus-source code snippet using org.cerberus.engine.gwt.impl.ControlService.verifyElementInElement
Source:ControlService.java
...268 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTDIFFERENT:269 res = this.verifyElementDifferent(execution, value1, controlExecution.getValue2());270 break;271 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTINELEMENT:272 res = this.verifyElementInElement(execution, value1, controlExecution.getValue2());273 break;274 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTCLICKABLE:275 res = this.verifyElementClickable(execution, value1);276 break;277 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTCLICKABLE:278 res = this.verifyElementNotClickable(execution, value1);279 break;280 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTEQUAL:281 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTEQUAL, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());282 break;283 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTDIFFERENT:284 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTDIFFERENT, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());285 break;286 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTCONTAINS:287 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTCONTAINS, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());288 break;289 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:290 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());291 break;292 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:293 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());294 break;295 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:296 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());297 break;298 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:299 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());300 break;301 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:302 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());303 break;304 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:305 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());306 break;307 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTMATCHREGEX:308 res = this.verifyElementTextMatchRegex(execution, value1, controlExecution.getValue2());309 break;310 case TestCaseStepActionControl.CONTROL_VERIFYTEXTINPAGE:311 res = this.verifyTextInPage(execution, value1);312 break;313 case TestCaseStepActionControl.CONTROL_VERIFYTEXTNOTINPAGE:314 res = this.verifyTextNotInPage(execution, value1);315 break;316 case TestCaseStepActionControl.CONTROL_VERIFYTITLE:317 res = this.verifyTitle(execution, value1, controlExecution.getValue3());318 break;319 case TestCaseStepActionControl.CONTROL_VERIFYURL:320 res = this.verifyUrl(execution, value1);321 break;322 case TestCaseStepActionControl.CONTROL_VERIFYTEXTINDIALOG:323 res = this.verifyTextInDialog(execution, value1, controlExecution.getValue2());324 break;325 case TestCaseStepActionControl.CONTROL_VERIFYXMLTREESTRUCTURE:326 res = this.verifyXmlTreeStructure(execution, value1, controlExecution.getValue2());327 break;328 case TestCaseStepActionControl.CONTROL_TAKESCREENSHOT:329 res = this.takeScreenshot(execution, controlExecution.getTestCaseStepActionExecution(), controlExecution, value1);330 break;331 case TestCaseStepActionControl.CONTROL_GETPAGESOURCE:332 res = this.getPageSource(execution, controlExecution.getTestCaseStepActionExecution(), controlExecution);333 break;334 default:335 res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_UNKNOWNCONTROL);336 res.resolveDescription("CONTROL", controlExecution.getControl());337 }338 } catch (final CerberusEventException exception) {339 res = exception.getMessageError();340 } catch (final Exception unexpected) {341 LOG.debug("Unexpected exception on control!", unexpected);342 res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC).resolveDescription("ERROR", unexpected.getMessage());343 }344 // Reset Timeout to default345 robotServerService.setOptionsToDefault(execution.getSession());346 controlExecution.setControlResultMessage(res);347 /*348 * Updating Control result message only if control is not successful.349 * This is to keep the last KO information and preventing KO to be350 * transformed to OK.351 */352 if (!(res.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS)))) {353 controlExecution.setExecutionResultMessage(new MessageGeneral(res.getMessage()));354 }355 /*356 * We only stop the test if Control Event message is in stop status AND357 * the control is FATAL. If control is not fatal, we continue the test358 * but refresh the Execution status.359 */360 if (res.isStopTest() && controlExecution.getFatal().equals("Y")) {361 controlExecution.setStopExecution(true);362 }363 controlExecution.setEnd(new Date().getTime());364 return controlExecution;365 }366 private MessageEvent verifyStringDifferent(String value1, String value2, String isCaseSensitive) {367 MessageEvent mes;368 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? !value1.equals(value2) : !value1.equalsIgnoreCase(value2)) {369 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_STRINGDIFFERENT);370 } else {371 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_STRINGDIFFERENT);372 }373 mes.resolveDescription("STRING1", value1);374 mes.resolveDescription("STRING2", value2);375 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));376 return mes;377 }378 private MessageEvent verifyStringEqual(String value1, String value2, String isCaseSensitive) {379 MessageEvent mes;380 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? value1.equals(value2) : value1.equalsIgnoreCase(value2)) {381 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_STRINGEQUAL);382 } else {383 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_STRINGEQUAL);384 }385 mes.resolveDescription("STRING1", value1);386 mes.resolveDescription("STRING2", value2);387 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));388 return mes;389 }390 private MessageEvent verifyStringContains(String value1, String value2, String isCaseSensitive) {391 MessageEvent mes;392 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? value1.contains(value2) : value1.toLowerCase().contains(value2.toLowerCase())) {393 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_CONTAINS);394 } else {395 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CONTAINS);396 }397 mes.resolveDescription("STRING1", value1);398 mes.resolveDescription("STRING2", value2);399 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));400 return mes;401 }402 private MessageEvent verifyStringNotContains(String value1, String value2, String isCaseSensitive) {403 MessageEvent mes;404 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? value1.contains(value2) : value1.toLowerCase().contains(value2.toLowerCase())) {405 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCONTAINS);406 } else {407 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTCONTAINS);408 }409 mes.resolveDescription("STRING1", value1);410 mes.resolveDescription("STRING2", value2);411 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));412 return mes;413 }414 private MessageEvent verifyStringGreater(String value1, String value2) {415 MessageEvent mes;416 if (value1.compareToIgnoreCase(value2) > 0) {417 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GREATER);418 } else {419 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GREATER);420 }421 mes.resolveDescription("STRING1", value1);422 mes.resolveDescription("STRING2", value2);423 return mes;424 }425 private MessageEvent verifyStringMinor(String value1, String value2) {426 MessageEvent mes;427 if (value1.compareToIgnoreCase(value2) < 0) {428 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_MINOR);429 } else {430 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_MINOR);431 }432 mes.resolveDescription("STRING1", value1);433 mes.resolveDescription("STRING2", value2);434 return mes;435 }436 private MessageEvent evaluateControlIfNumericXXX(String control, String controlValue1, String controlValue2) {437 if (LOG.isDebugEnabled()) {438 LOG.debug("Checking if Numeric Equals");439 }440 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_PENDING);441 // We first prepare the string for numeric conversion to replace , by .442 String newControlValue1 = StringUtil.prepareToNumeric(controlValue1);443 String newControlValue2 = StringUtil.prepareToNumeric(controlValue2);444 // We try to convert the strings value1 to numeric.445 Double value1;446 try {447 value1 = Double.valueOf(newControlValue1);448 } catch (NumberFormatException nfe) {449 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);450 mes.resolveDescription("COND", control);451 mes.resolveDescription("STRINGVALUE", newControlValue1);452 return mes;453 }454 // We try to convert the strings value2 to numeric.455 Double value2;456 try {457 value2 = Double.valueOf(newControlValue2);458 } catch (NumberFormatException nfe) {459 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);460 mes.resolveDescription("COND", control);461 mes.resolveDescription("STRINGVALUE", newControlValue2);462 return mes;463 }464 // Now that both values are converted to double we check the operator here.465 switch (control) {466 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICEQUALS:467 if (Objects.equals(value1, value2)) {468 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_EQUAL);469 } else {470 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_EQUAL);471 }472 break;473 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICDIFFERENT:474 if (!(Objects.equals(value1, value2))) {475 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_DIFFERENT);476 } else {477 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_DIFFERENT);478 }479 break;480 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATER:481 if (value1 > value2) {482 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GREATER);483 } else {484 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GREATER);485 }486 break;487 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATEROREQUAL:488 if (value1 >= value2) {489 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GREATEROREQUAL);490 } else {491 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GREATEROREQUAL);492 }493 break;494 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOR:495 if (value1 < value2) {496 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_MINOR);497 } else {498 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_MINOR);499 }500 break;501 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOROREQUAL:502 if (value1 <= value2) {503 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_MINOROREQUAL);504 } else {505 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_MINOROREQUAL);506 }507 break;508 default:509 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED);510 }511 mes.resolveDescription("COND", control);512 mes.resolveDescription("STRING1", value1.toString());513 mes.resolveDescription("STRING2", value2.toString());514 return mes;515 }516 private MessageEvent verifyElementPresent(TestCaseExecution tCExecution, String elementPath) {517 LOG.debug("Control: verifyElementPresent on: {}", elementPath);518 MessageEvent mes;519 if (!StringUtil.isNull(elementPath)) {520 Identifier identifier = identifierService.convertStringToIdentifier(elementPath);521 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)522 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)523 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {524 try {525 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {526 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator(), "");527 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {528 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), "", identifier.getLocator());529 } else if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {530 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);531 mes.resolveDescription("STRING1", elementPath);532 return mes;533 } else {534 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);535 mes.resolveDescription("STRING1", elementPath);536 return mes;537 }538 } catch (WebDriverException exception) {539 return parseWebDriverException(exception);540 }541 } else if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {542 if (tCExecution.getLastServiceCalled() != null) {543 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();544 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {545 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:546 if (xmlUnitService.isElementPresent(responseBody, elementPath)) {547 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);548 } else {549 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);550 }551 mes.resolveDescription("STRING1", elementPath);552 return mes;553 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {554 try {555 //Return of getFromJson can be "[]" in case when the path has this pattern "$..ex" and no elements found. Two dots after $ return a list.556 if (!jsonService.getFromJson(responseBody, null, elementPath).equals("[]")) {557 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);558 mes.resolveDescription("STRING1", elementPath);559 return mes;560 } else {561 throw new PathNotFoundException();562 }563 } catch (PathNotFoundException ex) {564 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);565 mes.resolveDescription("STRING1", elementPath);566 return mes;567 } catch (Exception ex) {568 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);569 mes.resolveDescription("ERROR", ex.toString());570 return mes;571 }572 }573 default:574 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);575 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());576 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT);577 return mes;578 }579 } else {580 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);581 return mes;582 }583 } else if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_FAT)) {584 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {585 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator(), "");586 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {587 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), "", identifier.getLocator());588 } else {589 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION_AND_IDENTIFIER);590 mes.resolveDescription("IDENTIFIER", identifier.getIdentifier());591 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT);592 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());593 return mes;594 }595 } else {596 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);597 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT);598 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());599 return mes;600 }601 } else {602 return new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT_NULL);603 }604 }605 private MessageEvent verifyElementNotPresent(TestCaseExecution execution, String elementPath) {606 LOG.debug("Control: verifyElementNotPresent on: {}", elementPath);607 MessageEvent mes;608 if (!StringUtil.isNull(elementPath)) {609 Identifier identifier = identifierService.convertStringToIdentifier(elementPath);610 if (execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)611 || execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)612 || execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {613 try {614 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {615 return sikuliService.doSikuliVerifyElementNotPresent(execution.getSession(), identifier.getLocator(), "");616 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {617 return sikuliService.doSikuliVerifyElementNotPresent(execution.getSession(), "", identifier.getLocator());618 } else if (!this.webdriverService.isElementPresent(execution.getSession(), identifier)) {619 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);620 } else {621 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);622 }623 mes.resolveDescription("STRING1", elementPath);624 return mes;625 } catch (WebDriverException exception) {626 return parseWebDriverException(exception);627 }628 } else if (execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_FAT)) {629 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {630 return sikuliService.doSikuliVerifyElementNotPresent(execution.getSession(), identifier.getLocator(), "");631 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {632 return sikuliService.doSikuliVerifyElementNotPresent(execution.getSession(), "", identifier.getLocator());633 } else {634 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION_AND_IDENTIFIER);635 mes.resolveDescription("IDENTIFIER", identifier.getIdentifier());636 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT);637 mes.resolveDescription("APPLICATIONTYPE", execution.getAppTypeEngine());638 return mes;639 }640 } else if (execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {641 if (execution.getLastServiceCalled() != null) {642 String responseBody = execution.getLastServiceCalled().getResponseHTTPBody();643 switch (execution.getLastServiceCalled().getResponseHTTPBodyContentType()) {644 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:645 if (!(xmlUnitService.isElementPresent(responseBody, elementPath))) {646 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);647 } else {648 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);649 }650 mes.resolveDescription("STRING1", elementPath);651 return mes;652 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {653 try {654 //Return of getFromJson can be "[]" in case when the path has this pattern "$..ex" and no elements found. Two dots after $ return a list.655 if (!jsonService.getFromJson(responseBody, null, elementPath).equals("[]")) {656 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);657 mes.resolveDescription("STRING1", elementPath);658 return mes;659 } else {660 throw new PathNotFoundException();661 }662 } catch (PathNotFoundException ex) {663 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);664 mes.resolveDescription("STRING1", elementPath);665 return mes;666 } catch (Exception ex) {667 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);668 mes.resolveDescription("ERROR", ex.toString());669 return mes;670 }671 }672 default:673 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);674 mes.resolveDescription("TYPE", execution.getLastServiceCalled().getResponseHTTPBodyContentType());675 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT);676 return mes;677 }678 } else {679 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);680 return mes;681 }682 } else {683 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);684 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT);685 mes.resolveDescription("APPLICATIONTYPE", execution.getAppTypeEngine());686 return mes;687 }688 } else {689 return new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT_NULL);690 }691 }692 private MessageEvent verifyElementInElement(TestCaseExecution tCExecution, String element, String childElement) {693 LOG.debug("Control: verifyElementInElement on: '{}' is child of '{}'", element, childElement);694 MessageEvent mes;695 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)696 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)) {697 if (!StringUtil.isNull(element) && !StringUtil.isNull(childElement)) {698 try {699 Identifier identifier = identifierService.convertStringToIdentifier(element);700 Identifier childIdentifier = identifierService.convertStringToIdentifier(childElement);701 if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {702 if (this.webdriverService.isElementInElement(tCExecution.getSession(), identifier, childIdentifier)) {703 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTINELEMENT);704 } else {705 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTINELEMENT);706 }707 mes.resolveDescription("STRING2", element);...
Source:ControlServiceTest.java
...775 String property = "id=test";776 String value = "null";777 String msg = "Element '" + value + "' is not child of element '" + property + "'.";778 TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();779 tcsace.setControl("verifyElementInElement");780 tcsace.setValue1(property);781 tcsace.setValue2(value);782 tcsace.setFatal("Y");783 TestCaseStepExecution tcse = new TestCaseStepExecution();784 tcse.settCExecution(tCExecution);785 TestCaseStepActionExecution tcsae = new TestCaseStepActionExecution();786 tcsae.setTestCaseStepExecution(tcse);787 tcsace.setTestCaseStepActionExecution(tcsae);788 this.controlService.doControl(tcsace);789 Assert.assertEquals(msg, tcsace.getControlResultMessage().getDescription());790 Assert.assertEquals("KO", tcsace.getReturnCode());791 Assert.assertEquals("Y", tcsace.getFatal());792 }793 @Test794 public void testDoControlElementInElementWhenPropertyIsNull() {795 String property = "null";796 String value = "id=test";797 String msg = "Element '" + value + "' is not child of element '" + property + "'.";798 TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();799 tcsace.setControl("verifyElementInElement");800 tcsace.setValue1(property);801 tcsace.setValue2(value);802 tcsace.setFatal("Y");803 TestCaseStepExecution tcse = new TestCaseStepExecution();804 tcse.settCExecution(tCExecution);805 TestCaseStepActionExecution tcsae = new TestCaseStepActionExecution();806 tcsae.setTestCaseStepExecution(tcse);807 tcsace.setTestCaseStepActionExecution(tcsae);808 this.controlService.doControl(tcsace);809 Assert.assertEquals(msg, tcsace.getControlResultMessage().getDescription());810 Assert.assertEquals("KO", tcsace.getReturnCode());811 Assert.assertEquals("Y", tcsace.getFatal());812 }813// @Ignore814// @Test815// public void testDoControlElementInElementWhenValueIsNotChildOfProperty() {816// String property = "id=parent";817// String value = "id=child";818// String msg = "Element '" + value + "' is not child of element '" + property + "'.";819// Identifier identifier = new Identifier();820// identifier.setIdentifier("id");821// identifier.setLocator("test");822// Identifier identifierValue = new Identifier();823// identifier.setIdentifier("id");824// identifier.setLocator("test2");825//826// when(webdriverService.isElementInElement(session, identifier, identifierValue)).thenReturn(Boolean.FALSE);827//828// TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();829// tcsace.setControl("verifyElementInElement");830// tcsace.setValue1(property);831// tcsace.setValue2(value);832// tcsace.setFatal("Y");833// TestCaseStepExecution tcse = new TestCaseStepExecution();834// tcse.settCExecution(tCExecution);835// TestCaseStepActionExecution tcsae = new TestCaseStepActionExecution();836// tcsae.setTestCaseStepExecution(tcse);837// tcsace.setTestCaseStepActionExecution(tcsae);838//839// this.controlService.doControl(tcsace);840//841// Assert.assertEquals(msg, tcsace.getControlResultMessage().getDescription());842// Assert.assertEquals("KO", tcsace.getReturnCode());843// Assert.assertEquals("Y", tcsace.getFatal());844// }845//846// @Ignore847// @Test848// public void testDoControlElementInElementWhenValueIsChildOfProperty() {849// String property = "id=parent";850// String value = "id=child";851// String msg = "Element '" + value + "' in child of element '" + property + "'.";852// Identifier identifier = new Identifier();853// identifier.setIdentifier("id");854// identifier.setLocator("test");855// Identifier identifierValue = new Identifier();856// identifier.setIdentifier("id");857// identifier.setLocator("test2");858//859// when(webdriverService.isElementInElement(session, identifier, identifierValue)).thenReturn(Boolean.TRUE);860//861// TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();862// tcsace.setControl("verifyElementInElement");863// tcsace.setValue1(property);864// tcsace.setValue2(value);865// tcsace.setFatal("Y");866// TestCaseStepExecution tcse = new TestCaseStepExecution();867// tcse.settCExecution(tCExecution);868// TestCaseStepActionExecution tcsae = new TestCaseStepActionExecution();869// tcsae.setTestCaseStepExecution(tcse);870// tcsace.setTestCaseStepActionExecution(tcsae);871//872// this.controlService.doControl(tcsace);873//874// Assert.assertEquals(msg, tcsace.getControlResultMessage().getDescription());875// Assert.assertEquals("OK", tcsace.getReturnCode());876// Assert.assertEquals("Y", tcsace.getFatal());...
verifyElementInElement
Using AI Code Generation
1package org.cerberus.engine.gwt.impl;2import java.util.ArrayList;3import java.util.List;4import org.cerberus.engine.entity.Identifier;5import org.cerberus.engine.entity.SeleniumAction;6import org.cerberus.engine.entity.TestCaseStepActionControl;7import org.cerberus.engine.gwt.IControlService;8import org.cerberus.engine.gwt.IFactorySelenium;9import org.cerberus.engine.gwt.IPropertyService;10import org.cerberus.engine.gwt.ISeleniumService;11import org.cerberus.exception.CerberusException;12import org.cerberus.util.answer.Answer;13import org.cerberus.util.answer.AnswerItem;14import org.openqa.selenium.By;15import org.openqa.selenium.WebDriver;16import org.openqa.selenium.WebElement;17import org.openqa.selenium.support.ui.ExpectedCondition;18import org.openqa.selenium.support.ui.Select;19import org.openqa.selenium.support.ui.WebDriverWait;20import org.springframework.beans.factory.annotation.Autowired;21import org.springframework.stereotype.Service;22public class ControlService implements IControlService {23 private IFactorySelenium factorySelenium;24 private IPropertyService propertyService;25 private ISeleniumService seleniumService;26 public AnswerItem<Boolean> verifyElementInElement(TestCaseStepActionControl testCaseStepActionControl, boolean isNot) throws CerberusException {27 AnswerItem<Boolean> answer = new AnswerItem<>();28 try {29 WebDriver driver = factorySelenium.getDriver();30 String property = testCaseStepActionControl.getValue1();31 String property2 = testCaseStepActionControl.getValue2();32 String property3 = testCaseStepActionControl.getValue3();33 String property4 = testCaseStepActionControl.getValue4();34 String property5 = testCaseStepActionControl.getValue5();35 String property6 = testCaseStepActionControl.getValue6();36 String property7 = testCaseStepActionControl.getValue7();37 String property8 = testCaseStepActionControl.getValue8();38 String property9 = testCaseStepActionControl.getValue9();39 String property10 = testCaseStepActionControl.getValue10();40 String property11 = testCaseStepActionControl.getValue11();41 String property12 = testCaseStepActionControl.getValue12();42 String control = testCaseStepActionControl.getControl();43 String controlProperty = testCaseStepActionControl.getControlProperty();44 String controlProperty2 = testCaseStepActionControl.getControlProperty2();
verifyElementInElement
Using AI Code Generation
1import org.cerberus.engine.gwt.impl.ControlService;2import org.cerberus.engine.gwt.impl.PageService;3import org.cerberus.engine.gwt.impl.TestCaseService;4import org.cerberus.engine.gwt.impl.TestService;5import org.cerberus.exception.CerberusException;6import org.cerberus.exception.CerberusFunctionalException;7import org.cerberus.exception.CerberusRobotException;8import org.cerberus.util.answer.Answer;9import org.cerberus.util.answer.AnswerItem;10import org.cerberus.util.answer.AnswerList;11import org.cerberus.util.answer.AnswerUtil;12import org.cerberus.util.answer.AnswerUtil;13import org.openqa.selenium.By;14import org.openqa.selenium.WebDriver;15import org.openqa.selenium.WebElement;16import org.openqa.selenium.support.ui.Select;17import org.openqa.selenium.support.ui.WebDriverWait;18import org.openqa.selenium.support.ui.ExpectedConditions;19import org.openqa.selenium.WebDriver;20import org.openqa.selenium.firefox.FirefoxDriver;21import org.openqa.selenium.JavascriptExecutor;22import org.openqa.selenium.WebDriver;23import org.openqa.selenium.firefox.FirefoxDriver;24import org.open
verifyElementInElement
Using AI Code Generation
1package org.cerberus.test;2import org.cerberus.engine.gwt.impl.ControlService;3public class TestVerifyElementInElement {4 public static void main(String[] args) throws Exception {5 ControlService controlService = new ControlService();6 controlService.setBrowser("firefox");7 controlService.setWaitTime(5000);8 controlService.start();9 controlService.verifyElementInElement("id", "lst-ib", "id", "gbqfq");10 controlService.stop();11 }12}13package org.cerberus.test;14import org.cerberus.engine.gwt.impl.ControlService;15public class TestVerifyElementInElement {16 public static void main(String[] args) throws Exception {17 ControlService controlService = new ControlService();18 controlService.setBrowser("firefox");19 controlService.setWaitTime(5000);20 controlService.start();21 controlService.verifyElementInElement("id", "lst-ib", "id", "gbqfq");22 controlService.stop();23 }24}25package org.cerberus.test;26import org.cerberus.engine.gwt.impl.ControlService;27public class TestVerifyElementInElement {28 public static void main(String[] args) throws Exception {29 ControlService controlService = new ControlService();30 controlService.setBrowser("firefox");31 controlService.setWaitTime(5000);32 controlService.start();33 controlService.verifyElementInElement("id", "lst-ib", "id", "gbqfq");34 controlService.stop();35 }36}37package org.cerberus.test;38import org.cerberus.engine.gwt.impl.ControlService;39public class TestVerifyElementInElement {40 public static void main(String[] args) throws Exception {41 ControlService controlService = new ControlService();
verifyElementInElement
Using AI Code Generation
1package com.cerberus.test;2import java.util.List;3import org.cerberus.engine.gwt.impl.ControlService;4import org.cerberus.engine.gwt.impl.GuiService;5import org.cerberus.engine.gwt.impl.PageService;6import org.cerberus.engine.gwt.impl.TestService;7import org.cerberus.engine.gwt.impl.VariableService;8import org.cerberus.engine.gui.impl.SeleniumGuiImpl;9import org.cerberus.engine.gui.impl.SeleniumPageImpl;10import org.cerberus.engine.gui.impl.SeleniumTestImpl;11import org.cerberus.engine.gui.impl.SeleniumVariableImpl;12import org.cerberus.event.IEventService;13import org.cerberus.exception.CerberusException;14import org.cerberus.factory.IFactoryTest;15import org.cerberus.factory.impl.FactoryTest;16import org.cerberus.gui.ICerberusGUI;17import org.cerberus.gui.impl.CerberusGUI;18import org.cerberus.page.IPage;19import org.cerberus.page.IPageService;20import org.cerberus.page.impl.Page;21import org.cerberus.service.ISeleniumService;22import org.cerberus.service.impl.SeleniumService;23import org.cerberus.util.answer.AnswerItem;24import org.cerberus.util.answer.AnswerList;25import org.openqa.selenium.By;26import org.openqa.selenium.WebDriver;27import org.openqa.selenium.WebElement;28public class test {29 public static void main(String[] args) throws CerberusException {30 ISeleniumService seleniumService = new SeleniumService();31 IEventService eventService = null;32 ICerberusGUI cerberusGUI = new CerberusGUI();33 IFactoryTest factoryTest = new FactoryTest();34 IPageService pageService = new PageService();35 TestService testService = new TestService();36 GuiService guiService = new GuiService();37 ControlService controlService = new ControlService();38 VariableService variableService = new VariableService();39 SeleniumVariableImpl seleniumVariableImpl = new SeleniumVariableImpl();40 SeleniumPageImpl seleniumPageImpl = new SeleniumPageImpl();41 SeleniumTestImpl seleniumTestImpl = new SeleniumTestImpl();42 SeleniumGuiImpl seleniumGuiImpl = new SeleniumGuiImpl();43 WebDriver driver = null;44 String object = "q";
verifyElementInElement
Using AI Code Generation
1package com.cerberus.test;2import org.cerberus.engine.gwt.impl.ControlService;3import org.cerberus.engine.gwt.impl.ControlServiceFactory;4import org.cerberus.engine.gwt.impl.ControlServiceFactory.ControlServiceType;5import org.cerberus.engine.gwt.impl.ControlServiceFactory.ControlServiceType.ControlServiceTypeValue;6import org.cerberus.engine.gwt.impl.ControlServiceFactory.ControlServiceType.ControlServiceTypeValue.ControlServiceTypeValueValue;7import org.cerberus.engine.gwt.impl.ControlServiceFactory.ControlServiceType.ControlServiceTypeValue.ControlServiceTypeValueValue.ControlServiceTypeValueValueValue;8import org.cerberus.engine.gwt.impl.ControlServiceFactory.ControlServiceType.ControlServiceTypeValue.ControlServiceTypeValueValue.ControlServiceTypeValueValueValue.ControlServiceTypeValueValueValueValue;9import org.cerberus.engine.gwt.impl.ControlServiceFactory.ControlServiceType.ControlServiceTypeValue.ControlServiceTypeValueValue.ControlServiceTypeValueValueValue.ControlServiceTypeValueValueValueValue.ControlServiceTypeValueValueValueValueValue;10import org.cerberus.engine.gwt.impl.ControlServiceFactory.ControlServiceType.ControlServiceTypeValue.ControlServiceTypeValueValue.ControlServiceTypeValueValueValue.ControlServiceTypeValueValueValueValue.ControlServiceTypeValueValueValueValueValue.ControlServiceTypeValueValueValueValueValueValue;11import org.cerberus.engine.gwt.impl.ControlServiceFactory.ControlServiceType.ControlServiceTypeValue.ControlServiceTypeValueValue.ControlServiceTypeValueValueValue.ControlServiceTypeValueValueValueValue.ControlServiceTypeValueValueValueValueValue.ControlServiceTypeValueValueValueValueValueValue.ControlServiceTypeValueValueValueValueValueValueValue;12import org.cerberus.engine.gwt.impl.ControlServiceFactory.ControlServiceType.ControlServiceTypeValue.ControlServiceTypeValueValue.ControlServiceTypeValueValueValue.ControlServiceTypeValueValueValueValue.ControlServiceTypeValueValueValueValueValue.ControlServiceTypeValueValueValueValueValueValue.ControlServiceTypeValueValueValueValueValueValueValue.ControlServiceTypeValueValueValueValueValueValueValueValue;13import org.cerberus.engine.gwt.impl.ControlServiceFactory.ControlServiceType.ControlServiceTypeValue.ControlServiceTypeValueValue.ControlServiceTypeValueValueValue.ControlServiceTypeValueValueValueValue.ControlServiceTypeValueValueValueValueValue.ControlServiceTypeValueValueValueValueValueValue.ControlServiceTypeValueValueValueValueValueValueValue.ControlServiceTypeValueValueValueValueValueValueValueValue.ControlServiceTypeValueValueValueValueValueValueValueValueValue;14import org.cerber
verifyElementInElement
Using AI Code Generation
1package com.cerberus.example;2import org.cerberus.engine.CerberusEngine;3import org.cerberus.engine.gwt.impl.ControlService;4import org.cerberus.engine.gwt.impl.ElementService;5import org.cerberus.engine.gwt.impl.PageService;6import org.cerberus.enums.ByVal;7import org.cerberus.enums.PlatformType;8import org.cerberus.event.Event;9import org.cerberus.event.IEvent;10import org.cerberus.exception.CerberusException;11import org.cerberus.launcher.Cerberus;12import org.cerberus.launcher.ICerberus;13import org.cerberus.utils.CerberusProperties;14public class 3 {15 public static void main(String[] args) throws CerberusException {16 ICerberus cerberus = Cerberus.getInstance();17 cerberus.init(CerberusProperties.getInstance());18 CerberusEngine cerberusEngine = new CerberusEngine(PlatformType.DESKTOP);19 PageService pageService = new PageService(cerberusEngine);20 ControlService controlService = new ControlService(cerberusEngine);21 ElementService elementService = new ElementService(cerberusEngine);22 IEvent event = new Event();23 System.out.println("Element present in the parent element: " + elementPresent);24 cerberusEngine.quit();25 }26}
verifyElementInElement
Using AI Code Generation
1package org.cerberus.engine.gwt.impl;2import com.google.gwt.dom.client.Element;3import com.google.gwt.dom.client.Node;4import com.google.gwt.dom.client.NodeList;5import com.google.gwt.user.client.DOM;6import com.google.gwt.user.client.ui.UIObject;7import org.cerberus.engine.gwt.IControlService;8public class ControlService implements IControlService {9 public ControlService() {10 }11 public boolean verifyElementInElement(Element parent, Element child) {12 NodeList nl = parent.getChildNodes();13 for (int i = 0; i < nl.getLength(); i++) {14 Node node = nl.getItem(i);15 if (node.getNodeType() == 1) {16 Element e = (Element) node;17 if (e == child) {18 return true;19 }20 if (verifyElementInElement(e, child)) {21 return true;22 }23 }24 }25 return false;26 }27 public boolean verifyElementInElement(UIObject parent, UIObject child) {28 return verifyElementInElement(parent.getElement(), child.getElement());29 }30 public boolean verifyElementInElement(String parent, String child) {31 return verifyElementInElement(DOM.getElementById(parent), DOM.getElementById(child));32 }33}34package org.cerberus.engine.gwt.impl;35import com.google.gwt.user.client.ui.UIObject;36import org.cerberus.engine.gwt.IControlService;37public class ControlService implements IControlService {38 public ControlService() {39 }40 public boolean verifyElementInElement(UIObject parent, UIObject child) {41 return false;42 }43 public boolean verifyElementInElement(String parent, String child) {44 return false;45 }46}47package org.cerberus.engine.gwt.impl;48import org.cerberus.engine.gwt.IControlService;
verifyElementInElement
Using AI Code Generation
1package org.cerberus.test;2import org.cerberus.engine.gwt.impl.ControlService;3import org.cerberus.engine.gwt.impl.SeleniumService;4import org.cerberus.exception.CerberusException;5import org.cerberus.util.StringUtil;6import org.cerberus.util.file.FileUtil;7import org.openqa.selenium.WebDriver;8public class Test3 {9 public static void main(String[] args) throws CerberusException {10 String driverPath = FileUtil.getFilePath("src/main/resources/drivers/chromedriver.exe");11 SeleniumService seleniumService = new SeleniumService();12 ControlService controlService = new ControlService();13 WebDriver driver = seleniumService.getWebDriver(driverPath);14 boolean result = controlService.verifyElementInElement(driver, element, parentElement);15 System.out.println("The result is : " + result);16 driver.close();17 }18}
verifyElementInElement
Using AI Code Generation
1package org.cerberus.test;2import org.cerberus.engine.entity.Selenium;3import org.cerberus.engine.entity.impl.SeleniumImpl;4import org.cerberus.engine.gwt.IControlService;5import org.cerberus.engine.gwt.impl.ControlService;6import org.cerberus.exception.CerberusException;7import org.cerberus.util.ParameterParserUtil;8import org.cerberus.util.answer.AnswerUtil;9import org.openqa.selenium.WebDriver;10import org.openqa.selenium.firefox.FirefoxDriver;11public class VerifyElementInElement {12 public static void main(String[] args) throws CerberusException {13 WebDriver driver = new FirefoxDriver();14 Selenium selenium = new SeleniumImpl(driver);15 IControlService controlService = new ControlService(selenium);16 String property = "xpath";17 String subProperty = "xpath";18 controlService.verifyElementInElement(property, locator, subProperty, subLocator);19 driver.close();20 }21}22package org.cerberus.engine.gwt.impl;23import org.cerberus.engine.entity.Selenium;24import org.cerberus.engine.gwt.IControlService;25import org.cerberus.exception.CerberusException;26import org.cerberus.util.answer.AnswerUtil;27import org.openqa.selenium.By;28import org.openqa.selenium.WebElement;29public class ControlService implements IControlService {30 private Selenium selenium;31 public ControlService(Selenium selenium) {32 this.selenium = selenium;33 }34 public boolean verifyElementInElement(String property, String locator, String subProperty, String subLocator) throws CerberusException {35 boolean result = false;36 WebElement element;37 try {38 element = selenium.getDriver().findElement(By.xpath(locator));39 if (element != null) {40 element.findElement(By.xpath(subLocator));41 result = true;42 }43 } catch (Exception e) {44 result = false;45 throw new CerberusException(new AnswerUtil<>(result));46 }47 return result;48 }49}
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!!