Best Cerberus-source code snippet using org.cerberus.engine.gwt.impl.PropertyService.property_getFromJson
Source:PropertyService.java
...649 case TestCaseCountryProperties.TYPE_GETDIFFERENCESFROMXML:650 testCaseExecutionData = this.property_getDifferencesFromXml(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);651 break;652 case TestCaseCountryProperties.TYPE_GETFROMJSON:653 testCaseExecutionData = this.property_getFromJson(testCaseExecutionData, tCExecution, forceRecalculation);654 break;655 case TestCaseCountryProperties.TYPE_GETFROMGROOVY:656 testCaseExecutionData = this.property_getFromGroovy(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);657 break;658 case TestCaseCountryProperties.TYPE_GETFROMCOMMAND:659 testCaseExecutionData = this.property_getFromCommand(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);660 break;661 case TestCaseCountryProperties.TYPE_GETELEMENTPOSITION:662 testCaseExecutionData = this.property_getElementPosition(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);663 break;664 case TestCaseCountryProperties.TYPE_GETFROMNETWORKTRAFFIC:665 testCaseExecutionData = this.property_getFromNetworkTraffic(testCaseExecutionData, testCaseCountryProperty, tCExecution, forceRecalculation);666 break;667 // DEPRECATED Property types.668 case TestCaseCountryProperties.TYPE_EXECUTESOAPFROMLIB: // DEPRECATED669 testCaseExecutionData = this.property_executeSoapFromLib(testCaseExecutionData, tCExecution, testCaseStepActionExecution, testCaseCountryProperty, forceRecalculation);670 res = testCaseExecutionData.getPropertyResultMessage();671 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());672 testCaseExecutionData.setPropertyResultMessage(res);673 logEventService.createForPrivateCalls("ENGINE", TestCaseCountryProperties.TYPE_EXECUTESOAPFROMLIB, MESSAGE_DEPRECATED + " Deprecated Property triggered by TestCase : ['" + test + "|" + testCase + "']");674 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Property " + TestCaseCountryProperties.TYPE_EXECUTESOAPFROMLIB + " triggered by TestCase : ['" + test + "'|'" + testCase + "']");675 break;676 case TestCaseCountryProperties.TYPE_EXECUTESQLFROMLIB: // DEPRECATED677 testCaseExecutionData = this.property_executeSqlFromLib(testCaseExecutionData, testCaseCountryProperty, tCExecution, forceRecalculation);678 res = testCaseExecutionData.getPropertyResultMessage();679 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());680 testCaseExecutionData.setPropertyResultMessage(res);681 logEventService.createForPrivateCalls("ENGINE", TestCaseCountryProperties.TYPE_EXECUTESQLFROMLIB, MESSAGE_DEPRECATED + " Deprecated Property triggered by TestCase : ['" + test + "|" + testCase + "']");682 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Property " + TestCaseCountryProperties.TYPE_EXECUTESQLFROMLIB + " triggered by TestCase : ['" + test + "'|'" + testCase + "']");683 break;684 default:685 res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_UNKNOWNPROPERTY);686 res.setDescription(res.getDescription().replace("%PROPERTY%", testCaseCountryProperty.getType()));687 testCaseExecutionData.setPropertyResultMessage(res);688 }689 execution_count++;690 }691 if (execution_count >= 2) { // If there were at least 1 retry, we notify it in the result message.692 res = testCaseExecutionData.getPropertyResultMessage();693 res.setDescription("Retried " + (execution_count - 1) + " time(s) with " + periodms + "ms period - " + res.getDescription());694 testCaseExecutionData.setPropertyResultMessage(res);695 }696 if (forced_retry) { // If the retry and period parameter was changed, we notify it in the result message.697 res = testCaseExecutionData.getPropertyResultMessage();698 res.setDescription(forced_retry_message + " - " + res.getDescription());699 testCaseExecutionData.setPropertyResultMessage(res);700 }701 } else {702 // cache activated and entry exist. We set the current value with cache entry data and notify the result from the messsage.703 TestCaseExecutionData testCaseExecutionDataFromCache = data;704 testCaseExecutionData.setFromCache("Y");705 testCaseExecutionData.setDataLib(testCaseExecutionDataFromCache.getDataLib());706 testCaseExecutionData.setValue(testCaseExecutionDataFromCache.getValue());707 testCaseExecutionData.setJsonResult(testCaseExecutionDataFromCache.getJsonResult());708 DateFormat df = new SimpleDateFormat(DateUtil.DATE_FORMAT_DISPLAY);709 res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_FROMCACHE).resolveDescription("ID", String.valueOf(testCaseExecutionDataFromCache.getId())).resolveDescription("DATE", df.format(testCaseExecutionDataFromCache.getStart()));710 testCaseExecutionData.setPropertyResultMessage(res);711 if (!StringUtil.isNullOrEmpty(testCaseExecutionDataFromCache.getJsonResult())) {712 // Convert json to HashMap.713 List<HashMap<String, String>> result = null;714 result = new ArrayList<>();715 try {716 LOG.debug("Converting Json : " + testCaseExecutionDataFromCache.getJsonResult());717 JSONArray json = new JSONArray(testCaseExecutionDataFromCache.getJsonResult());718 for (int i = 0; i < json.length(); i++) {719 JSONObject explrObject = json.getJSONObject(i);720 LOG.debug(explrObject.toString());721 HashMap<String, String> resultHash = new HashMap<>();722 Iterator<?> nameItr = explrObject.keys();723 while (nameItr.hasNext()) {724 String name = (String) nameItr.next();725 if (name.equals("KEY")) {726 resultHash.put("", explrObject.getString(name));727 } else {728 resultHash.put(name, explrObject.getString(name));729 }730 }731 result.add(resultHash);732 }733 } catch (JSONException ex) {734 java.util.logging.Logger.getLogger(PropertyService.class.getName()).log(Level.SEVERE, null, ex);735 LOG.error(ex, ex);736 }737 testCaseExecutionData.setDataLibRawData(result);738 //Record result in filessytem.739 recorderService.recordTestDataLibProperty(tCExecution.getId(), testCaseCountryProperty.getProperty(), 1, result);740 }741 }742 } catch (CerberusEventException ex) {743 LOG.error(ex.toString(), ex);744 testCaseExecutionData.setEnd(new Date().getTime());745 testCaseExecutionData.setPropertyResultMessage(ex.getMessageError());746 }747 testCaseExecutionData.setEnd(new Date().getTime());748 if (LOG.isDebugEnabled()) {749 LOG.debug("Finished to calculate Property : '" + testCaseCountryProperty.getProperty() + "'");750 }751 }752 private TestCaseExecutionData property_getFromCommand(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceRecalculation) {753 // Check if script has been correctly defined754 String script = testCaseExecutionData.getValue1();755 if (script == null || script.isEmpty()) {756 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMCOMMAND_NULL));757 return testCaseExecutionData;758 }759 // Try to evaluate Command script760 try {761 if (tCExecution.getApplicationObj().getType().equals(Application.TYPE_APK)) {762 String message = androidAppiumService.executeCommandString(tCExecution.getSession(), script, "");763 String value = "";764 if (!StringUtil.isNullOrEmpty(message)) {765 value = message;766 }767 testCaseExecutionData.setValue(value);768 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMCOMMAND).resolveDescription("VALUE", value));769 } else {770 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_FEATURENOTSUPPORTED);771 res.setDescription(res.getDescription().replace("%APPTYPE%", tCExecution.getApplicationObj().getType()));772 res.setDescription(res.getDescription().replace("%PROPTYPE%", testCaseExecutionData.getType()));773 testCaseExecutionData.setPropertyResultMessage(res);774 }775 } catch (Exception e) {776 LOG.debug("Exception Running Command Script :" + e.getMessage());777 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMCOMMAND_EXCEPTION).resolveDescription("REASON", e.getMessage()));778 }779 return testCaseExecutionData;780 }781 private TestCaseExecutionData property_getElementPosition(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceRecalculation) {782 // Check if script has been correctly defined783 String script = testCaseExecutionData.getValue1();784 if (script == null || script.isEmpty()) {785 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETELEMENTPOSITION_NULL));786 return testCaseExecutionData;787 }788 try {789 Identifier identifier = new Identifier();790 if (script != null) {791 identifier = identifierService.convertStringToIdentifier(script);792 }793 if (tCExecution.getApplicationObj().getType().equals(Application.TYPE_APK)) {794 String message = androidAppiumService.getElementPosition(tCExecution.getSession(), identifier);795 String value = "";796 if (!StringUtil.isNullOrEmpty(message)) {797 value = message;798 }799 testCaseExecutionData.setValue(value);800 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETELEMENTPOSITION).resolveDescription("VALUE", value));801 } else if (tCExecution.getApplicationObj().getType().equals(Application.TYPE_IPA)) {802 String message = iosAppiumService.getElementPosition(tCExecution.getSession(), identifier);803 String value = "";804 if (!StringUtil.isNullOrEmpty(message)) {805 value = message;806 }807 testCaseExecutionData.setValue(value);808 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETELEMENTPOSITION).resolveDescription("VALUE", value));809 } else {810 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_FEATURENOTSUPPORTED);811 res.setDescription(res.getDescription().replace("%APPTYPE%", tCExecution.getApplicationObj().getType()));812 res.setDescription(res.getDescription().replace("%PROPTYPE%", testCaseExecutionData.getType()));813 testCaseExecutionData.setPropertyResultMessage(res);814 }815 } catch (Exception e) {816 LOG.debug("Exception Running Command Script :" + e.getMessage());817 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETELEMENTPOSITION_EXCEPTION).resolveDescription("REASON", e.getMessage()));818 }819 return testCaseExecutionData;820 }821 private TestCaseExecutionData property_executeSqlFromLib(TestCaseExecutionData testCaseExecutionData, TestCaseCountryProperties testCaseCountryProperty, TestCaseExecution tCExecution, boolean forceCalculation) {822 try {823 String script = this.sqlLibraryService.findSqlLibraryByKey(testCaseExecutionData.getValue1()).getScript();824 testCaseExecutionData.setValue1(script); //TODO use the new library 825 } catch (CerberusException ex) {826 LOG.warn(ex);827 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_SQLLIB_NOTEXIT);828 res.setDescription(res.getDescription().replace("%SQLLIB%", testCaseExecutionData.getValue1()));829 testCaseExecutionData.setPropertyResultMessage(res);830 testCaseExecutionData.setEnd(new Date().getTime());831 return testCaseExecutionData;832 }833 testCaseExecutionData = this.property_getFromSql(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceCalculation);834 return testCaseExecutionData;835 }836 private TestCaseExecutionData property_getFromNetworkTraffic(TestCaseExecutionData testCaseExecutionData, TestCaseCountryProperties testCaseCountryProperty, TestCaseExecution tCExecution, boolean forceCalculation) {837 if (tCExecution.getApplicationObj().getType().equals(Application.TYPE_GUI)) {838 try {839 //TODO : check if HAR is the same than the last one to avoid to download same har file several times840 // String remoteHarMD5 = "http://" + tCExecution.getRobotExecutorObj().getHost() + ":" + tCExecution.getRobotExecutorObj().getExecutorExtensionPort() + "/getHarMD5?uuid="+tCExecution.getRemoteProxyUUID();841 //getHarFile842 String url = "http://" + tCExecution.getRobotExecutorObj().getHost() + ":" + tCExecution.getRobotExecutorObj().getExecutorExtensionPort() + "/getHar?uuid=" + tCExecution.getRemoteProxyUUID();843 //tCExecution.addFileList(recorderService.recordHarLog(tCExecution, url));844 testCaseExecutionData.setValue2(url);845 testCaseExecutionData = this.property_getFromJson(testCaseExecutionData, tCExecution, forceCalculation);846 } catch (Exception ex) {847 LOG.warn(ex);848 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_SQLLIB_NOTEXIT);849 res.setDescription(res.getDescription().replace("%SQLLIB%", testCaseExecutionData.getValue1()));850 testCaseExecutionData.setPropertyResultMessage(res);851 testCaseExecutionData.setEnd(new Date().getTime());852 return testCaseExecutionData;853 }854 } else {855 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_FEATURENOTSUPPORTED);856 res.setDescription(res.getDescription().replace("%APPTYPE%", tCExecution.getApplicationObj().getType()));857 res.setDescription(res.getDescription().replace("%PROPTYPE%", testCaseExecutionData.getType()));858 testCaseExecutionData.setPropertyResultMessage(res);859 }860 return testCaseExecutionData;861 }862 private TestCaseExecutionData property_getFromSql(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {863 return sQLService.calculateOnDatabase(testCaseExecutionData, testCaseCountryProperty, tCExecution);864 }865 private TestCaseExecutionData property_calculateText(TestCaseExecutionData testCaseExecutionData, TestCaseCountryProperties testCaseCountryProperty, boolean forceRecalculation) {866 if (TestCaseCountryProperties.NATURE_RANDOM.equals(testCaseCountryProperty.getNature())867 //TODO CTE Voir avec B. Civel "RANDOM_NEW"868 || (testCaseCountryProperty.getNature().equals(TestCaseCountryProperties.NATURE_RANDOMNEW))) {869 if (testCaseCountryProperty.getLength().equals("0")) {870 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_TEXTRANDOMLENGHT0);871 testCaseExecutionData.setPropertyResultMessage(res);872 } else {873 String charset;874 if (testCaseExecutionData.getValue1() != null && !"".equals(testCaseExecutionData.getValue1().trim())) {875 charset = testCaseExecutionData.getValue1();876 } else {877 charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";878 }879 String value = StringUtil.getRandomString(ParameterParserUtil.parseIntegerParam(testCaseCountryProperty.getLength(), 0), charset);880 testCaseExecutionData.setValue(value);881 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_RANDOM);882 res.setDescription(res.getDescription().replace("%FORCED%", forceRecalculation == true ? "Re-" : ""));883 res.setDescription(res.getDescription().replace("%VALUE%", ParameterParserUtil.securePassword(value, testCaseCountryProperty.getProperty())));884 testCaseExecutionData.setPropertyResultMessage(res);885// if (testCaseCountryProperty.getNature().equals("RANDOM_NEW")) {886// //TODO check if value exist on DB ( used in another test case of the revision )887// }888 }889 } else {890 LOG.debug("Setting value : " + testCaseExecutionData.getValue1());891 String value = testCaseExecutionData.getValue1();892 testCaseExecutionData.setValue(value);893 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_TEXT);894 res.setDescription(res.getDescription().replace("%VALUE%", ParameterParserUtil.securePassword(value, testCaseCountryProperty.getProperty())));895 testCaseExecutionData.setPropertyResultMessage(res);896 }897 return testCaseExecutionData;898 }899 private TestCaseExecutionData property_getFromHtmlVisible(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {900 try {901 Identifier identifier = identifierService.convertStringToIdentifier(testCaseExecutionData.getValue1());902 String valueFromHTML = this.webdriverService.getValueFromHTMLVisible(tCExecution.getSession(), identifier);903 if (valueFromHTML != null) {904 testCaseExecutionData.setValue(valueFromHTML);905 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_HTMLVISIBLE);906 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));907 res.setDescription(res.getDescription().replace("%VALUE%", valueFromHTML));908 testCaseExecutionData.setPropertyResultMessage(res);909 } else {910 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTMLVISIBLE_ELEMENTDONOTEXIST);911 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));912 testCaseExecutionData.setPropertyResultMessage(res);913 }914 } catch (NoSuchElementException exception) {915 LOG.debug(exception.toString());916 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTMLVISIBLE_ELEMENTDONOTEXIST);917 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));918 testCaseExecutionData.setPropertyResultMessage(res);919 }920 return testCaseExecutionData;921 }922 private TestCaseExecutionData property_getFromHtml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {923 if (tCExecution.getApplicationObj().getType().equals(Application.TYPE_APK)924 || tCExecution.getApplicationObj().getType().equals(Application.TYPE_IPA)925 || tCExecution.getApplicationObj().getType().equals(Application.TYPE_GUI)) {926 try {927 Identifier identifier = identifierService.convertStringToIdentifier(testCaseExecutionData.getValue1());928 String valueFromHTML = this.webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);929 if (valueFromHTML != null) {930 testCaseExecutionData.setValue(valueFromHTML);931 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_HTML);932 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));933 res.setDescription(res.getDescription().replace("%VALUE%", valueFromHTML));934 testCaseExecutionData.setPropertyResultMessage(res);935 }936 } catch (NoSuchElementException exception) {937 LOG.debug(exception.toString());938 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTML_ELEMENTDONOTEXIST);939 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));940 testCaseExecutionData.setPropertyResultMessage(res);941 }942 } else {943 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_FEATURENOTSUPPORTED);944 res.setDescription(res.getDescription().replace("%APPTYPE%", tCExecution.getApplicationObj().getType()));945 res.setDescription(res.getDescription().replace("%PROPTYPE%", testCaseExecutionData.getType()));946 }947 return testCaseExecutionData;948 }949 private TestCaseExecutionData property_getFromJS(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {950 String script = testCaseExecutionData.getValue1();951 String valueFromJS;952 String message = "";953 if (tCExecution.getManualExecution().equals("Y")) {954 MessageEvent mes = new MessageEvent(MessageEventEnum.PROPERTY_NOTPOSSIBLE);955 testCaseExecutionData.setPropertyResultMessage(mes);956 } else {957 try {958 valueFromJS = this.webdriverService.getValueFromJS(tCExecution.getSession(), script);959 } catch (Exception e) {960 message = e.getMessage().split("\n")[0];961 LOG.debug("Exception Running JS Script :" + message);962 valueFromJS = null;963 }964 if (valueFromJS != null) {965 testCaseExecutionData.setValue(valueFromJS);966 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_JS);967 res.setDescription(res.getDescription().replace("%SCRIPT%", script));968 res.setDescription(res.getDescription().replace("%VALUE%", valueFromJS));969 testCaseExecutionData.setPropertyResultMessage(res);970 } else {971 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_JS_EXCEPTION);972 res.setDescription(res.getDescription().replace("%EXCEPTION%", message));973 testCaseExecutionData.setPropertyResultMessage(res);974 }975 }976 return testCaseExecutionData;977 }978 private TestCaseExecutionData property_getFromGroovy(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {979 // Check if script has been correctly defined980 String script = testCaseExecutionData.getValue1();981 if (script == null || script.isEmpty()) {982 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMGROOVY_NULL));983 return testCaseExecutionData;984 }985 // Try to evaluate Groovy script986 try {987 String valueFromGroovy = groovyService.eval(script);988 testCaseExecutionData.setValue(valueFromGroovy);989 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMGROOVY)990 .resolveDescription("VALUE", valueFromGroovy));991 } catch (IGroovyService.IGroovyServiceException e) {992 LOG.debug("Exception Running Grrovy Script :" + e.getMessage());993 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMGROOVY_EXCEPTION).resolveDescription("REASON", e.getMessage()));994 }995 return testCaseExecutionData;996 }997 private TestCaseExecutionData property_getAttributeFromHtml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {998 MessageEvent res;999 try {1000 Identifier identifier = identifierService.convertStringToIdentifier(testCaseExecutionData.getValue1());1001 String valueFromHTML = this.webdriverService.getAttributeFromHtml(tCExecution.getSession(), identifier, testCaseExecutionData.getValue2());1002 if (valueFromHTML != null) {1003 testCaseExecutionData.setValue(valueFromHTML);1004 res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETATTRIBUTEFROMHTML);1005 res.setDescription(res.getDescription().replace("%VALUE%", valueFromHTML));1006 } else {1007 res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTML_ATTRIBUTEDONOTEXIST);1008 }1009 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));1010 res.setDescription(res.getDescription().replace("%ATTRIBUTE%", testCaseExecutionData.getValue2()));1011 } catch (NoSuchElementException exception) {1012 LOG.debug(exception.toString());1013 res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTMLVISIBLE_ELEMENTDONOTEXIST);1014 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));1015 }1016 testCaseExecutionData.setPropertyResultMessage(res);1017 return testCaseExecutionData;1018 }1019 private TestCaseExecutionData property_executeSoapFromLib(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {1020 String result = null;1021 AnswerItem<String> answerDecode = new AnswerItem<>();1022 try {1023 AppService appService = this.appServiceService.findAppServiceByKey(testCaseExecutionData.getValue1());1024 if (appService != null) {1025 String decodedEnveloppe = appService.getServiceRequest();1026 String decodedServicePath = appService.getServicePath();1027 String decodedMethod = appService.getOperation();1028 String decodedAttachement = appService.getAttachementURL();1029 if (appService.getServiceRequest().contains("%")) {1030 answerDecode = variableService.decodeStringCompletly(appService.getServiceRequest(), tCExecution, testCaseStepActionExecution, false);1031 decodedEnveloppe = (String) answerDecode.getItem();1032 if (!(answerDecode.isCodeStringEquals("OK"))) {1033 // If anything wrong with the decode --> we stop here with decode message in the action result.1034 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Service Request"));1035 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());1036 LOG.debug("Property interupted due to decode 'SOAP Service Request' Error.");1037 return testCaseExecutionData;1038 }1039 }1040 if (appService.getServicePath().contains("%")) {1041 answerDecode = variableService.decodeStringCompletly(appService.getServicePath(), tCExecution, testCaseStepActionExecution, false);1042 decodedServicePath = (String) answerDecode.getItem();1043 if (!(answerDecode.isCodeStringEquals("OK"))) {1044 // If anything wrong with the decode --> we stop here with decode message in the action result.1045 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Service Path"));1046 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());1047 LOG.debug("Property interupted due to decode 'SOAP Service Path.");1048 return testCaseExecutionData;1049 }1050 }1051 if (appService.getOperation().contains("%")) {1052 answerDecode = variableService.decodeStringCompletly(appService.getOperation(), tCExecution, testCaseStepActionExecution, false);1053 decodedMethod = (String) answerDecode.getItem();1054 if (!(answerDecode.isCodeStringEquals("OK"))) {1055 // If anything wrong with the decode --> we stop here with decode message in the action result.1056 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Operation"));1057 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());1058 LOG.debug("Property interupted due to decode 'SOAP Operation.");1059 return testCaseExecutionData;1060 }1061 }1062 if (appService.getAttachementURL().contains("%")) {1063 answerDecode = variableService.decodeStringCompletly(appService.getAttachementURL(), tCExecution, testCaseStepActionExecution, false);1064 decodedAttachement = (String) answerDecode.getItem();1065 if (!(answerDecode.isCodeStringEquals("OK"))) {1066 // If anything wrong with the decode --> we stop here with decode message in the action result.1067 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Attachement URL"));1068 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());1069 LOG.debug("Property interupted due to decode 'SOAP Attachement URL.");1070 return testCaseExecutionData;1071 }1072 }1073 //Call Soap and set LastSoapCall of the testCaseExecution.1074 AnswerItem soapCall = soapService.callSOAP(decodedEnveloppe, decodedServicePath, decodedMethod, decodedAttachement, null, null, 60000, tCExecution.getApplicationObj().getSystem());1075 AppService se1 = (AppService) soapCall.getItem();1076// tCExecution.setLastSOAPCalled(soapCall);1077 if (soapCall.isCodeEquals(200)) {1078// SOAPExecution lastSoapCalled = (SOAPExecution) tCExecution.getLastSOAPCalled().getItem();1079 String xmlResponse = se1.getResponseHTTPBody();1080 result = xmlUnitService.getFromXml(xmlResponse, appService.getAttachementURL());1081 }1082 if (result != null) {1083 testCaseExecutionData.setValue(result);1084 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_SOAP);1085 testCaseExecutionData.setPropertyResultMessage(res);1086 } else {1087 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SOAPFROMLIB_NODATA);1088 testCaseExecutionData.setPropertyResultMessage(res);1089 }1090 }1091 } catch (CerberusException exception) {1092 LOG.error(exception.toString(), exception);1093 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_TESTDATA_PROPERTYDONOTEXIST);1094 res.setDescription(res.getDescription().replace("%PROPERTY%", testCaseExecutionData.getValue1()));1095 testCaseExecutionData.setPropertyResultMessage(res);1096 } catch (CerberusEventException ex) {1097 LOG.error(ex.toString(), ex);1098 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP);1099 message.setDescription(message.getDescription().replace("%SOAPNAME%", testCaseExecutionData.getValue1()));1100 message.setDescription(message.getDescription().replace("%DESCRIPTION%", ex.getMessageError().getDescription()));1101 testCaseExecutionData.setPropertyResultMessage(message);1102 }1103 return testCaseExecutionData;1104 }1105 private TestCaseExecutionData property_getFromXml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {1106 // 1. Get XML value to parse1107 String xmlToParse = null;1108 // If value2 is defined, then take it as XML value to parse1109 if (!(StringUtil.isNullOrEmpty(testCaseExecutionData.getValue2()))) {1110 xmlToParse = testCaseExecutionData.getValue2();1111 } // Else try to get the last known response from service call1112 else if (tCExecution.getLastServiceCalled() != null) {1113 xmlToParse = tCExecution.getLastServiceCalled().getResponseHTTPBody();1114 } // If XML to parse is still null, then there is an error in XML value definition1115 else if (xmlToParse == null) {1116 testCaseExecutionData.setPropertyResultMessage(1117 new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMXML)1118 .resolveDescription("VALUE1", testCaseExecutionData.getValue1())1119 .resolveDescription("VALUE2", testCaseExecutionData.getValue2()));1120 return testCaseExecutionData;1121 }1122 // Else we can try to parse it thanks to the dedicated service1123 try {1124 String valueFromXml = xmlUnitService.getFromXml(xmlToParse, testCaseExecutionData.getValue1());1125 if (valueFromXml != null) {1126 testCaseExecutionData.setValue(valueFromXml);1127 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMXML);1128 res.setDescription(res.getDescription().replace("%VALUE%", valueFromXml));1129 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1130 testCaseExecutionData.setPropertyResultMessage(res);1131 } else {1132 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMXML);1133 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1134 res.setDescription(res.getDescription().replace("%VALUE2%", testCaseExecutionData.getValue2()));1135 testCaseExecutionData.setPropertyResultMessage(res);1136 }1137 } catch (Exception ex) {1138 LOG.debug(ex.toString());1139 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMXML);1140 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1141 res.setDescription(res.getDescription().replace("%VALUE2%", testCaseExecutionData.getValue2()));1142 testCaseExecutionData.setPropertyResultMessage(res);1143 }1144 return testCaseExecutionData;1145 }1146 private TestCaseExecutionData property_getFromCookie(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {1147 try {1148 String valueFromCookie = this.webdriverService.getFromCookie(tCExecution.getSession(), testCaseExecutionData.getValue1(), testCaseExecutionData.getValue2());1149 if (valueFromCookie != null) {1150 if (!valueFromCookie.equals("cookieNotFound")) {1151 testCaseExecutionData.setValue(valueFromCookie);1152 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMCOOKIE);1153 res.setDescription(res.getDescription().replace("%COOKIE%", testCaseExecutionData.getValue1()));1154 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue2()));1155 res.setDescription(res.getDescription().replace("%VALUE%", valueFromCookie));1156 testCaseExecutionData.setPropertyResultMessage(res);1157 } else {1158 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMCOOKIE_COOKIENOTFOUND);1159 res.setDescription(res.getDescription().replace("%COOKIE%", testCaseExecutionData.getValue1()));1160 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue2()));1161 testCaseExecutionData.setPropertyResultMessage(res);1162 }1163 } else {1164 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMCOOKIE_PARAMETERNOTFOUND);1165 res.setDescription(res.getDescription().replace("%COOKIE%", testCaseExecutionData.getValue1()));1166 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue2()));1167 testCaseExecutionData.setPropertyResultMessage(res);1168 }1169 } catch (Exception exception) {1170 LOG.debug(exception.toString());1171 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMCOOKIE_COOKIENOTFOUND);1172 res.setDescription(res.getDescription().replace("%COOKIE%", testCaseExecutionData.getValue1()));1173 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue2()));1174 testCaseExecutionData.setPropertyResultMessage(res);1175 }1176 return testCaseExecutionData;1177 }1178 private TestCaseExecutionData property_getDifferencesFromXml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {1179 try {1180 LOG.debug("Computing differences between " + testCaseExecutionData.getValue1() + " and " + testCaseExecutionData.getValue2());1181 String differences = xmlUnitService.getDifferencesFromXml(testCaseExecutionData.getValue1(), testCaseExecutionData.getValue2());1182 if (differences != null) {1183 LOG.debug("Computing done.");1184 testCaseExecutionData.setValue(differences);1185 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETDIFFERENCESFROMXML);1186 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1187 res.setDescription(res.getDescription().replace("%VALUE2%", testCaseExecutionData.getValue2()));1188 testCaseExecutionData.setPropertyResultMessage(res);1189 } else {1190 LOG.debug("Computing failed.");1191 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETDIFFERENCESFROMXML);1192 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1193 res.setDescription(res.getDescription().replace("%VALUE2%", testCaseExecutionData.getValue2()));1194 testCaseExecutionData.setPropertyResultMessage(res);1195 }1196 } catch (Exception ex) {1197 LOG.debug(ex.toString());1198 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETDIFFERENCESFROMXML);1199 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1200 res.setDescription(res.getDescription().replace("%VALUE2%", testCaseExecutionData.getValue2()));1201 testCaseExecutionData.setPropertyResultMessage(res);1202 }1203 return testCaseExecutionData;1204 }1205 private TestCaseExecutionData property_getFromJson(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, boolean forceRecalculation) {1206 String jsonResponse = "";1207 try {1208 /**1209 * If tCExecution LastServiceCalled exist, get the response;1210 */1211 if (null != tCExecution.getLastServiceCalled()) {1212 jsonResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();1213 }1214 if (!(StringUtil.isNullOrEmpty(testCaseExecutionData.getValue2()))) {1215 try {1216 URL myurl;1217 myurl = new URL(testCaseExecutionData.getValue2());1218 String str = "";1219 StringBuilder sb = new StringBuilder();...
property_getFromJson
Using AI Code Generation
1org.cerberus.engine.gwt.impl.PropertyService propertyService = new org.cerberus.engine.gwt.impl.PropertyService();2org.cerberus.engine.property.Property property = propertyService.getPropertyFromJson("myProperty");3org.cerberus.engine.gwt.impl.PropertyService propertyService = new org.cerberus.engine.gwt.impl.PropertyService();4org.cerberus.engine.property.Property property = propertyService.getPropertyFromJson("myProperty");5org.cerberus.engine.gwt.impl.PropertyService propertyService = new org.cerberus.engine.gwt.impl.PropertyService();6org.cerberus.engine.property.Property property = propertyService.getPropertyFromJson("myProperty");7org.cerberus.engine.gwt.impl.PropertyService propertyService = new org.cerberus.engine.gwt.impl.PropertyService();8org.cerberus.engine.property.Property property = propertyService.getPropertyFromJson("myProperty");9org.cerberus.engine.gwt.impl.PropertyService propertyService = new org.cerberus.engine.gwt.impl.PropertyService();10org.cerberus.engine.property.Property property = propertyService.getPropertyFromJson("myProperty");11org.cerberus.engine.gwt.impl.PropertyService propertyService = new org.cerberus.engine.gwt.impl.PropertyService();12org.cerberus.engine.property.Property property = propertyService.getPropertyFromJson("myProperty");13org.cerberus.engine.gwt.impl.PropertyService propertyService = new org.cerberus.engine.gwt.impl.PropertyService();14org.cerberus.engine.property.Property property = propertyService.getPropertyFromJson("myProperty");15org.cerberus.engine.gwt.impl.PropertyService propertyService = new org.cerberus.engine.gwt.impl.PropertyService();
property_getFromJson
Using AI Code Generation
1var propValue = property_getFromJson("propName","file.json","default value");2var propValue = property_getFromJson("propName","file.json");3var propValue = property_getFromJson("propName","file.json","");4var propValue = property_getFromJson("propName","file.json","");5var propValue = property_getFromJson("propName","file.json","");6var propValue = property_getFromJson("propName","file.json","");7var propValue = property_getFromJson("propName","file.json","");8var propValue = property_getFromJson("propName","file.json","");9var propValue = property_getFromJson("propName","file.json","");
property_getFromJson
Using AI Code Generation
1 ${defaultTimeout}= Property.Get From Json cerberus.engine.default.timeout2 Log ${defaultTimeout}3 Should Be Equal As Integers ${defaultTimeout} 100004 ${defaultTimeout}= Property.Get From Json cerberus.engine.default.timeout5 Log ${defaultTimeout}6 Should Be Equal As Integers ${defaultTimeout} 100007 ${defaultTimeout}= Property.Get From Json cerberus.engine.default.timeout8 Log ${defaultTimeout}9 Should Be Equal As Integers ${defaultTimeout} 1000010 ${defaultTimeoutAsString}= Convert To String ${defaultTimeout}11 Log ${defaultTimeoutAsString}
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!!