postmanpostman-collection-runnerpostman-testcase

Postman CLI doesn't pre-process certain variables?


I have a Postman request which performs a Login. The request depends on two environment variables, as shown in the screen-shot:

enter image description here

As you can see, this request succeeds when run from within the Postman client. However, this fails when run from the CLI:

CLI Failure

The 400 indicates a bad login. For debugging purposes, I changed the variable substitution to the hardcoded password. I've left the variable reference to the base URL in place.

enter image description here

This works in the Postman client and now this also works when invoked by the CLI:

enter image description here

But this is not my preferred approach. For a variety of reasons, I prefer to have the password contents of this payload parameterized, rather than hardcoded. We see that variables are supported by the CLI because the base URL to the endpoint is expressed as a variable reference. So how come the variable reference within the payload of the request is not processed properly? Is there any way to get this to work? Thanks for your advice!


Solution

  • In a nutshell, the CLI command must specify the Environment being used, as well as the path to the Global environment variables. It's a mistake to assume (as I was) that access to the Global environment variables is to be taken for granted. Perhaps it's counterintuitive, after all "global" is assumed to be global! But that's not the case.

    The command I was originally using specifies the collection, the environment (-e) and I'm not sure what the -i represents. But it does not specify access to the global variables.

    postman collection run 38820000-00000000-0000-0000-0000-000000012fcd 
       -e 38820000-00000000-0000-0000-0000-0000000904b3 
       -i 38820000-00000000-0000-0000-0000-0000000fe416 
    

    Here's the modified command which specifies access to the global variables (-g):

    postman collection run 38820000-00000000-0000-0000-0000-000000012fcd 
       -e 38820000-00000000-0000-0000-0000-0000000904b3 
       -i 38820000-00000000-0000-0000-0000-0000000fe416 
       -g "https://api.getpostman.com/workspaces/
               ed830000-00000000-0000-0000-0000-00000006d5d2/global-variables?
               apikey=PMAK-67050000000000000000000000000000000454ff"
    

    (Linebreaks inserted for clarity.)

    With the additional specification of the -g parameter -, the path to the global variables, my requests run within the CLI exactly as they run within the Postman client, with access to all Environment and Global variables and the value substitution of those variables works as expected.