# Data driven testing per request without using data file

**URL:** <https://community.postman.com/t/data-driven-testing-per-request-without-using-data-file/21563>\
**Category:** Help Hub\
**Created:** [March 18, 2021, 10:41pm UTC](https://community.postman.com/t/data-driven-testing-per-request-without-using-data-file/21563 "2021-03-18T22:41:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [March 18, 2021, 10:41pm UTC](https://community.postman.com/t/data-driven-testing-per-request-without-using-data-file/21563/1 "2021-03-18T22:41:23Z")

</div>

**Adding another answer on how to run data driven from same request:**

Create a environment variable called “csv” and copy the below content and paste it as value:

```
username,password,error_message,error_code
username1,password1,errormessage1,errorcode1
username1,password1,errormessage1,errorcode1

```

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/2/9292d00e5857827af5026f21d4b8a25942fcc086.png)

Now in pre-request add :

```
if (!pm.variables.get("index")) {

    const parse = require('csv-parse/lib/sync')
    //Environmental variable where we copy-pasted the csv content
    const input = pm.environment.get("csv");
    const records = parse(input, {
        columns: true,
        skip_empty_lines: true
    })

    pm.variables.set("index", 0)
    pm.variables.set("records", records)
}

records = pm.variables.get("records")
index = pm.variables.get("index")
if (index !== records.length) {
    for (let i of Object.entries(records[index])) {
        pm.variables.set(i[0], i[1])
    }
    pm.variables.set("index", ++index)
    postman.setNextRequest(pm.info.requestName)
}

```

Now you can run data driven for that one particular request:

Eg collection:

[https://www.getpostman.com/collections/eb144d613b7becb22482](https://www.getpostman.com/collections/eb144d613b7becb22482)

use the same data as environment variable content , now run the collection using collection runner or newman

**Output:**

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/5/2/5264483589648a0034f1e76a180583f2d2f7def0.png)

---

<div class="post-metadata">

**Author:** ![pranavdavar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pranavdavar/32/9152_2.png) [@pranavdavar](https://community.postman.com/u/pranavdavar)\
**Post date:** [March 19, 2021, 4:49am UTC](https://community.postman.com/t/data-driven-testing-per-request-without-using-data-file/21563/2 "2021-03-19T04:49:51Z")

</div>

Hi @praveendvd ,

This looks interesting, will try this for sure. Thank you for sharing 😌

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [March 19, 2021, 6:26am UTC](https://community.postman.com/t/data-driven-testing-per-request-without-using-data-file/21563/3 "2021-03-19T06:26:17Z")

</div>

Thank you 😊 let me know your thoughts

---

<div class="post-metadata">

**Author:** ![sutichaiu](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@sutichaiu](https://community.postman.com/u/sutichaiu)\
**Post date:** [April 5, 2022, 7:28am UTC](https://community.postman.com/t/data-driven-testing-per-request-without-using-data-file/21563/4 "2022-04-05T07:28:09Z")

</div>

Please complete by added this line in body  
 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/5/51d6a39bbc1f185886e4a53c5b1cefc083dfc7b8.png)

---

<div class="post-metadata">

**Author:** ![sutichaiu24](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@sutichaiu24](https://community.postman.com/u/sutichaiu24)\
**Post date:** [April 7, 2022, 10:18am UTC](https://community.postman.com/t/data-driven-testing-per-request-without-using-data-file/21563/5 "2022-04-07T10:18:22Z")

</div>

you have add this line of code other wise it will duplicate in the end

![image](https://us1.discourse-cdn.com/getpostman/original/2X/5/5f18d11c31bdbb2038358a9fffe7621fbdf45455.png)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [December 12, 2024, 2:47pm UTC](https://community.postman.com/t/data-driven-testing-per-request-without-using-data-file/21563/6 "2024-12-12T14:47:56Z")

</div>

Closed on December 12, 2024, 2:47pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
