Best Cerberus-source code snippet using org.cerberus.engine.gwt.impl.PropertyService.property_getRawFromXml
Source:PropertyService.java
...652 case TestCaseCountryProperties.TYPE_GETFROMXML:653 testCaseExecutionData = this.property_getFromXml(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);654 break;655 case TestCaseCountryProperties.TYPE_GETRAWFROMXML:656 testCaseExecutionData = this.property_getRawFromXml(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);657 break;658 case TestCaseCountryProperties.TYPE_GETDIFFERENCESFROMXML:659 testCaseExecutionData = this.property_getDifferencesFromXml(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);660 break;661 case TestCaseCountryProperties.TYPE_GETFROMJSON:662 testCaseExecutionData = this.property_getFromJson(testCaseExecutionData, tCExecution, forceRecalculation);663 break;664 case TestCaseCountryProperties.TYPE_GETFROMGROOVY:665 testCaseExecutionData = this.property_getFromGroovy(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);666 break;667 case TestCaseCountryProperties.TYPE_GETFROMCOMMAND:668 testCaseExecutionData = this.property_getFromCommand(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);669 break;670 case TestCaseCountryProperties.TYPE_GETELEMENTPOSITION:671 testCaseExecutionData = this.property_getElementPosition(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);672 break;673 case TestCaseCountryProperties.TYPE_GETFROMNETWORKTRAFFIC:674 testCaseExecutionData = this.property_getFromNetworkTraffic(testCaseExecutionData, testCaseCountryProperty, tCExecution, forceRecalculation);675 break;676 // DEPRECATED Property types.677 case TestCaseCountryProperties.TYPE_EXECUTESOAPFROMLIB: // DEPRECATED678 testCaseExecutionData = this.property_executeSoapFromLib(testCaseExecutionData, tCExecution, testCaseStepActionExecution, testCaseCountryProperty, forceRecalculation);679 res = testCaseExecutionData.getPropertyResultMessage();680 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());681 testCaseExecutionData.setPropertyResultMessage(res);682 logEventService.createForPrivateCalls("ENGINE", TestCaseCountryProperties.TYPE_EXECUTESOAPFROMLIB, MESSAGE_DEPRECATED + " Deprecated Property triggered by TestCase : ['" + test + "|" + testCase + "']");683 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Property " + TestCaseCountryProperties.TYPE_EXECUTESOAPFROMLIB + " triggered by TestCase : ['" + test + "'|'" + testCase + "']");684 break;685 case TestCaseCountryProperties.TYPE_EXECUTESQLFROMLIB: // DEPRECATED686 testCaseExecutionData = this.property_executeSqlFromLib(testCaseExecutionData, testCaseCountryProperty, tCExecution, forceRecalculation);687 res = testCaseExecutionData.getPropertyResultMessage();688 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());689 testCaseExecutionData.setPropertyResultMessage(res);690 logEventService.createForPrivateCalls("ENGINE", TestCaseCountryProperties.TYPE_EXECUTESQLFROMLIB, MESSAGE_DEPRECATED + " Deprecated Property triggered by TestCase : ['" + test + "|" + testCase + "']");691 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Property " + TestCaseCountryProperties.TYPE_EXECUTESQLFROMLIB + " triggered by TestCase : ['" + test + "'|'" + testCase + "']");692 break;693 default:694 res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_UNKNOWNPROPERTY);695 res.setDescription(res.getDescription().replace("%PROPERTY%", testCaseCountryProperty.getType()));696 testCaseExecutionData.setPropertyResultMessage(res);697 }698 execution_count++;699 }700 if (execution_count >= 2) { // If there were at least 1 retry, we notify it in the result message.701 res = testCaseExecutionData.getPropertyResultMessage();702 res.setDescription("Retried " + (execution_count - 1) + " time(s) with " + periodms + "ms period - " + res.getDescription());703 testCaseExecutionData.setPropertyResultMessage(res);704 }705 if (forced_retry) { // If the retry and period parameter was changed, we notify it in the result message.706 res = testCaseExecutionData.getPropertyResultMessage();707 res.setDescription(forced_retry_message + " - " + res.getDescription());708 testCaseExecutionData.setPropertyResultMessage(res);709 }710 } else {711 // cache activated and entry exist. We set the current value with cache entry data and notify the result from the messsage.712 TestCaseExecutionData testCaseExecutionDataFromCache = data;713 testCaseExecutionData.setFromCache("Y");714 testCaseExecutionData.setDataLib(testCaseExecutionDataFromCache.getDataLib());715 testCaseExecutionData.setValue(testCaseExecutionDataFromCache.getValue());716 testCaseExecutionData.setJsonResult(testCaseExecutionDataFromCache.getJsonResult());717 DateFormat df = new SimpleDateFormat(DateUtil.DATE_FORMAT_DISPLAY);718 res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_FROMCACHE).resolveDescription("ID", String.valueOf(testCaseExecutionDataFromCache.getId())).resolveDescription("DATE", df.format(testCaseExecutionDataFromCache.getStart()));719 testCaseExecutionData.setPropertyResultMessage(res);720 if (!StringUtil.isNullOrEmpty(testCaseExecutionDataFromCache.getJsonResult())) {721 // Convert json to HashMap.722 List<HashMap<String, String>> result = null;723 result = new ArrayList<>();724 try {725 LOG.debug("Converting Json : " + testCaseExecutionDataFromCache.getJsonResult());726 JSONArray json = new JSONArray(testCaseExecutionDataFromCache.getJsonResult());727 for (int i = 0; i < json.length(); i++) {728 JSONObject explrObject = json.getJSONObject(i);729 LOG.debug(explrObject.toString());730 HashMap<String, String> resultHash = new HashMap<>();731 Iterator<?> nameItr = explrObject.keys();732 while (nameItr.hasNext()) {733 String name = (String) nameItr.next();734 if (name.equals("KEY")) {735 resultHash.put("", explrObject.getString(name));736 } else {737 resultHash.put(name, explrObject.getString(name));738 }739 }740 result.add(resultHash);741 }742 } catch (JSONException ex) {743 java.util.logging.Logger.getLogger(PropertyService.class.getName()).log(Level.SEVERE, null, ex);744 LOG.error(ex, ex);745 }746 testCaseExecutionData.setDataLibRawData(result);747 //Record result in filessytem.748 recorderService.recordTestDataLibProperty(tCExecution.getId(), testCaseCountryProperty.getProperty(), 1, result);749 }750 }751 } catch (CerberusEventException ex) {752 LOG.error(ex.toString(), ex);753 testCaseExecutionData.setEnd(new Date().getTime());754 testCaseExecutionData.setPropertyResultMessage(ex.getMessageError());755 }756 testCaseExecutionData.setEnd(new Date().getTime());757 if (LOG.isDebugEnabled()) {758 LOG.debug("Finished to calculate Property : '" + testCaseCountryProperty.getProperty() + "'");759 }760 }761 private TestCaseExecutionData property_getFromCommand(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceRecalculation) {762 // Check if script has been correctly defined763 String script = testCaseExecutionData.getValue1();764 if (script == null || script.isEmpty()) {765 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMCOMMAND_NULL));766 return testCaseExecutionData;767 }768 // Try to evaluate Command script769 try {770 if (tCExecution.getAppTypeEngine().equals(Application.TYPE_APK)) {771 String message = androidAppiumService.executeCommandString(tCExecution.getSession(), script, testCaseExecutionData.getValue2());772 String value = "";773 if (!StringUtil.isNullOrEmpty(message)) {774 value = message;775 }776 testCaseExecutionData.setValue(value);777 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMCOMMAND).resolveDescription("VALUE", value));778 } else if (tCExecution.getAppTypeEngine().equals(Application.TYPE_IPA)) {779 String message = iosAppiumService.executeCommandString(tCExecution.getSession(), script, testCaseExecutionData.getValue2());780 String value = "";781 if (!StringUtil.isNullOrEmpty(message)) {782 value = message;783 }784 testCaseExecutionData.setValue(value);785 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMCOMMAND).resolveDescription("VALUE", value));786 } else {787 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_FEATURENOTSUPPORTED);788 res.setDescription(res.getDescription().replace("%APPTYPE%", tCExecution.getAppTypeEngine()));789 res.setDescription(res.getDescription().replace("%PROPTYPE%", testCaseExecutionData.getType()));790 testCaseExecutionData.setPropertyResultMessage(res);791 }792 } catch (Exception e) {793 LOG.debug("Exception Running Command Script :" + e.getMessage());794 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMCOMMAND_EXCEPTION).resolveDescription("REASON", e.getMessage()));795 }796 return testCaseExecutionData;797 }798 private TestCaseExecutionData property_getElementPosition(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceRecalculation) {799 // Check if script has been correctly defined800 String script = testCaseExecutionData.getValue1();801 if (script == null || script.isEmpty()) {802 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETELEMENTPOSITION_NULL));803 return testCaseExecutionData;804 }805 try {806 Identifier identifier = new Identifier();807 if (script != null) {808 identifier = identifierService.convertStringToIdentifier(script);809 }810 if (tCExecution.getAppTypeEngine().equals(Application.TYPE_APK)) {811 String message = androidAppiumService.getElementPosition(tCExecution.getSession(), identifier);812 String value = "";813 if (!StringUtil.isNullOrEmpty(message)) {814 value = message;815 }816 testCaseExecutionData.setValue(value);817 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETELEMENTPOSITION).resolveDescription("VALUE", value));818 } else if (tCExecution.getAppTypeEngine().equals(Application.TYPE_IPA)) {819 String message = iosAppiumService.getElementPosition(tCExecution.getSession(), identifier);820 String value = "";821 if (!StringUtil.isNullOrEmpty(message)) {822 value = message;823 }824 testCaseExecutionData.setValue(value);825 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETELEMENTPOSITION).resolveDescription("VALUE", value));826 } else {827 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_FEATURENOTSUPPORTED);828 res.setDescription(res.getDescription().replace("%APPTYPE%", tCExecution.getAppTypeEngine()));829 res.setDescription(res.getDescription().replace("%PROPTYPE%", testCaseExecutionData.getType()));830 testCaseExecutionData.setPropertyResultMessage(res);831 }832 } catch (Exception e) {833 LOG.debug("Exception Running Command Script :" + e.getMessage());834 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETELEMENTPOSITION_EXCEPTION).resolveDescription("REASON", e.getMessage()));835 }836 return testCaseExecutionData;837 }838 private TestCaseExecutionData property_executeSqlFromLib(TestCaseExecutionData testCaseExecutionData, TestCaseCountryProperties testCaseCountryProperty, TestCaseExecution tCExecution, boolean forceCalculation) {839 try {840 String script = this.sqlLibraryService.findSqlLibraryByKey(testCaseExecutionData.getValue1()).getScript();841 testCaseExecutionData.setValue1(script); //TODO use the new library842 } catch (CerberusException ex) {843 LOG.warn(ex);844 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_SQLLIB_NOTEXIT);845 res.setDescription(res.getDescription().replace("%SQLLIB%", testCaseExecutionData.getValue1()));846 testCaseExecutionData.setPropertyResultMessage(res);847 testCaseExecutionData.setEnd(new Date().getTime());848 return testCaseExecutionData;849 }850 testCaseExecutionData = this.property_getFromSql(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceCalculation);851 return testCaseExecutionData;852 }853 private TestCaseExecutionData property_getFromNetworkTraffic(TestCaseExecutionData testCaseExecutionData, TestCaseCountryProperties testCaseCountryProperty, TestCaseExecution tCExecution, boolean forceCalculation) {854 if ("Y".equalsIgnoreCase(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {855 try {856 //TODO : check if HAR is the same than the last one to avoid to download same har file several times857 // String remoteHarMD5 = "http://" + tCExecution.getRobotExecutorObj().getHost() + ":" + tCExecution.getRobotExecutorObj().getExecutorExtensionPort() + "/getHarMD5?uuid="+tCExecution.getRemoteProxyUUID();858 JSONObject harRes = executorService.getHar(testCaseExecutionData.getValue1(), false, tCExecution.getRobotExecutorObj().getExecutorExtensionHost(), tCExecution.getRobotExecutorObj().getExecutorExtensionPort(),859 tCExecution.getRemoteProxyUUID(), tCExecution.getSystem());860 harRes = harService.enrichWithStats(harRes, tCExecution.getCountryEnvironmentParameters().getDomain(), tCExecution.getSystem());861 //Record result in filessytem.862 testCaseExecutionData.addFileList(recorderService.recordProperty(tCExecution.getId(), testCaseExecutionData.getProperty(), 1, harRes.toString(1)));863 String valueFromJson = this.jsonService.getFromJson(harRes.toString(), null, testCaseExecutionData.getValue2());864 if (valueFromJson != null) {865 testCaseExecutionData.setValue(valueFromJson);866 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMNETWORKTRAFFIC);867 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue2()));868 res.setDescription(res.getDescription().replace("%VALUE%", valueFromJson));869 testCaseExecutionData.setPropertyResultMessage(res);870 } else {871 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMNETWORKTRAFFIC_PATHNOTFOUND);872 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue2()));873 testCaseExecutionData.setPropertyResultMessage(res);874 }875 } catch (Exception ex) {876 LOG.warn("Exception when getting property from Network Traffic.", ex);877 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMNETWORKTRAFFIC_PROXYNOTACTIVE);878 res.setDescription(res.getDescription().replace("%DETAIL%", ex.toString()));879 testCaseExecutionData.setPropertyResultMessage(res);880 testCaseExecutionData.setEnd(new Date().getTime());881 return testCaseExecutionData;882 }883 } else {884 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMNETWORKTRAFFIC_PROXYNOTACTIVE);885 res.setDescription(res.getDescription().replace("%ROBOT%", tCExecution.getRobot()));886 res.setDescription(res.getDescription().replace("%EXECUTOR%", tCExecution.getRobotExecutor()));887 testCaseExecutionData.setPropertyResultMessage(res);888 }889 return testCaseExecutionData;890 }891 private TestCaseExecutionData property_getFromSql(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {892 return sQLService.calculateOnDatabase(testCaseExecutionData, testCaseCountryProperty, tCExecution);893 }894 private TestCaseExecutionData property_calculateText(TestCaseExecutionData testCaseExecutionData, TestCaseCountryProperties testCaseCountryProperty, boolean forceRecalculation) {895 if (TestCaseCountryProperties.NATURE_RANDOM.equals(testCaseCountryProperty.getNature())896 //TODO CTE Voir avec B. Civel "RANDOM_NEW"897 || (testCaseCountryProperty.getNature().equals(TestCaseCountryProperties.NATURE_RANDOMNEW))) {898 if (testCaseCountryProperty.getLength().equals("0")) {899 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_TEXTRANDOMLENGHT0);900 testCaseExecutionData.setPropertyResultMessage(res);901 } else {902 String charset;903 if (testCaseExecutionData.getValue1() != null && !"".equals(testCaseExecutionData.getValue1().trim())) {904 charset = testCaseExecutionData.getValue1();905 } else {906 charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";907 }908 String value = StringUtil.getRandomString(ParameterParserUtil.parseIntegerParam(testCaseCountryProperty.getLength(), 0), charset);909 testCaseExecutionData.setValue(value);910 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_RANDOM);911 res.setDescription(res.getDescription().replace("%FORCED%", forceRecalculation == true ? "Re-" : ""));912 res.setDescription(res.getDescription().replace("%VALUE%", ParameterParserUtil.securePassword(value, testCaseCountryProperty.getProperty())));913 testCaseExecutionData.setPropertyResultMessage(res);914// if (testCaseCountryProperty.getNature().equals("RANDOM_NEW")) {915// //TODO check if value exist on DB ( used in another test case of the revision )916// }917 }918 } else {919 LOG.debug("Setting value : " + testCaseExecutionData.getValue1());920 String value = testCaseExecutionData.getValue1();921 testCaseExecutionData.setValue(value);922 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_TEXT);923 res.setDescription(res.getDescription().replace("%VALUE%", ParameterParserUtil.securePassword(value, testCaseCountryProperty.getProperty())));924 testCaseExecutionData.setPropertyResultMessage(res);925 }926 return testCaseExecutionData;927 }928 private TestCaseExecutionData property_getFromHtmlVisible(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {929 try {930 Identifier identifier = identifierService.convertStringToIdentifier(testCaseExecutionData.getValue1());931 String valueFromHTML = this.webdriverService.getValueFromHTMLVisible(tCExecution.getSession(), identifier);932 if (valueFromHTML != null) {933 testCaseExecutionData.setValue(valueFromHTML);934 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_HTMLVISIBLE);935 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));936 res.setDescription(res.getDescription().replace("%VALUE%", valueFromHTML));937 testCaseExecutionData.setPropertyResultMessage(res);938 } else {939 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTMLVISIBLE_ELEMENTDONOTEXIST);940 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));941 testCaseExecutionData.setPropertyResultMessage(res);942 }943 } catch (NoSuchElementException exception) {944 LOG.debug(exception.toString());945 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTMLVISIBLE_ELEMENTDONOTEXIST);946 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));947 testCaseExecutionData.setPropertyResultMessage(res);948 }949 return testCaseExecutionData;950 }951 private TestCaseExecutionData property_getFromHtml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {952 if (tCExecution.getAppTypeEngine().equals(Application.TYPE_APK)953 || tCExecution.getAppTypeEngine().equals(Application.TYPE_IPA)954 || tCExecution.getAppTypeEngine().equals(Application.TYPE_GUI)) {955 try {956 Identifier identifier = identifierService.convertStringToIdentifier(testCaseExecutionData.getValue1());957 String valueFromHTML = this.webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);958 if (valueFromHTML != null) {959 testCaseExecutionData.setValue(valueFromHTML);960 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_HTML);961 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));962 res.setDescription(res.getDescription().replace("%VALUE%", valueFromHTML));963 testCaseExecutionData.setPropertyResultMessage(res);964 }965 } catch (NoSuchElementException exception) {966 LOG.debug(exception.toString());967 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTML_ELEMENTDONOTEXIST);968 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));969 testCaseExecutionData.setPropertyResultMessage(res);970 }971 } else {972 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_FEATURENOTSUPPORTED);973 res.setDescription(res.getDescription().replace("%APPTYPE%", tCExecution.getAppTypeEngine()));974 res.setDescription(res.getDescription().replace("%PROPTYPE%", testCaseExecutionData.getType()));975 }976 return testCaseExecutionData;977 }978 private TestCaseExecutionData property_getFromJS(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {979 String script = testCaseExecutionData.getValue1();980 String valueFromJS;981 String message = "";982 if (tCExecution.getManualExecution().equals("Y")) {983 MessageEvent mes = new MessageEvent(MessageEventEnum.PROPERTY_NOTPOSSIBLE);984 testCaseExecutionData.setPropertyResultMessage(mes);985 } else {986 try {987 valueFromJS = this.webdriverService.getValueFromJS(tCExecution.getSession(), script);988 } catch (Exception e) {989 message = e.getMessage().split("\n")[0];990 LOG.debug("Exception Running JS Script :" + message);991 valueFromJS = null;992 }993 if (valueFromJS != null) {994 testCaseExecutionData.setValue(valueFromJS);995 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_JS);996 res.setDescription(res.getDescription().replace("%SCRIPT%", script));997 res.setDescription(res.getDescription().replace("%VALUE%", valueFromJS));998 testCaseExecutionData.setPropertyResultMessage(res);999 } else {1000 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_JS_EXCEPTION);1001 res.setDescription(res.getDescription().replace("%EXCEPTION%", message));1002 testCaseExecutionData.setPropertyResultMessage(res);1003 }1004 }1005 return testCaseExecutionData;1006 }1007 private TestCaseExecutionData property_getFromGroovy(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {1008 // Check if script has been correctly defined1009 String script = testCaseExecutionData.getValue1();1010 if (script == null || script.isEmpty()) {1011 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMGROOVY_NULL));1012 return testCaseExecutionData;1013 }1014 // Try to evaluate Groovy script1015 try {1016 String valueFromGroovy = groovyService.eval(script);1017 testCaseExecutionData.setValue(valueFromGroovy);1018 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMGROOVY)1019 .resolveDescription("VALUE", valueFromGroovy));1020 } catch (IGroovyService.IGroovyServiceException e) {1021 LOG.debug("Exception Running Grrovy Script :" + e.getMessage());1022 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMGROOVY_EXCEPTION).resolveDescription("REASON", e.getMessage()));1023 }1024 return testCaseExecutionData;1025 }1026 private TestCaseExecutionData property_getAttributeFromHtml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {1027 MessageEvent res;1028 try {1029 Identifier identifier = identifierService.convertStringToIdentifier(testCaseExecutionData.getValue1());1030 String valueFromHTML = this.webdriverService.getAttributeFromHtml(tCExecution.getSession(), identifier, testCaseExecutionData.getValue2());1031 if (valueFromHTML != null) {1032 testCaseExecutionData.setValue(valueFromHTML);1033 res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETATTRIBUTEFROMHTML);1034 res.setDescription(res.getDescription().replace("%VALUE%", valueFromHTML));1035 } else {1036 res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTML_ATTRIBUTEDONOTEXIST);1037 }1038 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));1039 res.setDescription(res.getDescription().replace("%ATTRIBUTE%", testCaseExecutionData.getValue2()));1040 } catch (NoSuchElementException exception) {1041 LOG.debug(exception.toString());1042 res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTMLVISIBLE_ELEMENTDONOTEXIST);1043 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));1044 }1045 testCaseExecutionData.setPropertyResultMessage(res);1046 return testCaseExecutionData;1047 }1048 private TestCaseExecutionData property_executeSoapFromLib(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {1049 String result = null;1050 AnswerItem<String> answerDecode = new AnswerItem<>();1051 try {1052 AppService appService = this.appServiceService.findAppServiceByKey(testCaseExecutionData.getValue1());1053 if (appService != null) {1054 String decodedEnveloppe = appService.getServiceRequest();1055 String decodedServicePath = appService.getServicePath();1056 String decodedMethod = appService.getOperation();1057 String decodedAttachement = appService.getAttachementURL();1058 if (appService.getServiceRequest().contains("%")) {1059 answerDecode = variableService.decodeStringCompletly(appService.getServiceRequest(), tCExecution, testCaseStepActionExecution, false);1060 decodedEnveloppe = (String) answerDecode.getItem();1061 if (!(answerDecode.isCodeStringEquals("OK"))) {1062 // If anything wrong with the decode --> we stop here with decode message in the action result.1063 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Service Request"));1064 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());1065 LOG.debug("Property interupted due to decode 'SOAP Service Request' Error.");1066 return testCaseExecutionData;1067 }1068 }1069 if (appService.getServicePath().contains("%")) {1070 answerDecode = variableService.decodeStringCompletly(appService.getServicePath(), tCExecution, testCaseStepActionExecution, false);1071 decodedServicePath = (String) answerDecode.getItem();1072 if (!(answerDecode.isCodeStringEquals("OK"))) {1073 // If anything wrong with the decode --> we stop here with decode message in the action result.1074 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Service Path"));1075 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());1076 LOG.debug("Property interupted due to decode 'SOAP Service Path.");1077 return testCaseExecutionData;1078 }1079 }1080 if (appService.getOperation().contains("%")) {1081 answerDecode = variableService.decodeStringCompletly(appService.getOperation(), tCExecution, testCaseStepActionExecution, false);1082 decodedMethod = (String) answerDecode.getItem();1083 if (!(answerDecode.isCodeStringEquals("OK"))) {1084 // If anything wrong with the decode --> we stop here with decode message in the action result.1085 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Operation"));1086 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());1087 LOG.debug("Property interupted due to decode 'SOAP Operation.");1088 return testCaseExecutionData;1089 }1090 }1091 if (appService.getAttachementURL().contains("%")) {1092 answerDecode = variableService.decodeStringCompletly(appService.getAttachementURL(), tCExecution, testCaseStepActionExecution, false);1093 decodedAttachement = (String) answerDecode.getItem();1094 if (!(answerDecode.isCodeStringEquals("OK"))) {1095 // If anything wrong with the decode --> we stop here with decode message in the action r1096 // If anything wrong with the decode --> we stop here with decode message in the acesult.1097 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Attachement URL"));1098 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());1099 LOG.debug("Property interupted due to decode 'SOAP Attachement URL.");1100 return testCaseExecutionData;1101 }1102 }1103 //Call Soap and set LastSoapCall of the testCaseExecution.1104 AnswerItem soapCall = soapService.callSOAP(decodedEnveloppe, decodedServicePath, decodedMethod, decodedAttachement, null, null, 60000, tCExecution.getApplicationObj().getSystem());1105 AppService se1 = (AppService) soapCall.getItem();1106// tCExecution.setLastSOAPCalled(soapCall);1107 if (soapCall.isCodeEquals(200)) {1108// SOAPExecution lastSoapCalled = (SOAPExecution) tCExecution.getLastSOAPCalled().getItem();1109 String xmlResponse = se1.getResponseHTTPBody();1110 result = xmlUnitService.getFromXml(xmlResponse, appService.getAttachementURL());1111 }1112 if (result != null) {1113 testCaseExecutionData.setValue(result);1114 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_SOAP);1115 testCaseExecutionData.setPropertyResultMessage(res);1116 } else {1117 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SOAPFROMLIB_NODATA);1118 testCaseExecutionData.setPropertyResultMessage(res);1119 }1120 }1121 } catch (CerberusException exception) {1122 LOG.error(exception.toString(), exception);1123 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_TESTDATA_PROPERTYDONOTEXIST);1124 res.setDescription(res.getDescription().replace("%PROPERTY%", testCaseExecutionData.getValue1()));1125 testCaseExecutionData.setPropertyResultMessage(res);1126 } catch (CerberusEventException ex) {1127 LOG.error(ex.toString(), ex);1128 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP);1129 message.setDescription(message.getDescription().replace("%SOAPNAME%", testCaseExecutionData.getValue1()));1130 message.setDescription(message.getDescription().replace("%DESCRIPTION%", ex.getMessageError().getDescription()));1131 testCaseExecutionData.setPropertyResultMessage(message);1132 }1133 return testCaseExecutionData;1134 }1135 private TestCaseExecutionData property_getFromXml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {1136 // 1. Get XML value to parse1137 String xmlToParse = null;1138 // If value2 is defined, then take it as XML value to parse1139 if (!(StringUtil.isNullOrEmpty(testCaseExecutionData.getValue2()))) {1140 xmlToParse = testCaseExecutionData.getValue2();1141 } // Else try to get the last known response from service call1142 else if (tCExecution.getLastServiceCalled() != null) {1143 xmlToParse = tCExecution.getLastServiceCalled().getResponseHTTPBody();1144 } // If XML to parse is still null, then there is an error in XML value definition1145 else if (xmlToParse == null) {1146 testCaseExecutionData.setPropertyResultMessage(1147 new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMXML)1148 .resolveDescription("VALUE1", testCaseExecutionData.getValue1())1149 .resolveDescription("VALUE2", testCaseExecutionData.getValue2()));1150 return testCaseExecutionData;1151 }1152 // Else we can try to parse it thanks to the dedicated service1153 try {1154 String valueFromXml = xmlUnitService.getFromXml(xmlToParse, testCaseExecutionData.getValue1());1155 if (valueFromXml != null) {1156 testCaseExecutionData.setValue(valueFromXml);1157 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMXML);1158 res.setDescription(res.getDescription().replace("%VALUE%", valueFromXml));1159 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1160 testCaseExecutionData.setPropertyResultMessage(res);1161 } else {1162 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMXML);1163 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1164 res.setDescription(res.getDescription().replace("%VALUE2%", testCaseExecutionData.getValue2()));1165 testCaseExecutionData.setPropertyResultMessage(res);1166 }1167 } catch (Exception ex) {1168 LOG.debug(ex.toString());1169 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMXML);1170 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1171 res.setDescription(res.getDescription().replace("%VALUE2%", testCaseExecutionData.getValue2()));1172 testCaseExecutionData.setPropertyResultMessage(res);1173 }1174 return testCaseExecutionData;1175 }1176 private TestCaseExecutionData property_getRawFromXml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {1177 // 1. Get XML value to parse1178 String xmlToParse = null;1179 // If value2 is defined, then take it as XML value to parse1180 if (!(StringUtil.isNullOrEmpty(testCaseExecutionData.getValue2()))) {1181 xmlToParse = testCaseExecutionData.getValue2();1182 } // Else try to get the last known response from service call1183 else if (tCExecution.getLastServiceCalled() != null) {1184 xmlToParse = tCExecution.getLastServiceCalled().getResponseHTTPBody();1185 } // If XML to parse is still null, then there is an error in XML value definition1186 else if (xmlToParse == null) {1187 testCaseExecutionData.setPropertyResultMessage(1188 new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMXML)1189 .resolveDescription("VALUE1", testCaseExecutionData.getValue1())1190 .resolveDescription("VALUE2", testCaseExecutionData.getValue2()));...
property_getRawFromXml
Using AI Code Generation
1package com.mycompany.myproject;2import org.cerberus.engine.gwt.impl.PropertyService;3import org.cerberus.engine.gwt.impl.PropertyServiceFactory;4import org.cerberus.engine.gwt.impl.PropertyServiceFactoryImpl;5import org.cerberus.engine.gwt.impl.PropertyServiceFactoryImpl.PropertyServiceType;6import org.cerberus.engine.gwt.impl.PropertyServiceFactoryImpl.PropertyServiceType.PropertyServiceTypeConstant;7public class PropertyServiceTest {8 public static void main(String[] args) {9 PropertyServiceFactory propertyServiceFactory = new PropertyServiceFactoryImpl();10 PropertyService propertyService = propertyServiceFactory.getPropertyService(PropertyServiceTypeConstant.XML);11 String propertyValue = propertyService.getRawFromXml("myproperty", "myfilepath");12 System.out.println(propertyValue);13 }14}
property_getRawFromXml
Using AI Code Generation
1importClass(org.cerberus.engine.gwt.impl.PropertyService);2var propertyService = new PropertyService();3var property = propertyService.getPropertyFromXml("Test", "TestProperty");4var rawValue = propertyService.getRawFromXml(property);5logEvent("Raw property value: " + rawValue);6logDebug("Raw property value: " + rawValue);7println("Raw property value: " + rawValue);8logCSV("Raw property value: " + rawValue);9logXML("Raw property value: " + rawValue);[/code]10importClass(org.cerberus.engine.gwt.impl.PropertyService);11var propertyService = new PropertyService();12var property = propertyService.getPropertyFromProperty("Test", "TestProperty");13var rawValue = propertyService.getRawFromProperty(property);14logEvent("Raw property value: " + rawValue);15logDebug("Raw property value: " + rawValue);16println("Raw property value: " + rawValue);17logCSV("Raw property value: " + rawValue);18logXML("Raw property value: " + rawValue);[/code]
property_getRawFromXml
Using AI Code Generation
1importPackage(Packages.org.cerberus.engine.gwt.impl);2var xmlFilePath = "/path/to/xml/file/properties.xml";3var propertyName = "myProperty";4var propertyValue = PropertyService.property_getRawFromXml(xmlFilePath, propertyName);5println("property value: " + propertyValue);6println("type of property value: " + typeof propertyValue);7println("length of property value: " + propertyValue.length);8println("property value as a string: " + propertyValue.toString());9println("property value as a number: " + propertyValue.valueOf());10println("property value as a boolean: " + propertyValue.valueOf());11println("property value as a date: " + propertyValue.valueOf());12println("property value as a regexp: " + propertyValue.valueOf());13println("property value as a function: " + propertyValue.valueOf());
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!