Provides the Multi-threaded Execution (MTE) framework for automated test orchestration in Total Control.
The mte module enables parallel and configurable execution of test scripts across one or more Android devices,
leveraging .tpf configuration files and JavaScript-based test cases. It is ideal for scenarios such as regression testing,
multi-device validation, and scalable automation.
Core Features:
- Create and manage test runs via the
Testrunclass. - Parallel execution across multiple devices (
runDTest) or configuration variants (runCTest). - Real-time test state tracking, including messages, status, and device binding.
- Static control interfaces for external status updates, result queries, and test termination.
- Dynamic test data injection through
.tpfconfig files or external data payloads.
Usage Overview:
- Prepare a
.tpffile with test sections (Testname,device,username, etc.). - Write a test script (
.js) that accesses parameters viaTestrun.getContext(). - Instantiate a
Testrun, or callrunDTest/runCTestfor concurrent execution. - Monitor status via
.getStatus()orTestrun.getStatus(name), and control execution via.stop()orTestrun.stop(name).
Execution APIs:
new Testrun(name, configFile, scriptFile, configName[, data[, extConfig[], autoStart]]): Single test execution.runDTest(name, configFile, scriptFile, configName, devices[]): Same script/config run across multiple devices.runCTest(name, configFile, scriptFile, baseConfig, configs[]): Same script run with multiple config variants.
Functions
Classes
getContext(idopt) → {object}
Get the runtime context object of the specified test run.
This static method allows access to configuration parameters loaded from .tpf
for a given Testrun, outside the test script itself.
Example
// With MTE, different apps can be launched on different devices based on config.
// 'mte.tpf' configuration content:
Testname weixin
deviceSN:'CUIVAEPR99999999'
appname:'com.tencent.mm'
username:'14016031'
password:'password001'
End
Testname qq
deviceSN:'KVSGFELFE6AY7LYL'
appname:'com.tencent.mobileqq'
username:'45178763'
password:'password002'
End
// Example script: 'mtesample.js'
define("requireVersion","1.5.0.2865");
define("version","6.5.0.2886");
define("verbose",0);
define("resolution","1080*1920");
print("RUN TEST BEGIN ...");
var { Testrun } = require('./mte');
print("Device SN is: " + Testrun.getContext().get("deviceSN"));
print("APP to be started: " + Testrun.getContext().get("appname"));
print("Username is: " + Testrun.getContext().get("username"));
print("Password is: " + Testrun.getContext().get("password"));
var device = Device.searchObject(tcConst.DevSerial, Testrun.getContext().get("deviceSN"));
if (!device) {
print(lastError());
} else {
device.runApp(Testrun.getContext().get("appname"));
}
print("RUN TEST END!");
// Caller usage example:
var { Testrun } = require('./mte');
// Start test for the 'weixin' config section in mte.tpf
var testrunObj1 = new Testrun('Hello', 'mte.tpf', 'mtesample.js', 'weixin');
// Will launch WeChat on the phone with SN 'CUIVAEPR99999999'
// Start test for the 'qq' config section in mte.tpf
var testrunObj2 = new Testrun('Hello2', 'mte.tpf', 'mtesample.js', 'qq');
// Will launch QQ on the phone with SN 'KVSGFELFE6AY7LYL'
Parameters:
| string | number | id |
<optional> |
The test run ID. If not provided, uses the latest Testrun ID. |
Returns:
| object |
Returns the context object (configuration data) of the specified test run. |
| string | number | id |
<optional> |
The ID of the Testrun. If not provided, returns the device from the most recently executed Testrun. |
Returns:
| Device | null |
A |
| string | name |
The name of the Testrun instance. |
Returns:
| string |
The current message or status of the test run. |
| string | name |
The name of the Testrun instance to query. |
Returns:
| string |
The current status message of the specified Testrun. |
| string | name |
The name of the Testrun instance. |
| string | msg |
The custom message to store (e.g., |
setStatus(name, message)
Set the current status string for a running Testrun by name.
This static method is used to assign a custom status message to a specific Testrun instance
identified by its name. The updated status can be later retrieved via Testrun.getStatus(name)
or testrunObj.getStatus() if you hold the object reference.
Note: that all non-object interfaces must be executed in the called js script.
Example
// Sample configuration file: 'facebook.tpf'
Testname login
device:'MOBILE-01'
username:'tester001'
password:'abc123'
info:'Login test user'
End
// Sample test script: 'Testenv.js'
define("requireVersion", "1.5.0.2865");
define("version", "6.5.0.2886");
define("verbose", 0);
define("resolution", "1080*1920");
var { Testrun } = require('./mte');
print("RUN TEST BEGIN ...");
print("Device name is: " + Testrun.getContext().get("device"));
print("Device username is: " + Testrun.getContext().get("username"));
print("Device password is: " + Testrun.getContext().get("password"));
print("Device message is: " + Testrun.getContext().get("info"));
print("RUN TEST END!");
//Example
var { Testrun } = require('./mte');
// In the controller script, start a Testrun and assign a status
let testrunObj;
try {
testrunObj = new Testrun("Hello", "facebook.tpf", "Testenv.js", "login");
} catch (e) {
print("Error: " + e);
print(lastError());
}
// Update the status externally using the static API
Testrun.setStatus("Hello", "bbbbbbbbbbbbb");
// Later, retrieve the status:
var status = Testrun.getStatus("Hello");
print("Updated status: " + status); // Output: bbbbbbbbbbbbb
Parameters:
| string | name |
The name of the Testrun instance to update. |
| string | message |
The status message to assign (e.g., |
stop(name) → {boolean}
Stops the currently running Testrun by its name.
This static method terminates the test script associated with the provided Testrun name.
If the task is found and stopped successfully, it returns true. If the task is not found
or already stopped, it returns false and logs an error via lastError().
Example
Configuration file: facebook.tpf
Testname login
device:'MOBILE-01'
username:'tester001'
password:'abc123'
info:'Login test'
End
// Script file: Testenv.js
define("requireVersion", "1.5.0.2865");
define("version", "6.5.0.2886");
define("verbose", 0);
define("resolution", "1080*1920");
var { Testrun } = require('./mte');
print("RUN TEST BEGIN ...");
print("Device name is: " + Testrun.getContext().get("device"));
print("Device username is: " + Testrun.getContext().get("username"));
print("Device password is: " + Testrun.getContext().get("password"));
print("Device message is: " + Testrun.getContext().get("info"));
print("RUN TEST END!");
// Example
// Usage in controller script
var { Testrun } = require('./mte');
let testrunObj;
try {
testrunObj = new Testrun("Hello", "facebook.tpf", "Testenv.js", "login");
} catch (e) {
print("Error: " + e);
print(lastError());
}
// Attempt to stop the Testrun by name
Testrun.stop("Hello"); // First stop
print("AAAAAAAA");
// Attempting to stop again (likely already stopped)
Testrun.stop("Hello"); // Will trigger error: "Test Hello is not found!"
print("BBBBBBBBB");
Parameters:
| string | name |
The name of the Testrun instance to stop. |
Returns:
| boolean |
Returns |
| string | TestrunName |
Testrun name. |
| string | configFileName |
The file name of the tpf configuration parameter file. Relative path, the tpf file must be in the same path as the js file specified by the third parameter. |
| string | jsScriptFilename |
The js file to be executed, the relative path, will be found in the user-defined scriptPath, the path corresponding to the environment variable TCSCRIPTPATH, / this computer / document / Scripts / under the script file, if not, lastError () will prompt an error . |
| string | configName |
Specify which configuration in the file corresponding to configFileName is used. |
| Array | configNameArr |
This parameter specifies an additional configuration to execute the script separately. |
Returns:
| Array |
Multiple Testrun objects are automatically created when runCTest is run. The return value is an array of these objects. |
| string | TestrunName |
The base name for each Testrun instance. A unique suffix will be added automatically. |
| string | configFileName |
The |
| string | jsScriptFilename |
The test script |
| string | configName |
The configuration section name in the |
| Array | deviceArr |
An array of |
Returns:
| Array |
Returns an array of |