3

I have a question about how best to chain requests to test multiple workflows in postman. I want to test the following two flows. Each of the boxes is a request set up in postman, but there are requests that are common to both workflows. How do I use the folder structure, collection runner and setNextRequest to enable this or should I just be duplicating the requests?

Any help would be much appreciated!

The workflow splits after create token. I have it set up as follows at the moment:

Api Name Folder

    1 Register Device (contains activate, create token and register device requests)
    2 Deregister a Device (contains activate, create token, list all devices and deregister a device requests
   request)

The problem with this is that the activate and create token requests are duplicated. I want to design a workflow that allows me to reuse them across workflows rather than duplicate them.

enter image description here

user3603308
  • 355
  • 4
  • 17
  • Does it always split off at the create Token part? What structure do you have at the moment? Could you use the collection or sub folder level elements to place some of the workflow logic in there - http://blog.getpostman.com/2017/12/13/keep-it-dry-with-collection-and-folder-elements/ – Danny Dainton Feb 11 '18 at 14:00
  • Hi, I've added in some extra detail above. In short, yes it always splits after create token. – user3603308 Feb 11 '18 at 19:58

2 Answers2

1

You could have the main root Collection contain the 3 requests that are the same in both journeys, capture the response data you require from these in a set of environment variables.

Once stored, these can then be used in the next set of requests, that could be structured in 2 separate folders - one for register and one for the deregister tasks.

I’m guessing that you would need to register something before you can deregister it so there is a natural order there.

The setNextRequest() function could work well here but i’m Not sure that you can reference the next request to be one in a different folder.

Can the request that gets the list of devices not be it’s own separate request. Using the same method of getting the response data and saving this as a variable, this data can be used to drive the deregister request.

Danny Dainton
  • 23,069
  • 6
  • 67
  • 80
  • Hi, Thanks for that. I'm not sure how this works in collection runner though. I understand that I can run the 3 requests and save the result to an environment variable, but to complete the first run I want to just run register a terminal. For the second run I want to run register a terminal > get the list of registered devices > deregister the device. Basically I want to run either the first workflow for the registering or I want to run the second workflow for deregistering. How do I run either or? Can I use a datafile to specify the ordering? – user3603308 Feb 12 '18 at 02:41
1

You can write logic accordingly inside the code. For example I used a Switch statement to handle this:

switch(pm.environment.get("PROFILE_set1")) {
    case 1:
        postman.setNextRequest("PROF_02 - Verify  the profile details");
        break;
    case 2:
        postman.setNextRequest("PROF_04 - Verify  update profile without firstname");
        break;
    case 3:
        postman.setNextRequest("PROF_05 - Verify update profile only with firstname");
        break;
    case 4:
        postman.setNextRequest("PROF_06 - Verify update profile only with phone");
        break;
    case 5:
        postman.setNextRequest("PROF_07 - Verify update profile only with last name");
        break;
    case 6:
        postman.setNextRequest("[Pre-condition] Logout - Profile");
        break;
}
anothernode
  • 5,100
  • 13
  • 43
  • 62
Ted87
  • 81
  • 8