4 minute read

Other Newman options

Now, you can create a file containing data that you will use as inputs. Create a simple .csv file containing two columns, each named after one of the variables. Create a couple of rows of input in the file. You should have a file that looks something like this:

Figure 8.6 – Data-driven input file Save this file as DataDrivenInput.csv. Before running your collection in Newman, you will need to export it again since you have made changes to it. Make sure you save the request in Postman and then export the collection again. You can use the same name you did previously and just overwrite the old file. Now that you have all the files that you need, you can run the collection in Newman with the following command:

Advertisement

newman run TestCollection.json -e NewmanTestEnvironment.json -d DataDrivenInputs.csv

After a few seconds, you should see a report showing the results. You will see that it ran the request with each of the inputs in your file, along with a table summarizing the results. Now that you can run a collection with an environment and data-driven inputs, you should be able to do most of what you need in Newman. There are a several other options that Newman has though, so let's take a closer look at some of them.

The -e and -d flags inNewman will give you most of the control that you need when running collections, but there are a few other flags that I want to highlight in here as well. I won't cover every possible flag in detail, but if you want, you can find out more by looking at the documentation: https://github.com/postmanlabs/

newman#command-line-options.

If you have a large collection with a lot of requests in it, there might be times when you don't want to run the whole collection. For example, you may want to only run a subset of the requests for debugging purposes. One option you can use for this is the --folder option. This option allows you to specify the name of a folder in your collection that you want to run. Newman will then only run requests that are in that folder. If you want to run several folders, you can just use the --folder option multiple times.

Another option you may want to use is the --delay-request option. This option allows you to specify an amount of time (in milliseconds) that Newman should wait after a request finishes before it starts the next request. You might want to use this if you have requests that depend on each other. For example, if you had a POST request that created some data and then you were running a GET request to check whether that data was there, you might want to put in a slight delay so that the server has time to fully process the POST request. You can also specify timeout values, which will dictate how long Newman waits for certain actions to happen before it considers them to have timed out. You can specify the --timeout flag to set a timeout value for how long you want to wait for the entire collection to run. You will want to be careful with this value since it can be hard to figure out how long it will make sense for this to be if you have a lot of requests in the collection. A more targeted option for this is --timeout-request, which specifies the amount of time to wait for a request to complete before considering it to have timed out. You can get even more targeted than that if you want by specifying the --timeout-script option, which sets the maximum amount of time any of the scripts (such as test or pre-request scripts) can run before you consider them to have timed out. These three flags are all need you to specify a number that represents the amount of time in milliseconds. You can also use options such as --bail, which lets Newman know that you want it to stop running as soon as any failure occurs. By default, it will stop the run as soon as a failure is detected, but if you want it to complete the current test script before stopping, you can specify it as --bail failure. You can also use the folder modifier as a way to skip running the entire collection if some of the inputs are incorrect. Another option you may need to use occasionally is the -k option. This option will disable strict SSL, which is sometimes required if you are getting SSL certification errors when running your request. You can also specify the --ignore-redirects option to prevent the redirect links from being automatically followed. There are several other options that Newman offers. Newman supports everything that Postman does, so if you are ever unsure of how to do something in Newman that you can do in Postman, check out the Newman documentation – you will find a way to do it.

This article is from: