How to run test scripts respectively?

Is there any method able to run the below test scripts respectively?

4 Likes

Do you mean in order 1-6?

The tests should show in the order you have them in your code unless you have them at the collection or folder level.

The execution order for each request will be collection tests, folder tests and then request tests.

Just out of curiosity. Why do you have a sendRequest in what appears to you your test tab? Aren’t these generally for the pre-request scripts?

Wouldn’t you usually setup a GET request as the next request in your collection\folder and pass the uuid as a collection variable? I’ve seen a few screenshots using sendRequest and in most cases I can’t understand why they aren’t standalone requests within the collection. (So just trying to understand the scenario and when to use them).

Hi @mdjones ,

Yes, in order 1-6.

I know that the scripts are always running according to the following hierarchy: collection-level pre-request script (if any), — folder-level pre-request script (if any) —, pre-request request-level script (if any), — request — response — collection-level script (if any), folder-level script (if any), request-level script (if any).

All of my scenario is in the designated request. Excluding “the failed response”.

My main aim is to test the typed scenarios in a request and these scenarios should be in order. Why in order? Let me explain it in detail.

For instance,

Scenario Number 1: I sent a POST Request, and this request turns an “ID”. According to this ID, I use the below methods as the end of endpoints’.

Scenario Number 2: I sent a GET Request

Scenario Number 3: I sent a PUT Request

Scenario Number 4: I sent a DELETE Request

If the sent request is worked as random(Assuming that “number 4” first), I can not delete anything without creating an ID. Due to that, I need to type in order my test scenarios in order.

@acihad

As far as I know, they should run in order as they show in your Tests tab, although clearly from your screenshot they don’t appear to be doing this. I noticed you have an if statement, so I’m wondering if that has any effect. Usually the Tests tab is used to parse data in the response and then assert on that data. They are quick as you are just working with the response data. If you are using sendRequest to make further requests that you are no longer working with just that response which sounds a bit messy to me and could possible have a performance impact, plus potentially make it harder to troubleshoot failing tests.

I’m still not quite understanding why you don’t just have a folder (or collection) with four separate requests in the appropriate order.

You store the ID in the initial post request in a variable using the Tests tab for that request, which can be used in any subsequent request using curly brackets, for example {{id}}

Your using sendRequest to chain the requests together in the Tests tab, which although it works, I don’t think was the intention for this function. I got the impression that the main use case was for pre-test scripts.

My advice is to create the POST, GET, PUT and DELETE request as four separate requests, and pass any required fields using variables between the requests.

This also means that you can write tests specifically for the POST, GET, PUT, and DELETE requests which may get messy if you have them all in one Test tab.

This is how the Postman Training in the Learning Centre teaches you how to pass data between requests.

For more info on variables.

Hi @acihad !

I’d love to help out but I will need a bit more context on your actual test script.

One thing that stands out to me is that #6 is running inside of a sendRequest function. This is asynchronous so it is not always guaranteed to run exactly in order. If your other tests are in a similar situation, this may be why things are appearing to be random :slight_smile:

Hi @kevin-postman and @mdjones ,

First of all, thank you for answering my question.

I have just uploaded a screenshot regarding this issue. There are two test scenarios that you see.

First Test: I have to send a “post request” to control mandatory fields, and due to that, I call the post request again.
Second Test: Control of the send request body and the response body is equal or not.(response body changes as dynamic.)

My main aim is to test the typed scenarios in a request and these scenarios should be in order. I just want to use the “POST-GET-PUT-DELETE” methods inside one request. Therefore, I need to run them in order. :slight_smile:

2 Likes