Use cases and examples

These examples show two common ways to use as-code. The first overrides part of an existing NeoLoad project. The second describes a whole test in YAML and switches between environments.

Override scenario settings for an automated test

In this use case, you supply a YAML file that describes the scenario to run, instead of the scenario that already sits in the NeoLoad project. The scenario settings to apply are:

Copy
scenarios:
- name: MyScenario
  populations:
  - name: MyPopulation
    constant_load:
      users: 500
      duration: 15m

A scenario in the YAML file replaces the scenario of the same name in the NeoLoad project. If the project has no scenario with that name, NeoLoad adds it. In this example, MyScenario already exists in the NeoLoad project, so the definition in the YAML file replaces it.

The same mechanism overrides server host names and test data:

Copy
servers:
- name: myapp
  host: myapp-staging.company.com
  scheme: https
  port: 443
variables:
- file:
    name: cities_file
    path: staging/data/list_of_cities.csv
    is_first_line_column_names: true
    change_policy: each_iteration
    scope: global

Then run the following command:

Copy
NeoLoadCmd.exe -project "<neoload projects path>/MyProject/MyProject.nlp" "<neoload projects path>/myproject-scenarios.yaml" "<neoload projects path>/myproject-environment.yaml" -launch MyScenario

As an alternative, create a ZIP archive of the <neoload projects path> folder, then upload it and run it from NeoLoad Web.

Structure YAML files per environment

The following layout uses only YAML files and covers two execution environments, staging and pre-production:

Copy
common/design.yaml
staging/servers.yaml
staging/variables.yaml
staging/slas.yaml
preprod/servers.yaml
preprod/variables.yaml
preprod/slas.yaml

Add a top-level file for each environment that includes the files that environment needs. Create staging.yaml:

Copy
includes:
- common/design.yaml
- staging/servers.yaml
- staging/variables.yaml
- staging/slas.yaml

Then create preprod.yaml:

Copy
includes:
- common/design.yaml
- preprod/servers.yaml
- preprod/variables.yaml
- preprod/slas.yaml

Finally, add a default file that points at the environment you run most often. Create default.yaml:

Copy
includes:
- staging.yaml

In the includes section, use a forward slash (/) as the path separator. No other separator works.

Zip the whole folder, then pick one of these two ways to run an environment:

  • Name the YAML file to run, either from the command line with -project staging.yaml or from the NeoLoad Web API with as-code: staging.yaml.

  • Edit default.yaml so it includes the file you want, then run the test from the NeoLoad Web interface, from the NeoLoad Web API without the as-code argument, or from the command line by naming only the folder that holds the YAML files.