I want to read lines from my local xml/json file in Pre-request script to add its value for my variables.
I have a file called OPC.xml, wanna attribute this file to a variable and find lines which have “name” in itself. E.g: “<Name)Qwerty (/Name>” I used ) because right formula makes it
invisible. Qwerty and other variables should be stored in one array.
How can I do this?
Thanks for any help.
I’m afraid Postman can’t easily access local files directly because it runs in a sandbox . However, there are a few workarounds as follows
- Postman can access data through API’s, so if you have the skills to create a local API (eg using Node.js & Express) then you can simply fetch the file using a request, store the data in a global, and use it in subsequent requests. (This isn’t as hard as you might think, I ran a workshop with complete novices to create a simple API - see slides 7-14)
- You can create a tool that formats your data into a csv or json file suitable to use with the collection runner, or Newman.
- You could write some code to inject your data into an environment or globals file prior to running it with Newman.
You’re probably going to have to write some code to get the data from your file into something that Postman can access, but that said, I’ve had to do this in the past and found it easier than I thought it might be (and I am not a dev by any estimation )
Let us know which one you think might suit you best, and if you get stuck we can help you.
Hello, I am very grateful for your complex response. But I already have dealt with it in other way.
Although parasing local files will be very useful. I am looking forward to have this option in Postman Have a nice day!