Contributions
How to trim white space after XMLParser
Hello! I have an xml.file and I need to generate random UUID and Date for every request. So I decided to write a groovy script: TimeZone.setDefault(TimeZone.getTimeZone("Europe/Moscow")); def now = new Date((System.currentTimeMillis() - 3600000L)) String s = now.format("yyyy-MM-dd'T'HH:mm:ss.SSS")+"+03:00" log.info(s) context.testCase.setPropertyValue('currentDateForXml', s) stringXML = '''<SmsSubscriptionsTarifficationNotifies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="***.xsd"> <TarifficationNotify> <TransactionId>971f513e-ff56-4b9b-9910-cd1acec12fab</TransactionId> <SubscriptionId>f6b3f278-d6fd-48a7-b8c4-5e5570a2b0a0</SubscriptionId> <ContentId>de1b0145-f4ae-48b4-a216-f5d8e302760</ContentId> <MSISDN>79855575412</MSISDN> <AttemptDate>2017-06-16T00:10:13.9+03:00</AttemptDate> <Result>false</Result> <FaultCode>102</FaultCode> </TarifficationNotify> <TarifficationNotify> .... the same story </TarifficationNotify> </SmsSubscriptionsTarifficationNotifies>''' def parsedXml = new XmlParser().parseText(stringXML) log.info(parsedXml ) def dt = parsedXml.'**'.TransactionId log.info(dt) dt.each{it.value = randomUUID() as String} def dd = parsedXml.'**'.AttemptDate log.info(dd) dd.each{it.value = s} def sw = new StringWriter() new XmlNodePrinter(new PrintWriter(sw)).print(parsedXml) def newXml = sw.toString() context.testCase.setPropertyValue('newXml', newXml) and i need to set new xml in property to use it for SOAP request But added to the properties xml looks like: <SmsSubscriptionsTarifficationNotifies xmlns="https://moipodpiski.ssl.mts.ru/xsd/SmsSubscriptionsTarifficationNotifies.xsd"> <TarifficationNotify> <TransactionId> d897fad0-3cd4-4c2a-a317-f69c976906ae </TransactionId> <SubscriptionId> 75cc04d4-b84a-4dbf-a881-d6fe39552083 </SubscriptionId> <ContentId> d2e1edd5-4e3c-4a80-a189-0f52e1b756ec </ContentId> <MSISDN> 79855575412 </MSISDN> <AttemptDate> 2017-06-16T00:10:13.9+03:00 </AttemptDate> <Result> false </Result> <FaultCode> 102 </FaultCode> </TarifficationNotify> </SmsSubscriptionsTarifficationNotifies> a lot of white spaces and as a result Ihave an invalid request Could you help me please How to remove spaces inside tags?Solved4.8KViews0likes4CommentsGroovy loop for parsing - XML Content is not allowed in prolog
Hello! Could you help me please. I have a JDBC Request and response looks like: <Results> <ResultSet fetchSize="0"> <Row rowNumber="1"> <PS_CONTENT_ONDEMAND.EXTERNAL_CODE>f538de04</PS_CONTENT_ONDEMAND.EXTERNAL_CODE> <PS_CONTENT_ONDEMAND.SUBSCRIBE_PARAMS_ID>8765</PS_CONTENT_ONDEMAND.SUBSCRIBE_PARAMS_ID> <PS_CONTENT_ONDEMAND.DATE>2017-03-15 00:00:00.705</PS_CONTENT_ONDEMAND.DATE> <PS_SUBSCRIBE_PARAMS.URL>http://stk.o4evidec.ru/?alias=mtsby_dance</PS_SUBSCRIBE_PARAMS.URL> <PS_SUBSCRIBE_PARAMS.ID>8765</PS_SUBSCRIBE_PARAMS.ID> </Row> <Row rowNumber="2"> <PS_CONTENT_ONDEMAND.EXTERNAL_CODE>2273851</PS_CONTENT_ONDEMAND.EXTERNAL_CODE> <PS_CONTENT_ONDEMAND.SUBSCRIBE_PARAMS_ID>8766</PS_CONTENT_ONDEMAND.SUBSCRIBE_PARAMS_ID> <PS_CONTENT_ONDEMAND.DATE>2017-03-15 06:00:00.944</PS_CONTENT_ONDEMAND.DATE> <PS_SUBSCRIBE_PARAMS.URL>http://intra.mobile-content.a1s/alias/tele2_dema</PS_SUBSCRIBE_PARAMS.URL> <PS_SUBSCRIBE_PARAMS.ID>8766</PS_SUBSCRIBE_PARAMS.ID> </Row> I need to create a loop to set each node : PS_CONTENT_ONDEMAND.EXTERNAL_CODE as property in that testCase At first, I decided to create a script assertion with a simple loop to check how it works : def parsedXml = new XmlSlurper().parseText("context.ResponseasXML") parsedXml.Row.each { Row -> println "Row index: ${Row.@rowNumber}" Row.children().each{ tag -> println " ${tag.name()}: ${tag.text()}" } } But I have an error : Content is not allowed in prolog What should i do?Solved8 years agoPlace ReadyAPI QuestionsReadyAPI Questions3.2KViews0likes2CommentsRe: JDBC request with date from another JDBC response and stored procedure
Thank you, very much! I did it! assert context.ResponseasXML def parsedXml = new XmlSlurper().parseText(context.ResponseasXML) def dt = parsedXml.'**'.find { it.name() == 'PS_SUBSCRIBE_DATA_290.CHANGED_DATE'} as String def dd = dt.substring(0, dt.lastIndexOf(".")) log.info( dd ) context.testCase.setPropertyValue('CHANGED_DATE', dd)2.5KViews1like0CommentsRe: JDBC request with date from another JDBC response and stored procedure
Hello! I triedthis code assert context.Response def parsedXml = new XmlSlurper().parseText(context.response) def dt = parsedXml.'**'.find { it.name() == 'PS_SUBSCRIBE_DATA_290.CHANGED_DATE'} as String log.info( parsedXml ) context.TestCase.setPropertyValue('CHANGED_DATE', dt.substring(0, dt.lastIndexOf("."))) and this message appears in logs: Wed Mar 01 11:55:52 MSK 2017:INFO:subscribed but it is not a response of JDBS request, It is a response of the first Test step in this Test case ((( And as a result i have an error: "Cannot invoke method lastIndexOf() on null object" Then I decided to make some changes: assert context.ResponseasXML def parsedXml = new XmlSlurper().parseText(context.ResponseasXML) def dt = parsedXml.'**'.find { it.name() == 'PS_SUBSCRIBE_DATA_290.CHANGED_DATE'} as String log.info( dt ) context.TestCase.setPropertyValue('CHANGED_DATE', dt.substring(0, dt.lastIndexOf("."))) and next message appears in logs: Wed Mar 01 12:52:48 MSK 2017:INFO:2017-03-01 11:22:47.036 And this is what I need But i have an error: "Cannot invoke method setPropertyValue() on null object" Could you help me, please? What should I change?3KViews0likes2CommentsJDBC request with date from another JDBC response and stored procedure
I have a JDBC response: <Results> <ResultSet fetchSize="0"> <Row rowNumber="1"> <PS_SUBSCRIBE_DATA_290.CHANGED_DATE>2017-02-01 12:13:51.378</PS_SUBSCRIBE_DATA_290.CHANGED_DATE> </Row> </ResultSet> </Results> I need to use this date in another JDBC request But also ineed to use stored procedure because of the name of the table. I have a SQL query for DBeaver client and it works: select * from get_partition_name('ps_subscribe_history','2017-02-01 12:13:51'::timestamp without time zone) But when i want to do the same sql query in JDBC request: select * from get_partition_name('ps_subscribe_history', '${JDBC Request#ResponseAsXml#PS_SUBSCRIBE_DATA_290.CHANGED_DATE}') This produces an error : 2017-02-01 18:46:34 - Error getting response; org.postgresql.util.PSQLException: ERROR: invalid input syntax for type timestamp: ""Position: 58 Could you help me to resolve this problem? Maybe thiserror is caused by an incorrect date format ? 2017-02-01 12:13:51.378Solved3.4KViews0likes11CommentsRe: Groovy script for JDBS request assertion. Unexpected element: CDATA
Thank you very much, guys! Your advice washelpful! I renamed the test step and it was a mistake. and i had to edit this line =>( "JDBC Request#ResponseAsXml" )8 years agoPlace ReadyAPI QuestionsReadyAPI Questions2.5KViews0likes0CommentsRe: Groovy script for JDBS request assertion. Unexpected element: CDATA
<Results> <ResultSet fetchSize="0"> <Row rowNumber="1"> <PS_SUBSCRIBE_DATA_290.CREATED_DATE>2016-11-14 16:35:27</PS_SUBSCRIBE_DATA_290.CREATED_DATE> <PS_SUBSCRIBE_DATA_290.CHANGED_DATE>2017-01-27 13:40:33.911</PS_SUBSCRIBE_DATA_290.CHANGED_DATE> </Row> </ResultSet> </Results> This is my response for jdbc request8 years agoPlace ReadyAPI QuestionsReadyAPI Questions2.6KViews0likes1Comment