gen-scripts

Creates test scripts from scenario files.

Synopsis

provengo gen-scripts [-s runs.json] [-x py] [-o path] <path-to-project>

Description

Creates test scripts (normally for 3rd party systems) from a scenarios file[1]. This sub-command is useful when you want to create a set of runs using provengo, but execute them using another automation framework. For example, if you already have a Python automation library, you can use this sub-command to generate Python scripts for your system.

By default, this command generates a single file per test scenario. If a single file is required, invoke this command with the --single-file flag, or set the gen-script.single-file configuration property to true.

Creating a scripts requires a scenarios file[2] to be present.
In order to protect your existing work, provengo will not overwrite existing scripts by default. To make provengo overwrite these files, add a --overwrite flag to the gen-scripts command. Alternatively, set the gen-scripts.overwrite flag in your project configuration to true.

Generating Scripts

There are two options to create scripts: one script file for all scenarios, or a separate script file for each scenario.

Scripts are generated using a script generation function. This function is responsible for translating a sequence of events that form a test scenario into the target language or export format. It accepts two parameters: a test scenario (an array of events) and a ScriptFile object, which is an interface to the generated script file.

/**
 * Entry point for script generation.
 * @param {Array<Event>} run A single scenario, described using an array of events
 * @param {ScriptBuilder} scriptFile A builder for the script file
 */
function generateScript(run, scriptFile){
    // read events from run, append lines to scriptFile
}

By default, this translation function is called generateScript, so provengo will look for this function in the project’s code when invoked with gen-script. To use another function (e.g. when you want to export a script to a different system), change the value of the gen-scripts.generator key in the configuration. The specified function should support accepting an event array and a ScriptBuilder (see below) as its first two parameters.

When generating a single script file, provengo additionally looks for the following functions. These functions are optional; If the are not specified, provengo will silently ignore their absence. The scriptFile parameter is an interface to the generated test script. The runs parameter is an array of all test scenarios that will be / were added to the file.

singleFileStart(runs, scriptFile)

Generate the file header, before runs are added. Useful for, e.g., adding column headers in CSV files, adding import statements to Java files, or adding initial doc data in xmls.

singleFileEnd(runs, scriptFile)

Generate the file footer, after all runs were written to the file. Useful for, e.g., closing nodes in xmls and jsons.

Function run order:

  1. singleFileStart(runs, scriptFile) (if present)

  2. generateScript(run, scriptFile) (once for each test scenario)

  3. singleFileEnd(runs, scriptFile) (if present)

  4. writeIndexFile(runs, scriptFile) (if present)

The ScriptFile Object

The scriptFile parameter is an object representing a single script being generated. It supports the following methods:

append(string, Optionalboolean)

Adds a line to the bottom of the file. when boolean is missing/true the line will add new line at the end of the line. otherwise when boolean set to false: no new line will be added at the end of the line.

include(path)

Adds the content of the file at the specified path, at the bottom of the script file being generated. The path can be absolute or relative. If relative, it is resolved starting from the project’s folder.

scriptNumber

The serial number of the scenario. Read only

Methods Available in Multiple Files Mode

When invoked with --single-file, the following methods are not available.
on writeIndexFile, the following methods are not available.
prepend(string)

Adds a line to the top of the file (e.g. when you realize you need an import)

name

Name of the generated script file. It is set for you automatically, but you can change it.

Parameters

--run-source/-s

The source of the runs. defaults to products/run-source/ensemble.json

-x/--suffix

The suffix of the generated files. Defaults to py (for Python). Can also be xml, bat, sh etc.

-o/--output-file

The output path to put the scripts in. Defaults to <project>/test-scripts/<run source name>

--single-file

Generate a single script file, rather than one file for each scenario.

--generator / -g

Name of the function function that generates the scripts. Defaults to generateScript

--generator-start

In --single-file mode, the name of the function that generates the start of the unified scenarios file. Normally used to add headers, preamble, etc. Defaults to singleFileStart.

--generator-end

In --single-file mode, the name of the function that generates the end of the unified scenarios file. Often used to add code for freeing resources, or for closing syntactic nodes (e.g. when creating XML or JSON). Defaults to singleFileEnd.


1. Scenario files are created using the `sample` or `ensemble` sub commands. They can also be downloaded from Provengo’s run reports.
2. Scenario files are created using the `sample` or `ensemble` sub commands. They can also be downloaded from Provengo’s run reports.