How to pass argument or value while running collection from newman ?
newman run mycollection.json -e envfile.json/csv is not working
Scenario
I have a collection which can run on multiple environments seamlessly but i need to pass one argument/value in first API request body which while drive to run on multiple environment
Steps to reproduce the behavior:
Go to newman
Run collection
I need to know how can i run collection by passing one value in command line
In above collection i need to pass organization id in first API
API name getDomain API
Request body
{âorgidâ: âgive_org_id_hereâ}
Could you please let me know the solution for this ?
I tried many things like passing environment json/csv file but nothing worked because environment json/csv files have only variable key doesnât have variable value
In my collection , i need to pass value for the first API
Below is the Request body of first API to which i need to send value form CLI
{
âorgidâ: â{{domain}}â
}
In above request body {{domain}} is the user defined variable name to which i need to send value from CLI
below command i am using as per your suggestion
newman run mycollection.json -global-var âdomain=valueâ , its giving me below
error: unknown option -o
newman run mycollection.json -g âdomain=valueâ , its giving me below
error: ENOENT: no such file or directory, open âC:\Users****\Desktop\27082019\domain=00D1U000000GqnbUACâ
Those quotes marks are a discourse copy/paste quirk
The issue was that they were using an incorrectly formatted command, with a single leading dash, to specify a single global variable from the command line.
The second attempt to run the command, the -g was used and thatâs for specifying a file location to read all the global variables.
Ah-ha, I fell for the forumâs copy-and-paste bug myself. Was puzzling over why it wasnât working, only to discover that I had been using the invalid curly-quotes from earlier examples. Once I literally straightened them out, it worked!
Bad: âglobal-var âk=vâ ; // bad em-dash & curly-quotes
Good: --env-var "ev=5999222 ; // good double-minus & straight-quotes"
References:
issue 764--global-var option added on Aug 22, 2017
issue 1799--env-var option added in Newman v4.4.0.