Skip to content

read local file in tests in postman #798

Closed
@hanyghazal

Description

@hanyghazal

I want to read a local file and parse it in tests in postman and I can't able to do this

Activity

abhijitkane

abhijitkane commented on Nov 11, 2014

@abhijitkane
Member

You can use the collection runner to load data files into Postman.
Check https://www.getpostman.com/docs/jetpacks_examples for examples. JSON and CSV are supported.

hanyghazal

hanyghazal commented on Nov 11, 2014

@hanyghazal
Author

Thank for your reply. But I know that. I mean I want to read file (excel, text and so on) in tests during writing my code in java script in postman. Do you know how?

abhijitkane

abhijitkane commented on Nov 11, 2014

@abhijitkane
Member

That's currently not supported - we're working on a way to include custom files in the Pre-request scripting / testing sandbox.

xiaobeiying

xiaobeiying commented on Nov 28, 2016

@xiaobeiying

@abhijitkane Looking forward to the NEW version.

garunski

garunski commented on Jan 10, 2017

@garunski

+1

bennetone

bennetone commented on Feb 22, 2017

@bennetone

+1

barnesm999

barnesm999 commented on Apr 12, 2017

@barnesm999

Any progress on this? Would really like the ability to load some complex data from files during Pre/Test Script. For example, I would like to load a JSON file which contains the expected response JSON schema. This would allow me to externalize the schema from the script and re-use it across multiple collections while only maintaining a single copy.

Currently I am stuck duplicating these schema definitions across many collections (or I need to set a global variable before running which is not desired). If the schema changes I will have to update dozens of collections that use it.

ji50180

ji50180 commented on May 10, 2017

@ji50180

Would be very interested in using that in our postman-sheme, too.
Our API calls are expensive, and we would have several dozen tests per call, which we now have to fill in per hand. One Test per call would take hours in our system.

Using a csv for that would be so much more effective.

saschawiener

saschawiener commented on Jun 14, 2017

@saschawiener

Would be cool to have somthing like this! We're doing JSON validation via tv4 in Jenkins/newman. The json-schema gets generated dynamically by a pre-executed server script. Loading this file would be much easier than deploying it somewhere and calling it via HTTP.

leonelgalan

leonelgalan commented on Jul 7, 2017

@leonelgalan

I'm interested in this feature too. I want to reuse JSON schema files I have, in both, RSpec and Postman/newman, the current solution is to write the schema into every Postman test.

Rachit1980

Rachit1980 commented on Aug 14, 2017

@Rachit1980

Need a way to read a txt/CSV file in tests and compare values to JSON element values

abhijitkane

abhijitkane commented on Sep 11, 2017

@abhijitkane
Member

A workaround for now is to start a local server (https://www.npmjs.com/package/simplehttpserver), and use a Postman request and test script to load the response into an environment variable.

Since we need to support collections in the cloud as well, this isn't on the immediate roadmap.

prashant7090

prashant7090 commented on Nov 30, 2017

@prashant7090

@barnesm999 Hey did you get any solution to externalize the JSON response schema files?

Kal6

Kal6 commented on May 2, 2018

@Kal6

Is there any new developments on this feature? It would be nice if we have it to handle the data from outside of the scripts.

Thank you!

christianbaumann

christianbaumann commented on May 28, 2018

@christianbaumann

+1

RickHough

RickHough commented on Jun 28, 2018

@RickHough

One solution might be to have your developers load the data to the application under test from csv, then expose that data via an end point. You can then load that as Global Variables using an initialisation script. Not pretty of course but it works.

nileshy112

nileshy112 commented on Jul 16, 2018

@nileshy112

Instead of copy and paste the JSON in body of the request, I would like to read it from JSON file (external source) and then replace all dynamic variables from JSON file.
e.g. Below is my JSON file which I want to read it from my hard disk and replace all variables with valid values before sending it.
{
"firstName": "{{firstName}}",
"lastName": "{{lastName}}",
"age": {{age}},
"correlationIds": [
{
"id": "{{id}}",
"source": "{{source}}"
},
{
"id": "{{id2}}",
"source": "{{source2}}"
}
]
}

trastle

trastle commented on Oct 11, 2018

@trastle

This is sorely needed for short lived tokens etc.
Manually copy pasting a token into postman every time my tokens expire is nuts.

Even something simple like use a JSON file for the environment of a folder would be a huge improvement.

ADaniel-dev

ADaniel-dev commented on Oct 25, 2018

@ADaniel-dev

i need postman read my large of test cases from csv, the csv filles contains URL, header, body and expeccted responses to assertion. i hope pm can make it.

junaidq57

junaidq57 commented on Jan 30, 2019

@junaidq57

I want to read a local file and parse it in tests in postman and I can't able to do this

check this out
The pre-request and test script sections of the Postman app rely on JavaScript (not text). Therefore, you can use Postman’s pm.* API, like the pm.iterationData.get(“variable-name”) method, to access the values loaded from the data file.

https://blog.getpostman.com/2018/04/11/looping-through-a-data-file-in-the-postman-collection-runner/

AshirwadVyawahare

AshirwadVyawahare commented on Feb 16, 2019

@AshirwadVyawahare

I'm unable to read the values in pre-requisite scripts when I read the data file from server in the pre-requisite script. Is this feature not available in Postman?

SHI-ZP

SHI-ZP commented on Feb 18, 2020

@SHI-ZP

Well, I suppose RickHough's solution would be the only approach.

rcmonitor

rcmonitor commented on May 24, 2020

@rcmonitor

Still looking for ability to load local file into string variable in pre-request script

VigneshOK10

VigneshOK10 commented on Jun 29, 2020

@VigneshOK10

any updates on provision for getting local files in tests?

arlemi

arlemi commented on Jun 30, 2020

@arlemi
Collaborator

This is not something we're working on at the moment, for any updates regarding this please follow #7210.

(closing to avoid more unwanted notifications from participants in this thread. 🙂)

locked and limited conversation to collaborators on Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @a85@abhijitkane@leonelgalan@garunski@christianbaumann

        Issue actions

          read local file in tests in postman · Issue #798 · postmanlabs/postman-app-support