Test environments are a useful concept which Nightwatch provides to be used for a better structure of configuration for using large-scale projects. For a complete overview of what test environments are and how they can be used, please refer to the Defining test environments page in the Getting Started section.

You can define multiple sections (environments) of test settings so you could overwrite specific values per environment.

A "default" environment is required. All the other environments are inheriting from default and can overwrite settings as needed.

An environment inherits all the base settings and all the settings defined under the "default" environment.

{
  ...
  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "globals" : {
        "myGlobalVar" : "some value",
        "otherGlobal" : "some other value"
      }
    },

    "integration" : {
      "launch_url" : "http://staging.host",
      "globals" : {
        "myGlobalVar" : "other value"
      }
    }
  }
}

The key of the settings group can be passed then to the runner as the `--env` argument to use the specified settings, like so:
nightwatch --env integration

This can be useful if you need to have different settings for your local machine and the Continuous Integration server.

Further Reading:

Improve this article