Scripting control module for the Total Control automation system.
This module provides high-level helpers to run, monitor, and stop automation scripts
across the Total Control environment. It supports executing JavaScript (.js) files
and test scenario files (.tst), passing arguments and device hints, resolving
script paths from multiple locations, and capturing/propagating exit codes in a
consistent way (via exit() or quit() semantics).
It also exposes utilities to list running scripts, kill one or all scripts, and
run inline test functions with argument passing (sigmaRun) to simplify debugging.
Internally it integrates with the Total Control task context (sigmaConstItemId)
so logs, device managers, and utilities are correctly bound to the current run.
Key Features
- Run JS or TST files with aliasing and argument passing (
scriptRun) - Poll script status by alias (
scriptWait) and terminate runs (scriptKill,scriptKillAll) - Enumerate currently running scripts and their metadata (
scriptList) - Execute an in-memory function with arguments, capturing exit codes (
sigmaRun) - Load and execute a script file with path fallback and exit-code capture (
sigmaLoad, aliastcLoad) - Explicit script termination helpers:
exit(code): throws a special, catchable signal used by runners to returncodequit(code): immediately aborts the script with a||quit||<code>marker
- Configure and query script context (
setScriptFileName/getScriptFileName,
setSigmaConstItemId/getSigmaConstItemId,getExitCode)
Path Resolution (when a relative path is provided)
- User-defined
scriptPath(viadefine('scriptPath', '...')) - Environment variable
TCSCRIPTPATH - Default Total Control script directory: “
/Scripts”
Absolute paths are used as-is and must exist or an error is returned.
Return Codes & Status
scriptRunreturns a positive run ID on success; negative values indicate failurescriptWait(name)returns:0→ error (e.g., alias not found)-1→ running-2→ ended-3→ aborted-4→ paused
scriptKill/scriptKillAllreturn0on success,-1on failuresigmaRun/sigmaLoadreturn the captured exit code (default0if none)
Usage Examples
var scripts = require("sigma/common/scripts");
// 1) Run a JS file with arguments and an alias
var args = { arguments: [1, "mobile2", "test.js"], deviceName: "mobile1" };
var runId = scripts.scriptRun("setMobileName", "setName.js", args);
if (runId > 0) print("run id: " + runId); else print(lastError());
// 2) Wait for status by alias
var status = scripts.scriptWait("setMobileName");
print("status: " + status); // e.g. -1 (running)
// 3) List and kill running scripts
var list = scripts.scriptList();
if (list) list.forEach(s => print(`${s.name} #${s.id} @ ${s.path}`));
scripts.scriptKillAll();
// 4) Load a file directly and capture exit code
// (supports relative paths and .tst execution)
var code = scripts.sigmaLoad("tests/login.tst");
print("exit code: " + code);
// 5) Inline test function with exit code capture
function checkTitle(expected) {
const { equal } = require("assert");
const query = "TP:textInput&&IX:0";
device.sendAai({ query, action: `setText('${expected}')` });
const got = device.sendAai({ query, action: "getText" }).retval;
equal(got, expected);
return 0; // or call exit(0)
}
var rc = scripts.sigmaRun(checkTitle, "Hello");
print("rc = " + rc);
Integration Notes
.tstruns initialize test device values (initTstDevicesValue) before execution.setSigmaConstItemId(id)wires the current task ID into dependent utilities
(device manager, color/excel utils, script executor) to ensure correct scoping.
Functions
(inner) getScriptFileName() → {string}
Get the current script file name.
Example
var { getScriptFileName } = require('sigma/common/scripts');
console.log(getScriptFileName()); // "terminal"
Returns:
| string |
The current script file name. |
| number |
The current sigma constant item ID. |
| number | code |
The exit code to throw, typically 0 for success or 1 for failure. |
Throws:
| string |
A string in the format '||quit|| This function is used to stop the script immediately and return a specific status code Example 1: Used in a standalone script executed via scriptRun() // Contents of script1.js: // Contents of script2.js: Example script: // Output: Example 2: Used in a test case executed with Testrun // mte.tpf contains: // script1.js: // script2.js: // Execution script: // Output: |
| number | id |
The ID of the script execution. |
Returns:
| number |
This function returns 0 on success or -1 on failure, you can use the lastError() function to get the specific error message. |
| number |
This function returns 0 on success or -1 on failure, you can use the lastError() function to get the specific error message. |
| Array | null |
This function returns an array on success or null on failure, you can use the lastError() function to get the specific error message. |
| string | name |
alias, an alias for the script to run. |
||
| string | scriptFile |
The path to the script file. It can be an be an absolute path to a file, or it can be a user-defined path, an environment variable path, or the default relative path of the Total Control script. |
||
| Object | arguments |
<optional> |
{arguments: []} | Sets the parameters needed to execute the script. When the script starts, the variables in "arguments" will provide the available information, which means that the parameters provided by "arguments" can be directly used in the script, for example: {arguments:['test .jpg', tcConst.IMG_JPG, 0,0,100,100]},arguments.length = 7,arguments [0] ='test.js',arguments [1] ='tcConst.IMG_JPG'... |
Returns:
| number |
If successful, returns the ID value of the script run, which is greater than 0. If it fails, its return value is less than 0., specific error information can be obtained by the lastError() function. |
| string | scriptname |
The name of the execution script. |
Returns:
| number |
Returns the status of the script:
|
| string | name |
The new script file name. |
(inner) setSigmaConstItemId(id)
Update the sigmaConstItemId stored in the module.
Example
setSigmaConstItemId(12345);
Parameters:
| number | id |
The new item ID. |
(inner) sigmaLoad(file) → {number}
sigmaLoad accept one argument, JavaScript filename, it will perform the execution of the script and return the exit code, if the script does not call exit(), zero will be returned. If the filename does not specify any path, it will run the script in the TC working directory.
This function supports both regular script files (e.g., .js) and test configuration files (.tst).
If the script throws a special quit code (e.g., throw ">>> 1 <<<"), the code is captured and returned.
Parameters:
| string | file |
Relative or absolute path or file name of the script or ".tst" file to load. |
Throws:
| Error |
If the file does not exist or the script throws a non-quit error. Example: var result = sigmaLoad("test.js"); // Output: |
| number |
The exit code returned by the script (default is 0). If |
| function | fn |
The function to execute. |
|
| any | args |
<repeatable> |
Arguments to pass to the function. |
Throws:
| string | Error |
If no function is passed or a non-exit error is thrown during execution. Example: // Call sigmaRun to execute the function and get the exit code //If it executes successfully, it will return: If an error occurs (e.g. input doesn't match): |
| number |
The exit code returned by the function (or passed via |
| string | scriptFile |
Script file. Supports absolute and relative paths. |
Returns:
| void |