How to use getPageSource method of org.cerberus.service.webdriver.impl.WebDriverService class

Best Cerberus-source code snippet using org.cerberus.service.webdriver.impl.WebDriverService.getPageSource

Source:ControlService.java Github

copy

Full Screen

...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);708 mes.resolveDescription("STRING1", childElement);709 } else {710 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NO_SUCH_ELEMENT);711 mes.resolveDescription("SELEX", new NoSuchElementException("").toString());712 mes.resolveDescription("ELEMENT", element);713 }714 } catch (WebDriverException exception) {715 return parseWebDriverException(exception);716 }717 } else {718 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTINELEMENT);719 mes.resolveDescription("STRING2", element);720 mes.resolveDescription("STRING1", childElement);721 }722 } else {723 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);724 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTINELEMENT);725 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());726 }727 return mes;728 }729 private MessageEvent verifyElementVisible(TestCaseExecution tCExecution, String html) {730 LOG.debug("Control: verifyElementVisible on: {}", html);731 MessageEvent mes;732 if (!StringUtil.isNull(html)) {733 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)734 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)735 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {736 try {737 Identifier identifier = identifierService.convertStringToIdentifier(html);738 if (this.webdriverService.isElementVisible(tCExecution.getSession(), identifier)) {739 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_VISIBLE);740 } else {741 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VISIBLE);742 }743 mes.resolveDescription("STRING1", html);744 } catch (WebDriverException exception) {745 return parseWebDriverException(exception);746 }747 } else {748 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);749 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTVISIBLE);750 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());751 }752 } else {753 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VISIBLE_NULL);754 }755 return mes;756 }757 private MessageEvent verifyElementNotVisible(TestCaseExecution tCExecution, String html) {758 LOG.debug("Control: verifyElementNotVisible on: {}", html);759 MessageEvent mes;760 if (!StringUtil.isNull(html)) {761 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)762 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)763 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {764 try {765 Identifier identifier = identifierService.convertStringToIdentifier(html);766 if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {767 if (this.webdriverService.isElementNotVisible(tCExecution.getSession(), identifier)) {768 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTVISIBLE);769 } else {770 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTVISIBLE);771 }772 mes.resolveDescription("STRING1", html);773 } else {774 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);775 }776 mes.resolveDescription("STRING1", html);777 } catch (WebDriverException exception) {778 return parseWebDriverException(exception);779 }780 } else {781 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);782 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTVISIBLE);783 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());784 }785 } else {786 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTVISIBLE_NULL);787 }788 return mes;789 }790 private MessageEvent verifyElementEquals(TestCaseExecution tCExecution, String xpath, String expectedElement) {791 LOG.debug("Control: verifyElementEquals on: {} expected Element: {}", xpath, expectedElement);792 MessageEvent mes;793 // If case of not compatible application then exit with error794 if (!tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {795 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);796 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTEQUALS);797 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());798 } else if (tCExecution.getLastServiceCalled() != null) {799 // Check if element on the given xpath is equal to the given expected element800 String xmlResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();801 if (AppService.RESPONSEHTTPBODYCONTENTTYPE_XML.equals(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType())) {802 mes = xmlUnitService.isElementEquals(xmlResponse, xpath, expectedElement) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTEQUALS) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTEQUALS);803 mes.resolveDescription("XPATH", xpath);804 mes.resolveDescription("EXPECTED_ELEMENT", expectedElement);805 } else {806 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);807 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());808 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTEQUALS);809 }810 } else {811 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);812 }813 return mes;814 }815 private MessageEvent verifyElementDifferent(TestCaseExecution tCExecution, String xpath, String differentElement) {816 LOG.debug("Control: verifyElementDifferent on: {} expected Element: {}", xpath, differentElement);817 MessageEvent mes = null;818 // If case of not compatible application then exit with error819 if (!tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {820 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);821 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTDIFFERENT);822 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());823 } else if (tCExecution.getLastServiceCalled() != null) {824 //Check if element on the given xpath is different from the given different element825 if (AppService.RESPONSEHTTPBODYCONTENTTYPE_XML.equals(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType())) {826 String xmlResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();827 mes = xmlUnitService.isElementEquals(xmlResponse, xpath, differentElement) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTDIFFERENT);828 mes.resolveDescription("XPATH", xpath);829 mes.resolveDescription("DIFFERENT_ELEMENT", differentElement);830 } else {831 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);832 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());833 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTDIFFERENT);834 }835 } else {836 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);837 }838 return mes;839 }840 @Override841 public MessageEvent verifyElementXXX(String control, TestCaseExecution tCExecution, String path, String expected, String isCaseSensitive) {842 LOG.debug("Control: verifyElementXXX ({}) on {} element against value: {} AppType: {}", control, path, expected, tCExecution.getAppTypeEngine());843 MessageEvent mes;844 // Get value from the path element according to the application type845 String actual;846 try {847 Identifier identifier = identifierService.convertStringToIdentifier(path);848 String applicationType = tCExecution.getAppTypeEngine();849 switch (applicationType) {850 case Application.TYPE_GUI:851 case Application.TYPE_APK:852 case Application.TYPE_IPA:853 actual = webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);854 // In case of null actual value then we alert user855 if (actual == null) {856 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NULL);857 mes.resolveDescription("STRING1", path);858 return mes;859 }860 // Get the result depending on the control required.861 mes = switchControl(control, path, actual, expected, isCaseSensitive);862 return mes;863 case Application.TYPE_SRV:864 if (tCExecution.getLastServiceCalled() != null) {865 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();866 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {867 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:868 if (!xmlUnitService.isElementPresent(responseBody, path)) {869 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);870 mes.resolveDescription("ELEMENT", path);871 return mes;872 }873 String newPath = StringUtil.addSuffixIfNotAlready(path, "/text()");874 actual = xmlUnitService.getFromXml(responseBody, newPath);875 // In case of null actual value then we alert user876 if (actual == null) {877 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NULL);878 mes.resolveDescription("ELEMENT", path);879 return mes;880 }881 // Get the result depending on the control required.882 mes = switchControl(control, path, actual, expected, isCaseSensitive);883 return mes;884 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {885 try {886 actual = jsonService.getFromJson(responseBody, null, path);887 } catch (Exception ex) {888 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);889 mes.resolveDescription("ERROR", ex.toString());890 return mes;891 }892 }893 // In case of null actual value then we alert user894 if (actual == null) {895 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);896 mes.resolveDescription("ELEMENT", path);897 return mes;898 }899 // Get the result depending on the control required.900 mes = switchControl(control, path, actual, expected, isCaseSensitive);901 return mes;902 default:903 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);904 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());905 mes.resolveDescription("CONTROL", control);906 return mes;907 }908 } else {909 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);910 return mes;911 }912 default:913 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);914 mes.resolveDescription("CONTROL", control);915 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());916 return mes;917 }918 } catch (NoSuchElementException exception) {919 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);920 mes.resolveDescription("ELEMENT", path);921 return mes;922 } catch (WebDriverException exception) {923 return parseWebDriverException(exception);924 }925 }926 private MessageEvent switchControl(String control, String path, String actual, String expected, String isCaseSensitive) {927 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);928 mes.resolveDescription("CONTROL", "switchControl-" + control);929 switch (control) {930 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTEQUAL:931 mes = verifyElementTextEqualCaseSensitiveCheck(actual, expected, isCaseSensitive);932 break;933 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTDIFFERENT:934 mes = verifyElementTextDifferentCaseSensitiveCheck(actual, expected, isCaseSensitive);935 break;936 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTCONTAINS:937 mes = verifyElementTextContainsCaseSensitiveCheck(actual, expected, isCaseSensitive);938 break;939 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:940 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:941 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:942 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:943 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:944 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:945 double value1;946 try {947 value1 = Double.parseDouble(actual);948 } catch (NumberFormatException nfe) {949 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);950 mes.resolveDescription("COND", control);951 mes.resolveDescription("STRINGVALUE", actual);952 return mes;953 }954 // We try to convert the strings value2 to numeric.955 double value2;956 try {957 value2 = Double.parseDouble(expected);958 } catch (NumberFormatException nfe) {959 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);960 mes.resolveDescription("COND", control);961 mes.resolveDescription("STRINGVALUE", expected);962 return mes;963 }964 mes = checkNumericVerifyElement(control, value1, value2);965 break;966 }967 mes.resolveDescription("ELEMENT", path);968 mes.resolveDescription("ELEMENTVALUE", actual);969 mes.resolveDescription("VALUE", expected);970 mes.resolveDescription("CASESENSITIVE", caseSensitiveMessageValue(isCaseSensitive));971 return mes;972 }973 private MessageEvent verifyElementTextEqualCaseSensitiveCheck(String actual, String expected, String isCaseSensitive) {974 MessageEvent mes;975 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {976 mes = actual.equals(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTEQUAL) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTEQUAL);977 } else {978 mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTEQUAL) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTEQUAL);979 }980 return mes;981 }982 private MessageEvent verifyElementTextDifferentCaseSensitiveCheck(String actual, String expected, String isCaseSensitive) {983 MessageEvent mes;984 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {985 mes = actual.equals(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTDIFFERENT);986 } else {987 mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTDIFFERENT);988 }989 return mes;990 }991 private MessageEvent verifyElementTextContainsCaseSensitiveCheck(String text, String textToSearch, String isCaseSensitive) {992 MessageEvent mes;993 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {994 mes = text.contains(textToSearch) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTCONTAINS) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTCONTAINS);995 } else {996 mes = text.toLowerCase().contains(textToSearch.toLowerCase()) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTCONTAINS) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTCONTAINS);997 }998 return mes;999 }1000 private MessageEvent checkNumericVerifyElement(String control, Double actual, Double expected) {1001 switch (control) {1002 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:1003 return actual.equals(expected)1004 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICEQUAL)1005 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICEQUAL);1006 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:1007 return !actual.equals(expected)1008 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICDIFFERENT)1009 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICDIFFERENT);1010 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:1011 return actual > expected1012 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICGREATER)1013 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICGREATER);1014 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:1015 return actual >= expected1016 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICGREATEROREQUAL)1017 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICGREATEROREQUAL);1018 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:1019 return actual < expected1020 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICMINOR)1021 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICMINOR);1022 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:1023 return actual <= expected1024 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICMINOROREQUAL)1025 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICMINOROREQUAL);1026 default:1027 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1028 return mes.resolveDescription("CONTROL", "checkNumericVerifyElement-" + control);1029 }1030 }1031 private MessageEvent verifyElementTextMatchRegex(TestCaseExecution tCExecution, String path, String regex) {1032 LOG.debug("Control: VerifyElementTextMatchRegex on: {} element against value: {}", path, regex);1033 MessageEvent mes;1034 String pathContent;1035 try {1036 Identifier identifier = identifierService.convertStringToIdentifier(path);1037 String applicationType = tCExecution.getAppTypeEngine();1038 // Get value from the path element according to the application type1039 if (Application.TYPE_GUI.equalsIgnoreCase(applicationType)1040 || Application.TYPE_APK.equalsIgnoreCase(applicationType)1041 || Application.TYPE_IPA.equalsIgnoreCase(applicationType)) {1042 pathContent = this.webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);1043 } else if (Application.TYPE_SRV.equalsIgnoreCase(applicationType)) {1044 if (tCExecution.getLastServiceCalled() != null) {1045 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();1046 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {1047 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:1048 if (!xmlUnitService.isElementPresent(responseBody, path)) {1049 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);1050 mes.resolveDescription("ELEMENT", path);1051 return mes;1052 }1053 String newPath = StringUtil.addSuffixIfNotAlready(path, "/text()");1054 pathContent = xmlUnitService.getFromXml(responseBody, newPath);1055 break;1056 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:1057 try {1058 pathContent = jsonService.getFromJson(responseBody, null, path);1059 } catch (Exception ex) {1060 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);1061 mes.resolveDescription("ERROR", ex.toString());1062 return mes;1063 }1064 break;1065 default:1066 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);1067 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());1068 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTMATCHREGEX);1069 return mes;1070 }1071 // TODO Give the actual element found into the description.1072 } else {1073 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);1074 return mes;1075 }1076 } else {1077 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1078 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTMATCHREGEX);1079 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1080 return mes;1081 }1082 LOG.debug("Control: VerifyElementMatchRegex element: {} has value: {}", path, StringUtil.sanitize(pathContent));1083 if (path != null && pathContent != null) {1084 try {1085 Pattern pattern = Pattern.compile(regex);1086 Matcher matcher = pattern.matcher(pathContent);1087 if (matcher.find()) {1088 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_REGEXINELEMENT);1089 } else {1090 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT);1091 }1092 mes.resolveDescription("STRING1", path);1093 mes.resolveDescription("STRING2", StringUtil.sanitize(pathContent));1094 mes.resolveDescription("STRING3", regex);1095 } catch (PatternSyntaxException e) {1096 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_INVALIDPATTERN);1097 mes.resolveDescription("PATTERN", regex);1098 mes.resolveDescription("ERROR", e.getMessage());1099 }1100 } else if (pathContent != null) {1101 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NULL);1102 } else {1103 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NO_SUCH_ELEMENT);1104 mes.resolveDescription("ELEMENT", path);1105 }1106 } catch (NoSuchElementException exception) {1107 LOG.debug(exception.toString());1108 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NO_SUCH_ELEMENT);1109 mes.resolveDescription("ELEMENT", path);1110 } catch (WebDriverException exception) {1111 return parseWebDriverException(exception);1112 }1113 return mes;1114 }1115 private MessageEvent verifyTextInDialog(TestCaseExecution tCExecution, String property, String value) {1116 LOG.debug("Control: verifyTextInDialog against value: {}", value);1117 MessageEvent mes;1118 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1119 try {1120 String str = this.webdriverService.getAlertText(tCExecution.getSession());1121 LOG.debug("Control: verifyTextInAlertPopup has value: {}", str);1122 if (str != null) {1123 String valueToTest = property;1124 if (valueToTest == null || "".equals(valueToTest.trim())) {1125 valueToTest = value;1126 }1127 if (str.trim().equalsIgnoreCase(valueToTest)) {1128 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTINALERT);1129 } else {1130 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINALERT);1131 }1132 mes.resolveDescription("STRING1", str);1133 mes.resolveDescription("STRING2", valueToTest);1134 } else {1135 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINALERT_NULL);1136 }1137 } catch (WebDriverException exception) {1138 return parseWebDriverException(exception);1139 }1140 } else {1141 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1142 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYTEXTINDIALOG);1143 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1144 }1145 return mes;1146 }1147 private MessageEvent verifyTextInPage(TestCaseExecution tCExecution, String regex) {1148 LOG.debug("Control: verifyTextInPage on : {}", regex);1149 MessageEvent mes;1150 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())1151 || Application.TYPE_APK.equalsIgnoreCase(tCExecution.getAppTypeEngine())1152 || Application.TYPE_IPA.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1153 String pageSource;1154 try {1155 pageSource = this.webdriverService.getPageSource(tCExecution.getSession());1156 LOG.debug(pageSource);1157 Pattern pattern = Pattern.compile(regex);1158 Matcher matcher = pattern.matcher(pageSource);1159 if (matcher.find()) {1160 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTINPAGE);1161 } else {1162 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINPAGE);1163 }1164 mes.resolveDescription("STRING1", Pattern.quote(regex));1165 } catch (PatternSyntaxException e) {1166 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINPAGE_INVALIDPATTERN);1167 mes.resolveDescription("PATTERN", Pattern.quote(regex));1168 mes.resolveDescription("ERROR", e.getMessage());1169 } catch (WebDriverException exception) {1170 return parseWebDriverException(exception);1171 }1172 } else if (Application.TYPE_FAT.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1173 mes = sikuliService.doSikuliVerifyTextInPage(tCExecution.getSession(), regex);1174 } else {1175 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1176 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYTEXTINPAGE);1177 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1178 }1179 return mes;1180 }1181 private MessageEvent verifyTextNotInPage(TestCaseExecution tCExecution, String regex) {1182 LOG.debug("Control: VerifyTextNotInPage on: {}", regex);1183 MessageEvent mes;1184 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())1185 || Application.TYPE_APK.equalsIgnoreCase(tCExecution.getAppTypeEngine())1186 || Application.TYPE_IPA.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1187 String pageSource;1188 try {1189 pageSource = this.webdriverService.getPageSource(tCExecution.getSession());1190 LOG.debug(pageSource);1191 Pattern pattern = Pattern.compile(regex);1192 Matcher matcher = pattern.matcher(pageSource);1193 if (!(matcher.find())) {1194 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTNOTINPAGE);1195 } else {1196 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINPAGE);1197 }1198 mes.resolveDescription("STRING1", Pattern.quote(regex));1199 } catch (PatternSyntaxException e) {1200 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINPAGE_INVALIDPATTERN);1201 mes.resolveDescription("PATTERN", Pattern.quote(regex));1202 mes.resolveDescription("ERROR", e.getMessage());1203 } catch (WebDriverException exception) {1204 return parseWebDriverException(exception);1205 }1206 } else {1207 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1208 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYTEXTNOTINPAGE);1209 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1210 }1211 return mes;1212 }1213 private MessageEvent verifyUrl(TestCaseExecution tCExecution, String value1) throws CerberusEventException {1214 LOG.debug("Control: verifyUrl on: {}", value1);1215 MessageEvent mes;1216 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1217 String url;1218 // Control is made forcing the / at the beginning of URL. getCurrentUrl from Selenium1219 // already have that control but value1 is specified by user and could miss it.1220 final String controlUrl = StringUtil.addPrefixIfNotAlready(value1, "/");1221 try {1222 LOG.debug("Before wait: {}", System.currentTimeMillis());1223 WebDriverWait wait = new WebDriverWait(tCExecution.getSession().getDriver(),1224 TimeUnit.MILLISECONDS.toSeconds(tCExecution.getSession().getCerberus_selenium_wait_element()));1225 //Wait until the url is the expected one1226 wait.until(new Function<WebDriver, Boolean>() {1227 final String expectedValue = controlUrl;1228 @Override1229 public Boolean apply(WebDriver driver) {1230 String value = "";1231 try {1232 value = webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());1233 LOG.debug("Get new url: {} >> Expected url: {}", value, expectedValue);1234 } catch (CerberusEventException ex) {1235 LOG.warn(ex.getMessageError().getDescription());1236 }1237 return value.equalsIgnoreCase(expectedValue);1238 }1239 });1240 LOG.debug("After wait: {}", System.currentTimeMillis());1241 url = this.webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());1242 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_URL);1243 mes.resolveDescription("STRING1", url);1244 } catch (TimeoutException exception) {1245 url = this.webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());1246 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_URL);1247 mes.resolveDescription("STRING1", url);1248 } catch (WebDriverException exception) {1249 return parseWebDriverException(exception);1250 }1251 mes.resolveDescription("STRING2", controlUrl);1252 } else {1253 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1254 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYURL);1255 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1256 }1257 return mes;1258 }1259 private MessageEvent verifyTitle(TestCaseExecution tCExecution, String title, String isCaseSensitive) {1260 LOG.debug("Control: verifyTitle on: {}", title);1261 MessageEvent mes;1262 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1263 String pageTitle = this.webdriverService.getTitle(tCExecution.getSession());1264 try {1265 LOG.debug("Before wait {}", System.currentTimeMillis());1266 WebDriverWait wait = new WebDriverWait(tCExecution.getSession().getDriver(),1267 TimeUnit.MILLISECONDS.toSeconds(tCExecution.getSession().getCerberus_selenium_wait_element()));1268 //Wait until the title is the expected one1269 wait.until(new Function<WebDriver, Boolean>() {1270 final String expectedValue = title;1271 @Override1272 public Boolean apply(WebDriver driver) {1273 String value = webdriverService.getTitle(tCExecution.getSession());1274 LOG.debug("Get new title: {} >> Expected title: {}", value, expectedValue);1275 return ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? expectedValue.equals(value) : expectedValue.equalsIgnoreCase(value);1276 }1277 });1278 LOG.debug("After wait {}", System.currentTimeMillis());1279 pageTitle = this.webdriverService.getTitle(tCExecution.getSession());1280 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TITLE);1281 } catch (TimeoutException exception) {1282 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TITLE);1283 } catch (WebDriverException exception) {1284 return parseWebDriverException(exception);1285 }1286 mes.resolveDescription("STRING1", pageTitle);1287 mes.resolveDescription("STRING2", title);1288 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));1289 } else {1290 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1291 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYTITLE);1292 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1293 }1294 return mes;1295 }1296 private MessageEvent verifyXmlTreeStructure(TestCaseExecution tCExecution, String controlProperty, String controlValue) {1297 LOG.debug("Control: verifyXmlTreeStructure on: {}", controlProperty);1298 MessageEvent mes;1299 if (Application.TYPE_SRV.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1300 try {1301 if (tCExecution.getLastServiceCalled() != null) {1302 if (AppService.RESPONSEHTTPBODYCONTENTTYPE_XML.equals(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType())) {1303 String xmlResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();1304 if (this.xmlUnitService.isSimilarTree(xmlResponse, controlProperty, controlValue)) {1305 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_SIMILARTREE);1306 } else {1307 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_SIMILARTREE);1308 }1309 mes.resolveDescription("STRING1", StringUtil.sanitize(controlProperty));1310 mes.resolveDescription("STRING2", StringUtil.sanitize(controlValue));1311 } else {1312 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);1313 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());1314 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYXMLTREESTRUCTURE);1315 }1316 } else {1317 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);1318 }1319 } catch (Exception exception) {1320 LOG.fatal(exception.toString());1321 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED);1322 }1323 } else {1324 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1325 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYXMLTREESTRUCTURE);1326 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1327 }1328 return mes;1329 }1330 private MessageEvent verifyElementClickable(TestCaseExecution tCExecution, String html) {1331 LOG.debug("Control: verifyElementClickable: {}", html);1332 MessageEvent mes;1333 if (!StringUtil.isNull(html)) {1334 Identifier identifier = identifierService.convertStringToIdentifier(html);1335 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1336 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)) {1337 try {1338 if (this.webdriverService.isElementClickable(tCExecution.getSession(), identifier)) {1339 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_CLICKABLE);1340 } else {1341 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CLICKABLE);1342 }1343 mes.resolveDescription("ELEMENT", html);1344 } catch (WebDriverException exception) {1345 return parseWebDriverException(exception);1346 }1347 } else {1348 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1349 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTCLICKABLE);1350 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1351 }1352 } else {1353 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CLICKABLE_NULL);1354 }1355 return mes;1356 }1357 private MessageEvent verifyElementNotClickable(TestCaseExecution tCExecution, String html) {1358 LOG.debug("Control: verifyElementNotClickable on: {}", html);1359 MessageEvent mes;1360 if (!StringUtil.isNull(html)) {1361 Identifier identifier = identifierService.convertStringToIdentifier(html);1362 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1363 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)) {1364 try {1365 if (this.webdriverService.isElementNotClickable(tCExecution.getSession(), identifier)) {1366 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTCLICKABLE);1367 } else {1368 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCLICKABLE);1369 }1370 mes.resolveDescription("ELEMENT", html);1371 } catch (WebDriverException exception) {1372 return parseWebDriverException(exception);1373 }1374 } else {1375 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1376 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTCLICKABLE);1377 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1378 }1379 } else {1380 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCLICKABLE_NULL);1381 }1382 return mes;1383 }1384 private String caseSensitiveMessageValue(String isCaseSensitive) {1385 return (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false))1386 ? "(case sensitive)"1387 : "(case insensitive)";1388 }1389 private MessageEvent takeScreenshot(TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution, String cropValues) {1390 MessageEvent message;1391 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1392 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)1393 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)1394 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_FAT)) {1395 List<TestCaseExecutionFile> file = recorderService.recordScreenshot(tCExecution, testCaseStepActionExecution, testCaseStepActionControlExecution.getControlId(), cropValues);1396 testCaseStepActionControlExecution.addFileList(file);1397 message = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TAKESCREENSHOT);1398 return message;1399 }1400 message = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1401 message.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_TAKESCREENSHOT);1402 message.resolveDescription("APPLICATIONTYPE", testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getAppTypeEngine());1403 return message;1404 }1405 private MessageEvent getPageSource(TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution) {1406 MessageEvent message;1407 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1408 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)1409 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {1410 TestCaseExecutionFile file = recorderService.recordPageSource(tCExecution, testCaseStepActionExecution, testCaseStepActionControlExecution.getControlId());1411 if (file != null) {1412 List<TestCaseExecutionFile> fileList = new ArrayList<>();1413 fileList.add(file);1414 testCaseStepActionControlExecution.setFileList(fileList);1415 }1416 message = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GETPAGESOURCE);1417 return message;1418 }1419 message = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);...

Full Screen

Full Screen

Source:ActionService.java Github

copy

Full Screen

...270 break;271 case TestCaseStepAction.ACTION_GETPAGESOURCE:272 res = this.doActionGetPageSource(testCaseStepActionExecution);273 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());274 logEventService.createForPrivateCalls("ENGINE", "getPageSource", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");275 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action getPageSource triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");276 break;277 case TestCaseStepAction.ACTION_TAKESCREENSHOT:278 res = this.doActionTakeScreenshot(testCaseStepActionExecution);279 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());280 logEventService.createForPrivateCalls("ENGINE", "takeScreenshot", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");281 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action takeScreenshot triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");282 break;283 case TestCaseStepAction.ACTION_CLICKANDWAIT:284 res = this.doActionClickWait(tCExecution, value1, value2);285 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());286 logEventService.createForPrivateCalls("ENGINE", "clickAndWait", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");287 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action clickAndWait triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");288 break;289 case TestCaseStepAction.ACTION_ENTER:290 res = this.doActionKeyPress(tCExecution, value1, "RETURN");291 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());292 logEventService.createForPrivateCalls("ENGINE", "enter", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");293 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action enter triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");294 break;295 case TestCaseStepAction.ACTION_SELECTANDWAIT:296 res = this.doActionSelect(tCExecution, value1, value2);297 this.doActionWait(tCExecution, StringUtil.NULL, StringUtil.NULL);298 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());299 logEventService.createForPrivateCalls("ENGINE", "selectAndWait", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");300 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action selectAndWait triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");301 break;302 default:303 res = new MessageEvent(MessageEventEnum.ACTION_FAILED_UNKNOWNACTION);304 res.setDescription(res.getDescription().replace("%ACTION%", testCaseStepActionExecution.getAction()));305 }306 } catch (final Exception unexpected) {307 LOG.error("Unexpected exception: " + unexpected.getMessage(), unexpected);308 res = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC).resolveDescription("DETAIL", unexpected.getMessage());309 }310 LOG.debug("Result of the action : " + res.getCodeString() + " " + res.getDescription());311 /**312 * In case 1/ the action is flaged as being Forced with a specific313 * return code = PE and 2/ the return of the action is stoping the test314 * --> whatever the return of the action is, we force the return to move315 * forward the test with no screenshot, pagesource.316 */317 if (testCaseStepActionExecution.getForceExeStatus().equals("PE") && res.isStopTest()) {318 res.setDescription(res.getDescription() + " -- Execution forced to continue.");319 res.setDoScreenshot(false);320 res.setGetPageSource(false);321 res.setStopTest(false);322 res.setMessage(MessageGeneralEnum.EXECUTION_PE_TESTEXECUTING);323 }324 testCaseStepActionExecution.setActionResultMessage(res);325 /**326 * Determine here the impact of the Action on the full test return code327 * from the ResultMessage of the Action.328 */329 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(res.getMessage()));330 /**331 * Determine here if we stop the test from the ResultMessage of the332 * Action.333 */334 testCaseStepActionExecution.setStopExecution(res.isStopTest());335 testCaseStepActionExecution.setEnd(new Date().getTime());336 return testCaseStepActionExecution;337 }338 private MessageEvent doActionClick(TestCaseExecution tCExecution, String value1, String value2) {339 String element;340 try {341 /**342 * Get element to use String object if not empty, String property if343 * object empty, throws Exception if both empty)344 */345 element = getElementToUse(value1, value2, TestCaseStepAction.ACTION_CLICK, tCExecution);346 /**347 * Get Identifier (identifier, locator) and check it's valid348 */349 Identifier identifier = identifierService.convertStringToIdentifier(element);350 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {351 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {352 return sikuliService.doSikuliActionClick(tCExecution.getSession(), identifier.getLocator(), "");353 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {354 return sikuliService.doSikuliActionClick(tCExecution.getSession(), "", identifier.getLocator());355 } else {356 identifierService.checkWebElementIdentifier(identifier.getIdentifier());357 return webdriverService.doSeleniumActionClick(tCExecution.getSession(), identifier, true, true);358 }359 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {360 identifierService.checkWebElementIdentifier(identifier.getIdentifier());361 return androidAppiumService.click(tCExecution.getSession(), identifier);362 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {363 identifierService.checkWebElementIdentifier(identifier.getIdentifier());364 return iosAppiumService.click(tCExecution.getSession(), identifier);365 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {366 identifierService.checkSikuliIdentifier(identifier.getIdentifier());367 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {368 return sikuliService.doSikuliActionClick(tCExecution.getSession(), identifier.getLocator(), "");369 } else {370 return sikuliService.doSikuliActionClick(tCExecution.getSession(), "", identifier.getLocator());371 }372 } else {373 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)374 .resolveDescription("ACTION", "Click")375 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());376 }377 } catch (CerberusEventException ex) {378 LOG.fatal("Error doing Action Click :" + ex);379 return ex.getMessageError();380 }381 }382 private MessageEvent doActionExecuteJS(TestCaseExecution tCExecution, String value1, String value2) {383 MessageEvent message;384 String script = value1;385 String valueFromJS;386 try {387 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {388 valueFromJS = this.webdriverService.getValueFromJS(tCExecution.getSession(), script);389 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_EXECUTEJS);390 message.setDescription(message.getDescription().replace("%SCRIPT%", script));391 message.setDescription(message.getDescription().replace("%VALUE%", valueFromJS));392 return message;393 }394 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);395 message.setDescription(message.getDescription().replace("%ACTION%", "executeJS"));396 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));397 return message;398 } catch (Exception e) {399 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTEJS);400 String messageString = e.getMessage().split("\n")[0];401 message.setDescription(message.getDescription().replace("%EXCEPTION%", messageString));402 LOG.debug("Exception Running JS Script :" + messageString);403 return message;404 }405 }406 private MessageEvent doActionMouseLeftButtonPress(TestCaseExecution tCExecution, String object, String property) {407 MessageEvent message;408 String element;409 try {410 /**411 * Get element to use String object if not empty, String property if412 * object empty, throws Exception if both empty)413 */414 element = getElementToUse(object, property, "mouseLeftButtonPress", tCExecution);415 /**416 * Get Identifier (identifier, locator)417 */418 Identifier identifier = identifierService.convertStringToIdentifier(element);419 identifierService.checkWebElementIdentifier(identifier.getIdentifier());420 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {421 return webdriverService.doSeleniumActionMouseDown(tCExecution.getSession(), identifier);422 }423 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);424 message.setDescription(message.getDescription().replace("%ACTION%", "MouseDown"));425 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));426 return message;427 } catch (CerberusEventException ex) {428 LOG.fatal("Error doing Action MouseDown :" + ex);429 return ex.getMessageError();430 }431 }432 private MessageEvent doActionRightClick(TestCaseExecution tCExecution, String object, String property) {433 MessageEvent message;434 String element;435 try {436 /**437 * Get element to use String object if not empty, String property if438 * object empty, throws Exception if both empty)439 */440 element = getElementToUse(object, property, "rightClick", tCExecution);441 /**442 * Get Identifier (identifier, locator)443 */444 Identifier identifier = identifierService.convertStringToIdentifier(element);445 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {446 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {447 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), identifier.getLocator(), "");448 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {449 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), "", identifier.getLocator());450 } else {451 identifierService.checkWebElementIdentifier(identifier.getIdentifier());452 return webdriverService.doSeleniumActionRightClick(tCExecution.getSession(), identifier);453 }454 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {455 identifierService.checkSikuliIdentifier(identifier.getIdentifier());456 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {457 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), identifier.getLocator(), "");458 } else {459 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), "", identifier.getLocator());460 }461 }462 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);463 message.setDescription(message.getDescription().replace("%ACTION%", "rightClick"));464 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));465 return message;466 } catch (CerberusEventException ex) {467 LOG.fatal("Error doing Action RightClick :" + ex);468 return ex.getMessageError();469 }470 }471 private MessageEvent doActionMouseLeftButtonRelease(TestCaseExecution tCExecution, String object, String property) {472 MessageEvent message;473 String element;474 try {475 /**476 * Get element to use String object if not empty, String property if477 * object empty, throws Exception if both empty)478 */479 element = getElementToUse(object, property, "mouseLeftButtonRelease", tCExecution);480 /**481 * Get Identifier (identifier, locator)482 */483 Identifier identifier = identifierService.convertStringToIdentifier(element);484 identifierService.checkWebElementIdentifier(identifier.getIdentifier());485 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {486 return webdriverService.doSeleniumActionMouseUp(tCExecution.getSession(), identifier);487 }488 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);489 message.setDescription(message.getDescription().replace("%ACTION%", "MouseUp"));490 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));491 return message;492 } catch (CerberusEventException ex) {493 LOG.fatal("Error doing Action MouseUp :" + ex);494 return ex.getMessageError();495 }496 }497 private MessageEvent doActionSwitchToWindow(TestCaseExecution tCExecution, String object, String property) {498 String element;499 try {500 /**501 * Get element to use String object if not empty, String property if502 * object empty, throws Exception if both empty)503 */504 element = getElementToUse(object, property, "switchToWindow", tCExecution);505 /**506 * Get Identifier (identifier, locator)507 */508 Identifier identifier = identifierService.convertStringToIdentifier(element);509 //identifierService.checkWebElementIdentifier(identifier.getIdentifier());510 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {511 return webdriverService.doSeleniumActionSwitchToWindow(tCExecution.getSession(), identifier);512 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {513 return androidAppiumService.switchToContext(tCExecution.getSession(), identifier);514 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {515 return iosAppiumService.switchToContext(tCExecution.getSession(), identifier);516 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {517 return sikuliService.doSikuliActionSwitchApp(tCExecution.getSession(), identifier.getLocator());518 } else {519 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)520 .resolveDescription("ACTION", "SwitchToWindow")521 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());522 }523 } catch (CerberusEventException ex) {524 LOG.fatal("Error doing Action SwitchToWindow :" + ex);525 return ex.getMessageError();526 }527 }528 private MessageEvent doActionManageDialog(TestCaseExecution tCExecution, String object, String property) {529 MessageEvent message;530 String element;531 try {532 /**533 * Get element to use String object if not empty, String property if534 * object empty, throws Exception if both empty)535 */536 element = getElementToUse(object, property, "manageDialog", tCExecution);537 /**538 * Get Identifier (identifier, locator)539 */540 Identifier identifier = identifierService.convertStringToIdentifier(element);541 identifierService.checkWebElementIdentifier(identifier.getIdentifier());542 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {543 return webdriverService.doSeleniumActionManageDialog(tCExecution.getSession(), identifier);544 }545 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);546 message.setDescription(message.getDescription().replace("%ACTION%", "ManageDialog"));547 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));548 return message;549 } catch (CerberusEventException ex) {550 LOG.fatal("Error doing Action ManageDialog :" + ex);551 return ex.getMessageError();552 }553 }554 private MessageEvent doActionClickWait(TestCaseExecution tCExecution, String string1, String string2) {555 MessageEvent message;556 try {557 Identifier identifier = identifierService.convertStringToIdentifier(string1);558 identifierService.checkWebElementIdentifier(identifier.getIdentifier());559 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {560 message = webdriverService.doSeleniumActionClick(tCExecution.getSession(), identifier, true, true);561 if (message.getCodeString().equals("OK")) {562 message = this.doActionWait(tCExecution, string2, null);563 }564 return message;565 }566 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);567 message.setDescription(message.getDescription().replace("%ACTION%", "ClickAndWait"));568 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", string1));569 return message;570 } catch (CerberusEventException ex) {571 LOG.fatal("Error doing Action ClickAndWait :" + ex);572 return ex.getMessageError();573 }574 }575 private MessageEvent doActionDoubleClick(TestCaseExecution tCExecution, String object, String property) {576 MessageEvent message;577 String element;578 try {579 /**580 * Get element to use String object if not empty, String property if581 * object empty, throws Exception if both empty)582 */583 element = getElementToUse(object, property, "doubleClick", tCExecution);584 /**585 * Get Identifier (identifier, locator)586 */587 Identifier identifier = identifierService.convertStringToIdentifier(element);588 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {589 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {590 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");591 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {592 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());593 } else {594 identifierService.checkWebElementIdentifier(identifier.getIdentifier());595 return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, true);596 }597 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)598 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {599 identifierService.checkWebElementIdentifier(identifier.getIdentifier());600 return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, false);601 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {602 identifierService.checkSikuliIdentifier(identifier.getIdentifier());603 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {604 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");605 } else {606 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());607 }608 }609 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);610 message.setDescription(message.getDescription().replace("%ACTION%", "doubleClick"));611 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));612 return message;613 } catch (CerberusEventException ex) {614 LOG.fatal("Error doing Action DoubleClick :" + ex);615 return ex.getMessageError();616 }617 }618 private MessageEvent doActionType(TestCaseExecution tCExecution, String object, String property, String propertyName) {619 try {620 /**621 * Check object and property are not null for GUI/APK/IPA Check622 * property is not null for FAT Application623 */624 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)625 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)626 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {627 if (object == null || property == null) {628 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);629 }630 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {631 if (property == null) {632 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);633 }634 }635 /**636 * Get Identifier (identifier, locator) if object not null637 */638 Identifier identifier = new Identifier();639 if (object != null) {640 identifier = identifierService.convertStringToIdentifier(object);641 }642 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {643 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {644 return sikuliService.doSikuliActionType(tCExecution.getSession(), identifier.getLocator(), property);645 } else {646 identifierService.checkWebElementIdentifier(identifier.getIdentifier());647 return webdriverService.doSeleniumActionType(tCExecution.getSession(), identifier, property, propertyName);648 }649 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {650 return androidAppiumService.type(tCExecution.getSession(), identifier, property, propertyName);651 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {652 return iosAppiumService.type(tCExecution.getSession(), identifier, property, propertyName);653 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {654 String locator = "";655 if (!StringUtil.isNullOrEmpty(object)) {656 identifierService.checkSikuliIdentifier(identifier.getIdentifier());657 locator = identifier.getLocator();658 }659 return sikuliService.doSikuliActionType(tCExecution.getSession(), locator, property);660 } else {661 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)662 .resolveDescription("ACTION", "Type")663 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());664 }665 } catch (CerberusEventException ex) {666 LOG.fatal("Error doing Action Type : " + ex);667 return ex.getMessageError();668 }669 }670 private MessageEvent doActionMouseOver(TestCaseExecution tCExecution, String object, String property) {671 MessageEvent message;672 String element;673 try {674 /**675 * Get element to use String object if not empty, String property if676 * object empty, throws Exception if both empty)677 */678 element = getElementToUse(object, property, "mouseOver", tCExecution);679 /**680 * Get Identifier (identifier, locator)681 */682 Identifier identifier = identifierService.convertStringToIdentifier(element);683 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {684 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {685 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");686 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {687 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());688 } else {689 identifierService.checkWebElementIdentifier(identifier.getIdentifier());690 return webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier);691 }692 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {693 identifierService.checkSikuliIdentifier(identifier.getIdentifier());694 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {695 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");696 } else {697 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());698 }699 }700 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);701 message.setDescription(message.getDescription().replace("%ACTION%", "mouseOver"));702 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));703 return message;704 } catch (CerberusEventException ex) {705 LOG.fatal("Error doing Action MouseOver :" + ex);706 return ex.getMessageError();707 }708 }709 private MessageEvent doActionMouseOverAndWait(TestCaseExecution tCExecution, String object, String property) {710 MessageEvent message;711 try {712 /**713 * Check object is not null714 */715 if (object == null) {716 return new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVERANDWAIT_GENERIC);717 }718 /**719 * Get Identifier (identifier, locator)720 */721 Identifier identifier = identifierService.convertStringToIdentifier(object);722 identifierService.checkWebElementIdentifier(identifier.getIdentifier());723 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {724 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {725 message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");726 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {727 message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());728 } else {729 message = webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier);730 }731 if (message.getCodeString().equals("OK")) {732 message = this.doActionWait(tCExecution, property, null);733 }734 return message;735 }736 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);737 message.setDescription(message.getDescription().replace("%ACTION%", "mouseOverAndWait"));738 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));739 return message;740 } catch (CerberusEventException ex) {741 LOG.fatal("Error doing Action MouseOverAndWait :" + ex);742 return ex.getMessageError();743 }744 }745 private MessageEvent doActionWait(TestCaseExecution tCExecution, String object, String property) {746 MessageEvent message;747 String element;748 long timeToWaitInMs = 0;749 Identifier identifier = null;750 try {751 /**752 * Get element to use String object if not empty, String property if753 * object empty, null if both are empty754 */755 element = getElementToUse(object, property, "wait", tCExecution);756 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)757 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)758 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)759 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) { // If application are Selenium or appium based, we have a session and can use it to wait.760 /**761 * if element is integer, set time to that value else Get762 * Identifier (identifier, locator)763 */764 if (StringUtil.isNullOrEmpty(element)) {765 timeToWaitInMs = tCExecution.getCerberus_action_wait_default();766 } else if (StringUtil.isInteger(element)) {767 timeToWaitInMs = Long.valueOf(element);768 } else {769 identifier = identifierService.convertStringToIdentifier(element);770 }771 if (identifier != null && identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {772 return sikuliService.doSikuliActionWait(tCExecution.getSession(), identifier.getLocator(), "");773 } else if (identifier != null && identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {774 return sikuliService.doSikuliActionWait(tCExecution.getSession(), "", identifier.getLocator());775 } else if (identifier != null) {776 identifierService.checkWebElementIdentifier(identifier.getIdentifier());777 return webdriverService.doSeleniumActionWait(tCExecution.getSession(), identifier);778 } else {779 return this.waitTime(timeToWaitInMs);780 }781 } else { // For any other application we wait for the integer value.782 if (StringUtil.isNullOrEmpty(element)) {783 // Get default wait from parameter784 timeToWaitInMs = tCExecution.getCerberus_action_wait_default();785 } else if (StringUtil.isInteger(element)) {786 timeToWaitInMs = Long.valueOf(element);787 }788 return this.waitTime(timeToWaitInMs);789 }790 } catch (CerberusEventException ex) {791 LOG.fatal("Error doing Action Wait :" + ex);792 return ex.getMessageError();793 }794 }795 private MessageEvent doActionKeyPress(TestCaseExecution tCExecution, String value1, String value2) {796 try {797 String appType = tCExecution.getApplicationObj().getType();798 /**799 * Check object and property are not null For IPA and APK, only800 * value2 (key to press) is mandatory For GUI and FAT, both801 * parameters are mandatory802 */803// if (appType.equalsIgnoreCase(Application.TYPE_APK) || appType.equalsIgnoreCase(Application.TYPE_IPA)) {804 if (StringUtil.isNullOrEmpty(value2)) {805 return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_MISSINGKEY).resolveDescription("APPLICATIONTYPE", appType);806 }807// } else if (appType.equalsIgnoreCase(Application.TYPE_GUI) || appType.equalsIgnoreCase(Application.TYPE_FAT)) {808// if (StringUtil.isNullOrEmpty(value1) || StringUtil.isNullOrEmpty(value2)) {809// return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS);810// }811// }812 /**813 * Get Identifier (identifier, locator)814 */815 Identifier objectIdentifier = identifierService.convertStringToIdentifier(value1);816 if (appType.equalsIgnoreCase(Application.TYPE_GUI)) {817 if (objectIdentifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {818 return sikuliService.doSikuliActionKeyPress(tCExecution.getSession(), objectIdentifier.getLocator(), value2);819 } else {820 identifierService.checkWebElementIdentifier(objectIdentifier.getIdentifier());821 return webdriverService.doSeleniumActionKeyPress(tCExecution.getSession(), objectIdentifier, value2);822 }823 } else if (appType.equalsIgnoreCase(Application.TYPE_APK)) {824 return androidAppiumService.keyPress(tCExecution.getSession(), value2);825 } else if (appType.equalsIgnoreCase(Application.TYPE_IPA)) {826 return iosAppiumService.keyPress(tCExecution.getSession(), value2);827 } else if (appType.equalsIgnoreCase(Application.TYPE_FAT)) {828 return sikuliService.doSikuliActionKeyPress(tCExecution.getSession(), objectIdentifier.getLocator(), value2);829 } else {830 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)831 .resolveDescription("ACTION", "KeyPress")832 .resolveDescription("APPLICATIONTYPE", appType);833 }834 } catch (CerberusEventException ex) {835 LOG.fatal("Error doing Action KeyPress :" + ex);836 return ex.getMessageError();837 }838 }839 private MessageEvent doActionOpenURL(TestCaseExecution tCExecution, String object, String property, boolean withBase) {840 MessageEvent message;841 String element;842 try {843 /**844 * Get element to use String object if not empty, String property if845 * object empty, throws Exception if both empty)846 */847 element = getElementToUse(object, property, "openUrl[WithBase]", tCExecution);848 /**849 * Get Identifier (identifier, locator)850 */851 Identifier identifier = new Identifier();852 identifier.setIdentifier("url");853 identifier.setLocator(element);854 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {855 return webdriverService.doSeleniumActionOpenURL(tCExecution.getSession(), tCExecution.getUrl(), identifier, withBase);856 }857 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);858 message.setDescription(message.getDescription().replace("%ACTION%", "OpenURL[WithBase]"));859 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));860 return message;861 } catch (CerberusEventException ex) {862 LOG.fatal("Error doing Action OpenUrl :" + ex);863 return ex.getMessageError();864 }865 }866 private MessageEvent doActionOpenApp(TestCaseExecution tCExecution, String value1) {867 MessageEvent message;868 /**869 * Check value1 is not null or empty870 */871 if (value1 == null || "".equals(value1)) {872 return new MessageEvent(MessageEventEnum.ACTION_FAILED_OPENAPP);873 }874 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)875 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {876 return sikuliService.doSikuliActionOpenApp(tCExecution.getSession(), value1);877 }878 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);879 message.setDescription(message.getDescription().replace("%ACTION%", "OpenApp"));880 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));881 return message;882 }883 private MessageEvent doActionCloseApp(TestCaseExecution tCExecution, String value1) {884 MessageEvent message;885 /**886 * Check value1 is not null or empty887 */888 if (value1 == null || "".equals(value1)) {889 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLOSEAPP);890 }891 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)892 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {893 return sikuliService.doSikuliActionCloseApp(tCExecution.getSession(), value1);894 }895 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);896 message.setDescription(message.getDescription().replace("%ACTION%", "CloseApp"));897 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));898 return message;899 }900 private MessageEvent doActionWaitVanish(TestCaseExecution tCExecution, String value1) {901 try {902 /**903 * Check value1 is not null or empty904 */905 if (value1 == null || "".equals(value1)) {906 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLOSEAPP);907 }908 /**909 * Get Identifier (identifier, locator)910 */911 Identifier identifier = identifierService.convertStringToIdentifier(value1);912 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {913 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {914 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), identifier.getLocator(), "");915 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {916 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), "", identifier.getLocator());917 } else {918 identifierService.checkWebElementIdentifier(identifier.getIdentifier());919 return webdriverService.doSeleniumActionWaitVanish(tCExecution.getSession(), identifier);920 }921 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)922 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {923 identifierService.checkWebElementIdentifier(identifier.getIdentifier());924 return webdriverService.doSeleniumActionWaitVanish(tCExecution.getSession(), identifier);925 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {926 identifierService.checkSikuliIdentifier(identifier.getIdentifier());927 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {928 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), identifier.getLocator(), "");929 } else {930 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), "", identifier.getLocator());931 }932 } else {933 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)934 .resolveDescription("ACTION", "WaitVanish")935 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());936 }937 } catch (CerberusEventException ex) {938 LOG.fatal("Error doing Action KeyPress :" + ex);939 return ex.getMessageError();940 }941 }942 private MessageEvent doActionSelect(TestCaseExecution tCExecution, String value1, String value2) {943 MessageEvent message;944 try {945 /**946 * Check object and property are not null947 */948 if (StringUtil.isNullOrEmpty(value1) || StringUtil.isNullOrEmpty(value2)) {949 return new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT);950 }951 /**952 * Get Identifier (identifier, locator)953 */954 Identifier identifierObject = identifierService.convertStringToIdentifier(value1);955 Identifier identifierValue = identifierService.convertStringToSelectIdentifier(value2);956 identifierService.checkWebElementIdentifier(identifierObject.getIdentifier());957 identifierService.checkSelectOptionsIdentifier(identifierValue.getIdentifier());958 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)959 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)960 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {961 return webdriverService.doSeleniumActionSelect(tCExecution.getSession(), identifierObject, identifierValue);962 }963 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);964 message.setDescription(message.getDescription().replace("%ACTION%", "Select"));965 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));966 return message;967 } catch (CerberusEventException ex) {968 LOG.fatal("Error doing Action Select :" + ex);969 return ex.getMessageError();970 }971 }972 private MessageEvent doActionUrlLogin(TestCaseExecution tCExecution) {973 MessageEvent message;974 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {975 return webdriverService.doSeleniumActionUrlLogin(tCExecution.getSession(), tCExecution.getUrl(), tCExecution.getCountryEnvironmentParameters().getUrlLogin());976 }977 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);978 message.setDescription(message.getDescription().replace("%ACTION%", "UrlLogin"));979 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));980 return message;981 }982 private MessageEvent doActionFocusToIframe(TestCaseExecution tCExecution, String object, String property) {983 MessageEvent message;984 String element;985 try {986 /**987 * Get element to use String object if not empty, String property if988 * object empty, throws Exception if both empty)989 */990 element = getElementToUse(object, property, "focusToIframe", tCExecution);991 /**992 * Get Identifier (identifier, locator)993 */994 Identifier identifier = identifierService.convertStringToIdentifier(element);995 identifierService.checkWebElementIdentifier(identifier.getIdentifier());996 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {997 return webdriverService.doSeleniumActionFocusToIframe(tCExecution.getSession(), identifier);998 }999 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1000 message.setDescription(message.getDescription().replace("%ACTION%", "FocusToIframe"));1001 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1002 return message;1003 } catch (CerberusEventException ex) {1004 LOG.fatal("Error doing Action FocusToIframe :" + ex);1005 return ex.getMessageError();1006 }1007 }1008 private MessageEvent doActionFocusDefaultIframe(TestCaseExecution tCExecution) {1009 MessageEvent message;1010 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1011 return webdriverService.doSeleniumActionFocusDefaultIframe(tCExecution.getSession());1012 }1013 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1014 message.setDescription(message.getDescription().replace("%ACTION%", "FocusDefaultIframe"));1015 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1016 return message;1017 }1018 private MessageEvent doActionCallService(TestCaseStepActionExecution testCaseStepActionExecution, String value1) {1019 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);1020 TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();1021 AnswerItem lastServiceCalledAnswer;1022 lastServiceCalledAnswer = serviceService.callService(value1, null, null, null, null, tCExecution);1023 message = lastServiceCalledAnswer.getResultMessage();1024 if (lastServiceCalledAnswer.getItem() != null) {1025 AppService lastServiceCalled = (AppService) lastServiceCalledAnswer.getItem();1026 tCExecution.setLastServiceCalled(lastServiceCalled);1027 /**1028 * Record the Request and Response in filesystem.1029 */1030 testCaseStepActionExecution.addFileList(recorderService.recordServiceCall(tCExecution, testCaseStepActionExecution, 0, null, lastServiceCalled));1031 }1032 return message;1033 }1034 private MessageEvent doActionTakeScreenshot(TestCaseStepActionExecution testCaseStepActionExecution) {1035 MessageEvent message;1036 if (testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)1037 || testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)1038 || testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1039 recorderService.recordScreenshot(testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution(),1040 testCaseStepActionExecution, 0);1041 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_TAKESCREENSHOT);1042 return message;1043 } else if (testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {1044 /**1045 * TODO Implement screenshot for FAT client application1046 */1047 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1048 }1049 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1050 message.setDescription(message.getDescription().replace("%ACTION%", "TakeScreenShot"));1051 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType()));1052 return message;1053 }1054 private MessageEvent doActionGetPageSource(TestCaseStepActionExecution testCaseStepActionExecution) {1055 MessageEvent message;1056 if (testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)1057 || testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)1058 || testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1059 recorderService.recordPageSource(testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution(), testCaseStepActionExecution, 0);1060 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_GETPAGESOURCE);1061 return message;1062 }1063 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1064 message.setDescription(message.getDescription().replace("%ACTION%", "getPageSource"));1065 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType()));1066 return message;1067 }1068 private MessageEvent doActionRemoveDifference(TestCaseStepActionExecution testCaseStepActionExecution, String object, String property) {1069 // Filters differences from the given object pattern1070 String filteredDifferences = xmlUnitService.removeDifference(object, property);1071 // If filtered differences are null then service has returned with errors1072 if (filteredDifferences == null) {1073 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_REMOVEDIFFERENCE);1074 message.setDescription(message.getDescription().replace("%DIFFERENCE%", object));1075 message.setDescription(message.getDescription().replace("%DIFFERENCES%", property));1076 return message;1077 }1078 // Sets the property value to the new filtered one...

Full Screen

Full Screen

Source:RecorderService.java Github

copy

Full Screen

...80 // Used for logging purposes81 String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";82 TestCaseExecution myExecution;83 boolean doScreenshot;84 boolean getPageSource;85 String applicationType;86 String returnCode;87 Integer controlNumber = 0;88 if (testCaseStepActionControlExecution == null) {89 myExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();90 doScreenshot = testCaseStepActionExecution.getActionResultMessage().isDoScreenshot();91 getPageSource = testCaseStepActionExecution.getActionResultMessage().isGetPageSource();92 applicationType = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType();93 returnCode = testCaseStepActionExecution.getReturnCode();94 } else {95 myExecution = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution();96 doScreenshot = testCaseStepActionControlExecution.getControlResultMessage().isDoScreenshot();97 getPageSource = testCaseStepActionControlExecution.getControlResultMessage().isGetPageSource();98 applicationType = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution().getApplicationObj().getType();99 returnCode = testCaseStepActionControlExecution.getReturnCode();100 controlNumber = testCaseStepActionControlExecution.getControlSequence();101 }102 /**103 * SCREENSHOT Management. Screenshot only done when : screenshot104 * parameter is eq to 2 or screenshot parameter is eq to 1 with the105 * correct doScreenshot flag on the last action MessageEvent.106 */107 if ((myExecution.getScreenshot() == 2) || ((myExecution.getScreenshot() == 1) && (doScreenshot))) {108 if (applicationType.equals(Application.TYPE_GUI)109 || applicationType.equals(Application.TYPE_APK)110 || applicationType.equals(Application.TYPE_IPA)111 || applicationType.equals(Application.TYPE_FAT)) {112 /**113 * Only if the return code is not equal to Cancel, meaning lost114 * connectivity with selenium.115 */116 if (!returnCode.equals("CA")) {117 objectFile = this.recordScreenshot(myExecution, testCaseStepActionExecution, controlNumber);118 if (objectFile != null) {119 objectFileList.add(objectFile);120 }121 } else {122 LOG.debug(logPrefix + "Not Doing screenshot because connectivity with selenium server lost.");123 }124 }125 } else {126 LOG.debug(logPrefix + "Not Doing screenshot because of the screenshot parameter or flag on the last Action result.");127 }128 /**129 * PAGESOURCE management. Get PageSource if requested by the last Action130 * MessageEvent.131 *132 */133 if ((myExecution.getPageSource() == 2) || ((myExecution.getPageSource() == 1) && (getPageSource))) {134 if (applicationType.equals(Application.TYPE_GUI)135 || applicationType.equals(Application.TYPE_APK)136 || applicationType.equals(Application.TYPE_IPA)) {137 /**138 * Only if the return code is not equal to Cancel, meaning lost139 * connectivity with selenium.140 */141 if (!returnCode.equals("CA")) {142 objectFile = this.recordPageSource(myExecution, testCaseStepActionExecution, controlNumber);143 if (objectFile != null) {144 objectFileList.add(objectFile);145 }146 } else {147 LOG.debug(logPrefix + "Not Doing screenshot because connectivity with selenium server lost.");148 }149 }150 } else {151 LOG.debug(logPrefix + "Not getting page source because of the pageSource parameter or flag on the last Action result.");152 }153 /**154 * Last call XML SOURCE management. Get Source of the XML if requested155 * by the last Action or control MessageEvent.156 *157 */158 if (applicationType.equals(Application.TYPE_SRV)159 && ((myExecution.getPageSource() == 2) || ((myExecution.getPageSource() == 1) && (getPageSource))160 || (myExecution.getScreenshot() == 2) || ((myExecution.getScreenshot() == 1) && (doScreenshot)))) {161 //Record the Request and Response.162 AppService se = (AppService) testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getLastServiceCalled();163 if (se != null) { // No Calls were performed previously164 List<TestCaseExecutionFile> objectFileSOAPList = new ArrayList<TestCaseExecutionFile>();165 objectFileSOAPList = this.recordServiceCall(myExecution, testCaseStepActionExecution, controlNumber, null, se);166 if (objectFileSOAPList.isEmpty() != true) {167 for (TestCaseExecutionFile testCaseExecutionFile : objectFileSOAPList) {168 objectFileList.add(testCaseExecutionFile);169 }170 }171 }172 }173 return objectFileList;174 }175 @Override176 public AnswerItem recordManuallyFile(TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution, String extension, String desc, FileItem file, Integer id, String fileName, Integer fileID) {177 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",178 "Can't upload file");179 AnswerItem a = new AnswerItem();180 TestCaseExecutionFile object = null;181 String returnCode;182 Integer controlNumber = 0;183 String test = "";184 String testCase = "";185 String step = "";186 String index = "";187 String sequence = "";188 String controlString = "";189 Integer myExecution = id;190 if (testCaseStepActionControlExecution == null) {191 test = testCaseStepActionExecution.getTest();192 testCase = testCaseStepActionExecution.getTestCase();193 step = String.valueOf(testCaseStepActionExecution.getStep());194 index = String.valueOf(testCaseStepActionExecution.getIndex());195 sequence = String.valueOf(testCaseStepActionExecution.getSequence());196 controlString = controlNumber.equals(0) ? null : String.valueOf(controlNumber);197 returnCode = testCaseStepActionExecution.getReturnCode();198 } else {199 returnCode = testCaseStepActionControlExecution.getReturnCode();200 controlNumber = testCaseStepActionControlExecution.getControlSequence();201 test = testCaseStepActionControlExecution.getTest();202 testCase = testCaseStepActionControlExecution.getTestCase();203 step = String.valueOf(testCaseStepActionControlExecution.getStep());204 index = String.valueOf(testCaseStepActionControlExecution.getIndex());205 sequence = String.valueOf(testCaseStepActionControlExecution.getSequence());206 controlString = controlNumber.equals(0) ? null : String.valueOf(controlNumber);207 }208 // Used for logging purposes209 String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - [" + test + " - " + testCase + " - step: " + step + " action: " + sequence + "] ";210 try {211 Recorder recorder = new Recorder();212 String name = "";213 File dir = null;214 if (file != null) {215 name = file.getName();216 extension = name.substring(name.lastIndexOf('.') + 1, name.length());217 extension = extension.toUpperCase();218 extension = testCaseExecutionFileService.checkExtension(name, extension);219 recorder = this.initFilenames(myExecution, test, testCase, step, index, sequence, controlString, null, 0, name.substring(0, name.lastIndexOf('.')), extension, true);220 dir = new File(recorder.getFullPath());221 } else {222 name = fileName;223 extension = testCaseExecutionFileService.checkExtension(name, extension);224 if (name.contains(".")) {225 recorder = this.initFilenames(myExecution, test, testCase, step, index, sequence, controlString, null, 0, name.substring(0, name.lastIndexOf('.')), extension, true);226 dir = new File(recorder.getFullPath());227 } else {228 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);229 msg.setDescription(msg.getDescription().replace("%ITEM%", "manual testcase execution file")230 .replace("%OPERATION%", "Create")231 .replace("%REASON%", "file is missing!"));232 a.setResultMessage(msg);233 return a;234 }235 }236 if (!dir.exists()) {237 try {238 boolean isCreated = dir.mkdirs();239 if (!isCreated) {240 throw new SecurityException();241 }242 } catch (SecurityException se) {243 LOG.warn("Unable to create manual execution file dir: " + se.getMessage());244 msg = new MessageEvent(MessageEventEnum.FILE_ERROR).resolveDescription("DESCRIPTION",245 se.toString()).resolveDescription("MORE", "Please check the parameter cerberus_exemanualmedia_path");246 a.setResultMessage(msg);247 return a;248 }249 }250 if (file != null) {251 AnswerItem<TestCaseExecutionFile> current = testCaseExecutionFileService.readByKey(myExecution, recorder.getLevel(), desc);252 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);253 if (current.getItem() != null) {254 try {255 File temp = new File(recorder.getRootFolder() + current.getItem().getFileName());256 temp.delete();257 } catch (SecurityException se) {258 LOG.warn("Unable to create manual execution file dir: " + se.getMessage());259 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",260 se.toString());261 }262 }263 try {264 file.write(new File(recorder.getFullFilename()));265 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("DESCRIPTION",266 "Manual Execution File uploaded");267 msg.setDescription(msg.getDescription().replace("%ITEM%", "Manual Execution File").replace("%OPERATION%", "Upload"));268 LOG.debug(logPrefix + "Copy file finished with success - source: " + file.getName() + " destination: " + recorder.getRelativeFilenameURL());269 object = testCaseExecutionFileFactory.create(fileID, myExecution, recorder.getLevel(), desc, recorder.getRelativeFilenameURL(), extension, "", null, "", null);270 } catch (Exception e) {271 LOG.warn("Unable to upload Manual Execution File: " + e.getMessage());272 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",273 e.toString());274 }275 } else {276 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("DESCRIPTION",277 "Manual Execution File updated");278 msg.setDescription(msg.getDescription().replace("%ITEM%", "Manual Execution File").replace("%OPERATION%", "updated"));279 LOG.debug(logPrefix + "Updated test case manual file finished with success");280 object = testCaseExecutionFileFactory.create(fileID, myExecution, recorder.getLevel(), desc, name, extension, "", null, "", null);281 }282 testCaseExecutionFileService.saveManual(object);283 } catch (CerberusException e) {284 LOG.error(logPrefix + e.toString());285 }286 a.setResultMessage(msg);287 a.setItem(object);288 return a;289 }290 @Override291 public TestCaseExecutionFile recordScreenshot(TestCaseExecution testCaseExecution, TestCaseStepActionExecution testCaseStepActionExecution, Integer control) {292 TestCaseExecutionFile object = null;293 String test = testCaseStepActionExecution.getTest();294 String testCase = testCaseStepActionExecution.getTestCase();295 String step = String.valueOf(testCaseStepActionExecution.getStep());296 String index = String.valueOf(testCaseStepActionExecution.getIndex());297 String sequence = String.valueOf(testCaseStepActionExecution.getSequence());298 String controlString = control.equals(0) ? null : String.valueOf(control);299 long runId = testCaseExecution.getId();300 String applicationType = testCaseExecution.getApplicationObj().getType();301 // Used for logging purposes302 String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - [" + test + " - " + testCase + " - step: " + step + " action: " + sequence + "] ";303 LOG.debug(logPrefix + "Doing screenshot.");304 /**305 * Take Screenshot and write it306 */307 File newImage = null;308 if (applicationType.equals(Application.TYPE_GUI)309 || applicationType.equals(Application.TYPE_APK)310 || applicationType.equals(Application.TYPE_IPA)) {311 newImage = this.webdriverService.takeScreenShotFile(testCaseExecution.getSession());312 } else if (applicationType.equals(Application.TYPE_FAT)) {313 newImage = this.sikuliService.takeScreenShotFile(testCaseExecution.getSession());314 }315 if (newImage != null) {316 try {317 Recorder recorder = this.initFilenames(runId, test, testCase, step, index, sequence, controlString, null, 0, "screenshot", "png", false);318 LOG.debug(logPrefix + "FullPath " + recorder.getFullPath());319 File dir = new File(recorder.getFullPath());320 if (!dir.exists()) {321 LOG.debug(logPrefix + "Create directory for execution " + recorder.getFullPath());322 dir.mkdirs();323 }324 // Getting the max size of the screenshot.325 long maxSizeParam = parameterService.getParameterIntegerByKey("cerberus_screenshot_max_size", "", 1048576);326 if (maxSizeParam < newImage.length()) {327 LOG.warn(logPrefix + "Screen-shot size exceeds the maximum defined in configurations " + newImage.getName() + " destination: " + recorder.getRelativeFilenameURL());328 }329 //copies the temp file to the execution file330 FileUtils.copyFile(newImage, new File(recorder.getFullFilename()));331 LOG.debug(logPrefix + "Copy file finished with success - source: " + newImage.getName() + " destination: " + recorder.getRelativeFilenameURL());332 // Index file created to database.333 object = testCaseExecutionFileFactory.create(0, testCaseExecution.getId(), recorder.getLevel(), "Screenshot", recorder.getRelativeFilenameURL(), "PNG", "", null, "", null);334 testCaseExecutionFileService.save(object);335 //deletes the temporary file336 FileUtils.forceDelete(newImage);337 LOG.debug(logPrefix + "Temp file deleted with success " + newImage.getName());338 LOG.debug(logPrefix + "Screenshot done in : " + recorder.getRelativeFilenameURL());339 } catch (IOException ex) {340 LOG.error(logPrefix + ex.toString());341 } catch (CerberusException ex) {342 LOG.error(logPrefix + ex.toString());343 }344 } else {345 LOG.warn(logPrefix + "Screenshot returned null.");346 }347 return object;348 }349 @Override350 public TestCaseExecutionFile recordPageSource(TestCaseExecution testCaseExecution, TestCaseStepActionExecution testCaseStepActionExecution, Integer control) {351 // Used for logging purposes352 String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";353 LOG.debug(logPrefix + "Starting to save Page Source File.");354 TestCaseExecutionFile object = null;355 String test = testCaseExecution.getTest();356 String testCase = testCaseExecution.getTestCase();357 String step = String.valueOf(testCaseStepActionExecution.getStep());358 String index = String.valueOf(testCaseStepActionExecution.getIndex());359 String sequence = String.valueOf(testCaseStepActionExecution.getSequence());360 String controlString = control.equals(0) ? null : String.valueOf(control);361 try {362 Recorder recorder = this.initFilenames(testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getId(), test, testCase, step, index, sequence, controlString, null, 0, "pagesource", "html", false);363 File dir = new File(recorder.getFullPath());364 dir.mkdirs();365 File file = new File(recorder.getFullFilename());366 try(FileOutputStream fileOutputStream = new FileOutputStream(file);) {367 fileOutputStream.write(this.webdriverService.getPageSource(testCaseExecution.getSession()).getBytes());368 fileOutputStream.close();369 // Index file created to database.370 object = testCaseExecutionFileFactory.create(0, testCaseExecution.getId(), recorder.getLevel(), "Page Source", recorder.getRelativeFilenameURL(), "HTML", "", null, "", null);371 testCaseExecutionFileService.save(object);372 } catch (FileNotFoundException ex) {373 LOG.error(logPrefix + ex.toString());374 } catch (IOException ex) {375 LOG.error(logPrefix + ex.toString());376 }377 LOG.debug(logPrefix + "Page Source file saved in : " + recorder.getRelativeFilenameURL());378 } catch (CerberusException ex) {379 LOG.error(logPrefix + ex.toString());380 }381 return object;...

Full Screen

Full Screen

getPageSource

Using AI Code Generation

copy

Full Screen

1package org.cerberus.service.webdriver.impl;2import java.util.logging.Level;3import java.util.logging.Logger;4import org.cerberus.engine.entity.MessageEvent;5import org.cerberus.engine.entity.MessageGeneral;6import org.cerberus.engine.entity.Session;7import org.cerberus.engine.entity.TestCaseExecution;8import org.cerberus.engine.execution.IRecorderService;9import org.cerberus.engine.execution.IRobotService;10import org.cerberus.engine.execution.IVariableService;11import org.cerberus.engine.groovy.GroovyService;12import org.cerberus.engine.queuemanagement.IExecutionThreadPoolService;13import org.cerberus.engine.queuemanagement.IExecutionThreadPoolService.IExecutionThreadPoolServiceHandler;14import org.cerberus.engine.queuemanagement.IExecutionThreadPoolService.IExecutionThreadPoolServiceHandlerFactory;15import org.cerberus.exception.CerberusException;16import org.cerberus.service.engine.IRecorderService;17import org.cerberus.service.engine.IRobotService;18import org.cerberus.service.engine.IVariableService;19import org.cerberus.service.engine.impl.RecorderService;20import org.cerberus.service.engine.impl.RobotService;21import org.cerberus.service.engine.impl.VariableService;22import org.cerberus.service.webdriver.IWebDriverService;23import org.cerberus.util.answer.Answer;24import org.cerberus.util.answer.AnswerItem;25import org.cerberus.util.answer.AnswerList;26import org.cerberus.util.answer.AnswerUtil;27import org.cerberus.util.answer.IAnswerItem;28import org.cerberus.util.answer.IAnswerList;29import org.cerberus.util.answer.IAnswerUtil;30import org.openqa.selenium.WebDriver;31import org.springframework.beans.factory.annotation.Autowired;32import org.springframework.stereotype.Service;33public class WebDriverService implements IWebDriverService {34 private static final Logger LOG = Logger.getLogger(WebDriverService.class.getName());35 private IRecorderService recorderService;36 private IVariableService variableService;37 private IRobotService robotService;38 private IExecutionThreadPoolService executionThreadPoolService;39 public IAnswerItem<WebDriver> getWebDriver(TestCaseExecution tCExecution, String property, String propertyIndex, String propertyType, String propertyName, String property

Full Screen

Full Screen

getPageSource

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.MessageEvent;2import org.cerberus.engine.entity.Session;3import org.cerberus.engine.execution.IRecorderService;4import org.cerberus.engine.execution.impl.RecorderService;5import org.cerberus.engine.queuemanagement.IExecutionThreadPoolService;6import org.cerberus.engine.queuemanagement.impl.ExecutionThreadPoolService;7import org.cerberus.engine.queuemanagement.impl.MessageEventFactory;8import org.cerberus.engine.queuemanagement.impl.SessionFactory;9import org.cerberus.engine.queuemanagement.impl.ThreadPoolService;10import org.cerberus.exception.CerberusEventException;11import org.cerberus.service.webdriver.IWebDriverService;12import org.cerberus.service.webdriver.impl.WebDriverService;13import org.openqa.selenium.WebDriver;14import org.openqa.selenium.chrome.ChromeDriver;15import org.openqa.selenium.chrome.ChromeOptions;16import java.net.MalformedURLException;17import java.util.HashMap;18import java.util.Map;19public class TestClass {20 public static void main(String[] args) throws MalformedURLException, CerberusEventException {21 IWebDriverService webDriverService = new WebDriverService();22 IRecorderService recorderService = new RecorderService();23 IExecutionThreadPoolService executionThreadPoolService = new ExecutionThreadPoolService();24 ThreadPoolService threadPoolService = new ThreadPoolService();25 threadPoolService.setWebDriverService(webDriverService);26 threadPoolService.setRecorderService(recorderService);27 threadPoolService.setExecutionThreadPoolService(executionThreadPoolService);28 threadPoolService.init();29 Map<String, String> map = new HashMap<>();30 map.put("cerberus_screenshotpath", "C:\\Users\\test\\Desktop\\");31 map.put("cerberus_recorderpath", "C:\\Users\\test\\Desktop\\");32 map.put("cerberus_recorderactive", "true");33 map.put("cerberus_screenshotactive", "true");34 map.put("cerberus_recordermaxsize", "5000");35 map.put("cerberus_screenshotfullpage", "true");36 map.put("cerberus_recordermaxaction", "5000");37 map.put("cerberus_screenshotformat", "png");38 map.put("cerberus_screenshotquality", "75");39 map.put("cerberus_screenshotmaxsize", "5000");40 map.put("cerber

Full Screen

Full Screen

getPageSource

Using AI Code Generation

copy

Full Screen

1package org.cerberus.service.webdriver.impl;2import org.cerberus.crud.entity.TestCaseExecution;3import org.cerberus.crud.entity.TestCaseExecutionData;4import org.cerberus.crud.service.ITestCaseExecutionDataService;5import org.cerberus.crud.service.ITestCaseExecutionService;6import org.cerberus.engine.entity.Identifier;7import org.cerberus.engine.entity.MessageEvent;8import org.cerberus.engine.entity.MessageGeneral;9import org.cerberus.engine.entity.Session;10import org.cerberus.engine.execution.IRecorderService;11import org.cerberus.engine.execution.impl.ManageDatabaseService;12import org.cerberus.engine.execution.impl.ManageFileService;13import org.cerberus.engine.execution.impl.ManageLogEventService;14import org.cerberus.engine.execution.impl.ManageScreenshotService;15import org.cerberus.engine.execution.impl.ManageService;16import org.cerberus.engine.execution.impl.ManageWaitService;17import org.cerberus.engine.execution.impl.ManageWebElementService;18import org.cerberus.engine.execution.impl.RecorderService;19import org.cerberus.engine.queuemanagement.entity.IQueueAction;20import org.cerberus.engine.queuemanagement.entity.QueueAction;21import org.cerberus.engine.queuemanagement.entity.QueueActionControl;22import org.cerberus.engine.queuemanagement.entity.QueueActionControlAction;23import org.cerberus.engine.queuemanagement.entity.QueueActionControlActionControl;24import org.cerberus.engine.queuemanagement.entity.QueueActionControlActionControlExecution;25import org.cerberus.engine.queuemanagement.entity.QueueActionControlExecution;26import org.cerberus.engine.queuemanagement.entity.QueueActionExecution;27import org.cerberus.engine.queuemanagement.entity.QueueActionExecutionQueueActionControlExecution;28import org.cerberus.engine.queuemanagement.entity.QueueActionExecutionQueueActionControlExecutionQueueActionControlActionControlExecution;29import org.cerberus.engine.queuemanagement.entity.QueueActionQueueActionControl;30import org.cerberus.engine.queuemanagement.entity.QueueActionQueueActionControlQueueActionControlAction;31import org.cerberus.engine.queuemanagement.entity.QueueActionQueueActionControlQueueActionControlActionControl;32import org.cerberus.engine.queuemanagement

Full Screen

Full Screen

getPageSource

Using AI Code Generation

copy

Full Screen

1package org.cerberus.service.webdriver.impl;2import java.util.logging.Level;3import java.util.logging.Logger;4import org.cerberus.crud.entity.TestCaseExecution;5import org.cerberus.crud.entity.TestCaseStepActionExecution;6import org.cerberus.engine.entity.MessageEvent;7import org.cerberus.engine.entity.MessageGeneral;8import org.cerberus.engine.entity.Session;9import org.cerberus.engine.execution.IRecorderService;10import org.cerberus.engine.execution.impl.RecorderService;11import org.cerberus.engine.queuemanagement.IExecutionThreadPoolService;12import org.cerberus.engine.queuemanagement.impl.ExecutionThreadPoolService;13import org.cerberus.enums.MessageEventEnum;14import org.cerberus.enums.MessageGeneralEnum;15import org.cerberus.exception.CerberusEventException;16import org.cerberus.exception.CerberusException;17import org.cerberus.service.ILogEventService;18import org.cerberus.service.ILogEventService.LOGLEVEL;19import org.cerberus.service.ITestCaseStepActionExecutionService;20import org.cerberus.service.ITestCaseStepActionExecutionService.STATUS;21import org.cerberus.service.webdriver.IActionService;22import org.cerberus.util.answer.Answer;23import org.cerberus.util.answer.AnswerItem;24import org.openqa.selenium.WebDriver;25import org.springframework.beans.factory.annotation.Autowired;26import org.springframework.stereotype.Service;27public class ActionService implements IActionService {28 private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(ActionService.class);29 private ITestCaseStepActionExecutionService testCaseStepActionExecutionService;30 private ILogEventService logEventService;31 public void doAction(WebDriverService webdriverService, TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution) throws CerberusEventException {32 LOG.info("ActionService.doAction - Start");33 IRecorderService recorderService = new RecorderService();34 try {35 WebDriver driver = webdriverService.getDriver(tCExecution.getSession());36 testCaseStepActionExecution.setStart(new java.sql.Timestamp(new java.util.Date().getTime()));

Full Screen

Full Screen

getPageSource

Using AI Code Generation

copy

Full Screen

1package org.cerberus;2import org.cerberus.engine.entity.Session;3import org.cerberus.engine.entity.TestCaseExecution;4import org.cerberus.engine.execution.IExecutionThreadService;5import org.cerberus.engine.execution.impl.ExecutionThreadService;6import org.cerberus.engine.threadpool.IExecutionThreadPoolService;7import org.cerberus.engine.threadpool.impl.ExecutionThreadPoolService;8import org.cerberus.engine.threadpool.impl.ExecutionThreadPoolSingleton;9import org.cerberus.exception.CerberusException;10import org.cerberus.service.engine.IParameterService;11import org.cerberus.service.engine.impl.ParameterService;12import org.cerberus.service.webdriver.IWebDriverService;13import org.cerberus.service.webdriver.impl.WebDriverService;14import org.openqa.selenium.WebDriver;15public class Cerberus {16 public static void main(String[] args) {17 try {18 IParameterService parameterService = new ParameterService();19 IExecutionThreadPoolService executionThreadPoolService = new ExecutionThreadPoolService(parameterService);20 IExecutionThreadService executionThreadService = new ExecutionThreadService(parameterService, executionThreadPoolService);21 IWebDriverService webDriverService = new WebDriverService(parameterService, executionThreadService);22 Session session = new Session();23 TestCaseExecution testCaseExecution = new TestCaseExecution();24 testCaseExecution.setCountry("AU");25 testCaseExecution.setEnvironment("QA");26 testCaseExecution.setBrowser("firefox");27 testCaseExecution.setBrowserVersion("31");28 testCaseExecution.setPlatform("WINDOWS");29 testCaseExecution.setApplication("cerberus");30 testCaseExecution.setManualExecution("Y");31 testCaseExecution.setVerbose("1");32 testCaseExecution.setScreenshot("1");33 testCaseExecution.setPageSource("1");34 testCaseExecution.setSeleniumLog("1");35 testCaseExecution.setRobotLog("1");36 testCaseExecution.setRobotHost("localhost");37 testCaseExecution.setRobotPort("4444");38 testCaseExecution.setRobotPlatform("WINDOWS");39 testCaseExecution.setRobotBrowser("firefox");40 testCaseExecution.setRobotBrowserVersion("31");41 testCaseExecution.setRobotScreenSize("1024x768");42 testCaseExecution.setRobotTimeout("

Full Screen

Full Screen

getPageSource

Using AI Code Generation

copy

Full Screen

1package com.cerberus;2import org.cerberus.service.webdriver.impl.WebDriverService;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5public class 3 {6public static void main(String[] args) {7System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Desktop\\chromedriver.exe");8WebDriver driver = new ChromeDriver();9WebDriverService wds = new WebDriverService();10String pageSource = wds.getPageSource(driver);11System.out.println(pageSource);12driver.quit();13}14}

Full Screen

Full Screen

getPageSource

Using AI Code Generation

copy

Full Screen

1package test;2import org.cerberus.engine.entity.MessageEvent;3import org.cerberus.engine.execution.IExecutionHandler;4import org.cerberus.engine.execution.impl.ExecutionHandler;5import org.cerberus.engine.execution.impl.TestExecutor;6import org.cerberus.engine.threadpool.ThreadPoolService;7import org.cerberus.engine.threadpool.impl.ThreadPoolServiceFactory;8import org.cerberus.engine.threadpool.impl.ThreadPoolServiceFactoryTest;9import org.cerberus.exception.CerberusEventException;10import org.cerberus.exception.CerberusException;11import org.cerberus.service.engine.IRecorderService;12import org.cerberus.service.engine.IVariableService;13import org.cerberus.service.engine.impl.RecorderService;14import org.cerberus.service.engine.impl.VariableService;15import org.cerberus.service.engine.impl.action.ActionService;16import org.cerberus.service.engine.impl.action.IActionService;17import org.cerberus.service.engine.impl.appservice.AppServiceService;18import org.cerberus.service.engine.impl.appservice.IAppServiceService;19import org.cerberus.service.engine.impl.appservice.IAppServiceServiceFactory;20import org.cerberus.service.engine.impl.appservice.impl.AppServiceServiceFactory;21import org.cerberus.service.engine.impl.appservice.impl.AppServiceServiceFactoryTest;22import org.cerberus.service.engine.impl.elementhandler.IElementHandlerService;23import org.cerberus.service.engine.impl.elementhandler.impl.ElementHandlerService;24import org.cerberus.service.engine.impl.elementhandler.impl.ElementHandlerServiceFactory;25import org.cerberus.service.engine.impl.elementhandler.impl.ElementHandlerServiceFactoryTest;26import org.cerberus.service.engine.impl.factory.IFactoryActionService;27import org.cerberus.service.engine.impl.factory.IFactoryAppServiceService;28import org.cerberus.service.engine.impl.factory.IFactoryElementHandlerService;29import org.cerberus.service.engine.impl.factory.IFactoryTestCaseService;30import org.cerberus.service.engine.impl.factory.impl.FactoryActionService;31import org.cerberus.service.engine.impl.factory.impl.FactoryAppServiceService;32import org.cerberus.service.engine.impl.factory.impl.FactoryElementHandlerService;33import org.cerber

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful