# Tests script not running

**URL:** <https://community.postman.com/t/tests-script-not-running/50965>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [August 25, 2023, 10:19am UTC](https://community.postman.com/t/tests-script-not-running/50965 "2023-08-25T10:19:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![orbital-module-arch5](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@orbital-module-arch5](https://community.postman.com/u/orbital-module-arch5)\
**Post date:** [August 25, 2023, 10:19am UTC](https://community.postman.com/t/tests-script-not-running/50965/1 "2023-08-25T10:19:20Z")

</div>

I’m trying to simulate a server with webhook behavior. The idea is that we send a request to this server containing a “webhook\_url” in the request body. Then the server immediately responds with a random GUID “id” in the response body. After a short delay, it should _also_ send a POST request to the “webhook\_url” with a body containing the GUID.

The problem is, when I test it by clicking “Try” in the Postman UI, it works fine and the Test scripts are run. However when I actually test it externally (i.e. via my node app), the Tests do not appear to run at all. Am I doing something wrong? How can I debug this? TIA

Here’s my script:

```auto
let res = pm.response.json();
let transcriptId = res.id;

var webhookUrl = req.webhook_url;
// Simulate the async call to the extracted webhook_url after a delay
setTimeout(function() {
  var webhookRequest = {
    url: webhookUrl, // Use the extracted webhook_url
    method: "POST",
    header: {
      "Content-Type": "application/json"
    },
    body: {
      mode: "raw",
      raw: JSON.stringify({
        "transcript_id": transcriptId,
        "status": "completed"
      })
    }
  };
  
  pm.sendRequest(webhookRequest, function(response) {
    // Log or perform actions based on the webhook response
    console.log("done!");
  });
}, 5000); // Simulated delay of 2000 milliseconds (2 seconds)

```

 ![Screenshot 2023-08-25 at 3.13.44 AM](https://us1.discourse-cdn.com/getpostman/original/3X/4/1/4125f978886e63aae783bc680d6ff24f388f5309.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 25, 2023, 1:43pm UTC](https://community.postman.com/t/tests-script-not-running/50965/2 "2023-08-25T13:43:22Z")

</div>

Hey @orbital-module-arch5 👋

Would you be able to expand on this point more, please? An example of what this looks/behaves like would be helpful.

> [@orbital-module-arch5](#):
>
> However when I actually test it externally (i.e. via my node app), the Tests do not appear to run at all.

---

<div class="post-metadata">

**Author:** ![orbital-module-arch5](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@orbital-module-arch5](https://community.postman.com/u/orbital-module-arch5)\
**Post date:** [August 25, 2023, 3:19pm UTC](https://community.postman.com/t/tests-script-not-running/50965/3 "2023-08-25T15:19:54Z")

</div>

@ dannydainton I have a NextJS 13 app on Vercel, with some API routes. On Vercel preview branches, the app is configured to make a call to our mock Postman server with the request I described above. The `webhook_url` provided is: the current Vercel app deployment URL + `/api/v1/transcriptions`. This is an API route for our app which I can monitor requests to in Vercel logs.

In summary, the flow is:

1. NextJS app is triggered to make a request to `{{postmanUrl}}/v2/transcript`, with a body containing `webhook_url` pointing back at our app’s API route
2. The Postman endpoint should return a random guid in the reponse
3. After a delay, the Postman endpoint should send a POST to the `webhook_url` with a body containing the generated guid
4. We can view the logs to confirm whether our app’s API route was hit

When I manually hit “Try” in the Postman UI with the real value for `webhook_url` pointing to our app (i.e. faking step #1), then steps #2-4 occur successfully. However, when I trigger step #1 for real in our app, only #2 appears to occur. I am unable to confirm #4 in our logs.

---

<div class="post-metadata">

**Author:** ![orbital-module-arch5](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@orbital-module-arch5](https://community.postman.com/u/orbital-module-arch5)\
**Post date:** [August 25, 2023, 6:57pm UTC](https://community.postman.com/t/tests-script-not-running/50965/4 "2023-08-25T18:57:25Z")

</div>

Here’s a simpler test I did:

**[SUCCESS]** Clicking “Try” in the Postman UI gives me correct response with guid, I can see activity in the console window, and I can confirm via Vercel logs that it made an outbound request to the `webhook_url` endpoint from the Tests script.

**[FAIL]** For _the same postman example_, I open the code snippet view and copy the cURL command. I execute the command, do NOT see console activity, and do NOT see any outbound request to `webhook_url` as evidenced in our Vercel logs.

Maybe my understanding is wrong. Should the Tests script _always_ be run, or _only_ when trying example requests within the postman application?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 25, 2023, 8:36pm UTC](https://community.postman.com/t/tests-script-not-running/50965/5 "2023-08-25T20:36:27Z")

</div>

Have you tried creating an actual request, with all the same details, rather than doing that via an example?

There could be some slight differences in the way that those two different things work, when run programmatically.

---

<div class="post-metadata">

**Author:** ![orbital-module-arch5](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@orbital-module-arch5](https://community.postman.com/u/orbital-module-arch5)\
**Post date:** [August 25, 2023, 10:11pm UTC](https://community.postman.com/t/tests-script-not-running/50965/6 "2023-08-25T22:11:20Z")

</div>

Yes. My findings were that Test scripts are executed when running postman examples, but _not_ run when the incoming request is from an external source.

Is that not true?

---

<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:** [November 23, 2023, 10:11pm UTC](https://community.postman.com/t/tests-script-not-running/50965/7 "2023-11-23T22:11:23Z")

</div>

Closed on November 23, 2023, 10:11pm UTC

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