KVN
KVN

Reputation: 982

Postman - how to pass data from List<string>, in memory, into -data portion of Newman command line

I need to execute Postman collection from within my C# method. But instead of the data file, I need to pass the data directly from the method output (as List).

Here is my code:

 public StringBuilder RunPostmanCall(string collectionPath, string executionFolder, string environmentPath, List<string> inputFilePath = null)
        {
            StringBuilder runOutputBuilder = new StringBuilder();
            string runOutput = null;
            ProcessStartInfo psiNpm = new ProcessStartInfo
            {
                FileName = "cmd",
                RedirectStandardOutput = true,
                RedirectStandardInput = true,
                UseShellExecute = false
            };
            Process pNpmRun = Process.Start(psiNpm);
            pNpmRun.OutputDataReceived += (sender, a) => runOutputBuilder.AppendLine(a.Data);
            Console.WriteLine("   - Install Newman ...");
            pNpmRun.StandardInput.WriteLine($"npm install -g newman");
            Console.WriteLine("   - Execute Postman Script ...");
            string value = $"newman run " +
                $"\"" + collectionPath + "\" " +
                $"--folder \"" + executionFolder + "\" " +
                $"--environment \"" + environmentPath + "\" " +
                $"-d \"" + inputFilePath + "\" " +
                $"--disable-unicode";
            pNpmRun.StandardInput.WriteLine(value);
            pNpmRun.BeginOutputReadLine();
            pNpmRun.StandardInput.WriteLine("exit 0");

I'm getting the following error:

bin\Debug>newman run "../../api/postman_audit.json" --folder "SearchIndex" --environment "../../api/postman_environment.json" -d "System.Collections.Generic.List`1[System.String]" --disable-unicode

I could save the output into the file, and then just use that file location in the command-line. But I would like to avoid creating a file, and read data directly from the memory.

Upvotes: 1

Views: 409

Answers (1)

DieGraueEminenz
DieGraueEminenz

Reputation: 880

unfortunately with -d you can only refer to a file in your filesystem.

If you are not willing to write this data directly into a file, i would suggest to set the values directly as a global variable from commandline. Try to add this parameter to your newman run command --global-var key=value

You can add your data into a string and add it as a global variable. You can parse it in your pre-request or test-script normally.

Upvotes: 1

Related Questions