Contributions
Re: wildcards in XPATH expressions?
It looks like it makes sense, just like post#2. But the problem is still the same: I cant (or dont know how to) apply it in this situation. Extended the code: import com.eviware.soapui.impl.wsdl.teststeps.* import com.eviware.soapui.support.XmlHolder def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def steps = testRunner.testCase.getTestStepsOfType( WsdlTestRequestStep.class ) def project = testRunner.testCase.testSuite.project for (step in steps) { log.info step.name// + step.getLabel() def holder1 = groovyUtils.getXmlHolder( step.testRequest.requestContent ) assert project.getPropertyValue("objectid") != null, "no objectid set" // holder1["//Les/ObjectID"]=project.getPropertyValue("objectid") // holder1["//LesCreate/ObjectID"]=project.getPropertyValue("objectid") // holder1["//LesDelete/ObjectID"]=project.getPropertyValue("objectid") def nodes = holder1.getDomNodes("//ObjectID/parent::*[contains(name(), \"Les\")]") log.info "new value "+project.getPropertyValue("objectid") for(int i = 0; i < nodes.length-1 ; i++) { def elems = nodes[i].getChildNodes(); for(int j = 0; j < elems.length-1 ; j++) { def child = elems.item(j); log.info "child $j "+ child if( child.getNodeName() == "ObjectID") { log.info "YES! we got one! Now the new value: " child.setNodeValue(project.getPropertyValue("objectid")) log.info child.getNodeValue() } } } holder1.updateProperty() step.testRequest.setRequestContent (holder1.getXml()); } Problems: 1) The last print log.info child.getNodeValue() does print null. And no, the project.getPropertyValue("objectid") does not return null. 2) the XML code of the test request has not changed. 3) The node "Les" does NOT match the Xpath expression 4) It is slightly better as parsing the whole document yourself but.... barely. It is a mess compared to a simple sed -e 's/Les(.*)\/ObjectID/.... . You get the meaning, in lots of languages this is a one statement string replace with a reg ex.10KViews0likes0CommentsRe: wildcards in XPATH expressions?
Consider the following XML <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:raad="http://raadpleegles.aanboddienst-01_00.davinci.ov.vlaanderen.be"> <soapenv:Header/> <soapenv:Body> <raad:RaadpleegLes> <LesCreate> <ObjectID>2d4e672c-8ebb-4a6d-9ee6-12eabf4b446a:14c47413430</ObjectID> <ConcurrencyToken>cdb93192-c8e9-4f85-9e52-54f2482b99c9:14c47413430</ConcurrencyToken> </LesCreate> <LesDelete> <ObjectID>5d4e672c-8ebb-4a6d-9ee6-12eabf4b446a:14c47413430</ObjectID> <ConcurrencyToken>cdb93192-c8e9-4f85-9e52-54f2482b99c9:14c47413430</ConcurrencyToken> </LesDelete> <Les> <ObjectID>hd4e672c-8ebb-4a6d-9ee6-12eabf4b446a:14c47413430</ObjectID> <ConcurrencyToken>cdb93192-c8e9-4f85-9e52-54f2482b99c9:14c47413430</ConcurrencyToken> </Les> <DONTCHANGE> <ObjectID>hd4e672c-8ebb-4a6d-9ee6-12eabf4b446a:14c47413430</ObjectID> <ConcurrencyToken>cdb93192-c8e9-4f85-9e52-54f2482b99c9:14c47413430</ConcurrencyToken> </DONTCHANGE> </raad:RaadpleegLes> </soapenv:Body> </soapenv:Envelope> Several nodes name name starting with the string "Les". In those nodes Id like to change the value of their child node named "ObjectID". I can not do that for everything else like "DONTTOUCH". To substitute this script will work fine import com.eviware.soapui.impl.wsdl.teststeps.* import com.eviware.soapui.support.XmlHolder def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def steps = testRunner.testCase.getTestStepsOfType( WsdlTestRequestStep.class ) def project = testRunner.testCase.testSuite.project for (step in steps) { log.info step.name// + step.getLabel() def holder1 = groovyUtils.getXmlHolder( step.testRequest.requestContent ) assert project.getPropertyValue("objectid") != null, "no objectid set" holder1["//Les/ObjectID"]=project.getPropertyValue("objectid") holder1["//LesCreate/ObjectID"]=project.getPropertyValue("objectid") holder1["//LesDelete/ObjectID"]=project.getPropertyValue("objectid") holder1.updateProperty() step.testRequest.setRequestContent (holder1.getXml()); } In the example I included only 3 different names for the nodes to replace (Les, LesCreate, LesDelete). Now imagine there are not 3 but hundreds of possibilities, then how should one go about this? Providing an expression the equivalent of //Les*/ObjectID would be my first attempt but I cant see how to include that in the supplied groovy script.10KViews0likes2CommentsRe: wildcards in XPATH expressions?
Thank you, I think it might be something just like that. Only I wouldnt know how to apply this to my situation. I also dont get what @id refers to. holder1["//*[starts-with(@id,'Plaatsing') and ends-with(@id,'DAVINCIObjectID')"] =project.getPropertyValue("Plaatsing_objectid") This grants me an error XPath syntax error at char 70 on line 2 in {...ds-with(@id,'DAVINCIObjectI...}: expected "]", found " " error at line: 1711KViews0likes4Commentswildcards in XPATH expressions?
Context: In a groovy script, a request is modified as in holder1["//NodeA/ObjectID"]=project.getPropertyValue("objectid") holder1["//NodeB/ObjectID"]=project.getPropertyValue("objectid") ... You can see the node always starts with Node ans is then followed optionally by some string. Question: Is it possible to make 1 XPATH expression taht matches all Node* named nodes? Is there a different way to achieve this in a different way? The reason a groovy script is used is because lots of requests have to be changed and regular property transfer doesnt allow that (I presume).11KViews0likes6CommentsRe: changing soap request xml tag
After changing the structure of the nodes, you have to notify the request to update itself with the changed XML content. Something along: myRequest.setRequestContent (holder.getXml()); OR myTestStep.setPropertyValue('Request', holder.getXml())1.2KViews0likes0CommentsAfter executing a systemcall , the waitFor() method hangs
This piece of groovy is used in an assertion on a teststep. It does make a systemcall to execute unzip. The cmd itself works fine. the call cmd.execute() works fine and the unzip command is properly executed by the OS. The problem is the next statement "results.waitFor()" because SoapUI hangs. It doesnt do anything but you cant click on anything except drag the window of the assertion code editor. The canvas however is not painted anymore, all buttons dont work and killing the process is the only way to get rid of it. Commenting out the waitFor line resolves the problem but then you cant test the result of the systemcall. def unzipPath = "C:\\zip\\unzip.exe" def cmd = "$unzipPath \"$zipFileName\" -d \"${groovyUtils.projectPath}\"" log.info "cmd=$cmd" def results = cmd.execute() results.waitFor() log.info "result is "+results.exitValue() //assert results.exitValue() == 0 //results.destroy() How can I test the exitValue?4.6KViews0likes5Comments[solved]Decoding an attachment of XOP (base64binary)
[edit] Ok, seems like someone sent a plain file along, not encoded at all. It was just a zip :S. The question is therefore not relevant anymore. ------------------------ The SOAP response I receive includes an attachment <xop:Include href="cid:3f38c9b5-83b1-49cb-ace3-4ed18eaff555%40null" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>. This attachment is in binary and I need to turn it into regular XML again. Disclaimer: I am a noob so i might leap to bizar conclusions and make assumptions that are wrong. Based on this single attachment in binary I decided this is a base64binary encoded file. Because I dont know any better I thought a SOAPUI assertion might check it and meanwhile decode it so I can actually understand it as a human. Below is the assertion but it turns out to be doing not so great. Using the simple "encodedString.decodeBase64()" wont work because it is not a string but binary data. assert messageExchange.responseAttachments.length == 1 def atta = messageExchange.getResponseAttachments()[0] log.info atta.getContentEncoding() assert atta.getSize() != 0 def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ); import org.apache.commons.codec.binary.Base64; Base64 decoder = new Base64(); def eIS = atta.getInputStream() def f = new File(groovyUtils.projectPath + "decoded"); f.delete(); def inp = new byte[1]; while (eIS.read(inp) != -1 ) { //EOF log.info "enc "+inp f << decoder.decode(inp) log.info "dec "+decoder.decode(inp) } log.info(groovyUtils.projectPath + "decoded"); The execution of this yiled me this log Tue Mar 17 22:40:30 CET 2015:INFO:binary Tue Mar 17 22:40:30 CET 2015:INFO:enc [80] Tue Mar 17 22:40:30 CET 2015:INFO:dec [0] Tue Mar 17 22:40:30 CET 2015:INFO:enc [75] Tue Mar 17 22:40:30 CET 2015:INFO:dec [0] Tue Mar 17 22:40:30 CET 2015:INFO:enc [3] Tue Mar 17 22:40:30 CET 2015:INFO:dec [] Tue Mar 17 22:40:30 CET 2015:INFO:enc [4] Tue Mar 17 22:40:30 CET 2015:INFO:dec [] Tue Mar 17 22:40:30 CET 2015:INFO:enc [20] Tue Mar 17 22:40:30 CET 2015:INFO:dec [] Tue Mar 17 22:40:30 CET 2015:INFO:enc [0] Tue Mar 17 22:40:30 CET 2015:INFO:dec [] Tue Mar 17 22:40:30 CET 2015:INFO:enc [8] Tue Mar 17 22:40:30 CET 2015:INFO:dec [] Tue Mar 17 22:40:30 CET 2015:INFO:enc [0] Tue Mar 17 22:40:30 CET 2015:INFO:dec [] Tue Mar 17 22:40:30 CET 2015:INFO:enc [8] Tue Mar 17 22:40:30 CET 2015:INFO:dec [] Tue Mar 17 22:40:30 CET 2015:INFO:enc [0] Tue Mar 17 22:40:30 CET 2015:INFO:dec [] Tue Mar 17 22:40:30 CET 2015:INFO:enc [68] Tue Mar 17 22:40:30 CET 2015:INFO:dec [0] Tue Mar 17 22:40:30 CET 2015:INFO:enc [-104] At this point there pops up a dialoguebox titled "Error" with the content "-104". I am clueless as to what is happening and what an proper decoding from an attachment would be like.1.1KViews0likes0Comments