I am trying to test a range of different instances with a SOAP query that is for the most identical across instances but also has a part of the request body that is unique from one instance to another. So far I have managed to create global variables for URL etc. without any problems.
But what I need now is to capture a big piece of xml; tags, attribute and content all in one go into one parameter. I am thinking I could maybe use a data file and store the variable there and then insert it into the whole XML request. I guess a great deal of paring and escaping characters is needed if this is at all possible.
I look forward to hear your ideas!
EDIT: Please excuse me for bumping my own post just this once. For clarity, I am looking for a solution similar to the one demonstrated by @vdespa below, but for a SOAP request and an XML file.
While I am not exactly sure how you would like to accomplish your goal, Iโd like to refer you to a video I made regarding using XML with Postman Tests and Pre-Request Script sections, using cheerio.js, as this might help.
To better assist though, can you provide an example chunk of XML youโd like to parameterize? Ideally, this should work the same way as in @vdespa video, then in your request body, you write out the raw XML and insert the XML variables in your raw xml, like so
Thank you both for your responses, I have watched each of your videos and parts of the answer I am looking for is probably in both of them.
I realize โchunkโ is not a very exact term. Payload is a better term and in my case a payload is a document with several lines of unique xml. A simplified anonymized example below. The point is that the payloads differ wildly, some may have some 30 unique tags.
I am aware that I can use iteration data to point to an external file, and I have used cheerio for testing xml responses, but I need to combine different approaches in this scenario. I hope my question is clearer now.
Thanks for clarifying, I think I understand better, but let me know if my understanding is correct based on my response below.
What you can do is save the XML payloads as environment variables. Then when you need to use the payload in your script, you can pull them out from the environment. Lastly, if you need change anything about the XML payload before inserting it into your wrapper XML, you can initialize the XML as a cheerio object, manipulate the values, then deserialize the cheerio object back to XML and use it in your payload.
Let me this sound like what youโre looking for, and if so, let me know code examples / scenarios youโre looking for.
Hi @odanylewycz , what you describe is a first step to to what I am looking for indeed, and I have now managed to put in place what you describe. Instead of environment variables I use global variables, but otherwise the same idea.
Right now I have a hardcode global payload variable defined for the xml . Since ultimately I will use Newman in the solution I use that as an example here.
But the catch is, I already have a repo with xml payload documents (Earlier we used Fitnesse framework at my company and we have a repo of existing xml payloads that I would like to reuse in Postman) I would also like to have the newman commands shorter.
What I would like to have in the end would look have a path to the doc - something short and sweet like this:
" --global-var "payload= folder/payloadOne.xml"
That is what I mean by parameterize a chunk of xml.
All the examples I see for Postman indicate I can use either json, and csv files to set key value pairs for iterationdata. I will probably have to create a json document where I create a payload key and set the value to the xml (I just experimented with this and I get unexpected end of string line errors unless I remove all line breaks).
Interesting use case. I have not had much experience with this, but I certainly see what you are trying to do.
Given that you want to use newman at the end of it, what may work is using the file system module, and read the xml file from there, which makes is a native nodejs file. From there, you can define a string output of the file to another variable, say a payload variable, and then use that as your payload for your request.
const fs = require('fs');
fs.readFile('/folder/payloadOne.xml', 'utf8' , (err, data) => {
if (err) {
console.error(err)
return
}
var payload = data
})
I am not sure how well this would work, but it should in theory. While its not the elegant solution you were looking for, it should help and ideally make your newman command shorter as this code would be in a node.js script.
Apologies for having left this thread hanging. I am reading the question I posted a while ago and and I think there are many valuable answers. I hope it is not bad etiquette if I leave this thread without a marked solution. I may have moved goalposts as I considered all kinds of data file formats and approaches, and ended up going with something hacky. What we decided in my organization is to us jason files and strings of xml. It is not pretty but it works for our SOAP requests. Now I am tasked with the opposite problem which is building a REST collection which has its own conversion issue. But that is maybe for another thread
No worries, glad to help in any way possible, and looks like a combination of solutions helped resolve your issue, albeit hacky.
If youโre having issues doing a conversion to another service (for your REST collection), certainly feel free to open another thread, and weโll work on it there.