Testrun

mte~ Testrun

new Testrun(TestrunName, configFileName, jsScriptFileName, configName) → {object|null}

Create a new Testrun object and execute it immediately.

Example
// Given a configuration file 'mte.tpf' and script file 'mtesample.js' in the script directory.
// 'mte.tpf' content:

Testname qqmusic
deviceSN:'7N2SQL154X038444'
appname:'com.tencent.qqmusic'
username:'14016031'
password:'password001'
End

Testname qq
deviceSN:'KVSGFELFE6AY7LYL'
appname:'com.tencent.mobileqq'
username:'45178763'
password:'password002'
End

'mtesample.js' content:

var { Device } = require("sigma/device");
var { Testrun } = require("sigma/mte");
print("RUN TEST BEGIN ...");
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 {
    print("Run app");
    device.runApp(Testrun.getContext().get('appname'));
}
print("RUN TEST END!");


// Execution example:
var { Testrun } = require("sigma/mte");

try {
    var testrunObj = new Testrun("Hello007", "mte.tpf", "mtesample.js", "qqmusic");
    testrunObj.stop("Hello007");
} catch (e) {
    print("Error: " + e);
    print(lastError());
}

// If it executes successfully, it will return:
RUN TEST BEGIN ...
Device SN is: 7N2SQL154X038444
APP to be started: com.tencent.qqmusic
Username is: 14016031
Password is: password001
Run app
RUN TEST END!
Parameters:
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.

Returns:
object | null

This function returns testrun object on success or null on failure. Specific error information can be obtained by the lastError() function.

Members

getContext

Get the environment object of the Testrun object.

Example
// Example: Run test on all connected devices using runDTest and access test context
var { runDTest } = require("sigma/mte");

var devices = Device.searchObject(sigmaConst.DevAll);
var objArr = runDTest('Hello', 'facebook.tpf', 'Testenv.js', 'login', devices);

for (let i = 0; i < objArr.length; i++) {
  // Get configuration parameters for each device's test run
  print("Device name is: " + objArr[i].getContext().get('device'));
  print("Device username is: " + objArr[i].getContext().get('username'));
  print("Device password is: " + objArr[i].getContext().get('password'));
}

// Testenv.js content:

define("requireVersion","1.5.0.2865");
define("version","6.5.0.2886");
define("verbose", 0);
define("resolution", "1080*1920");

var { Testrun } = require("sigma/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!");

getDevice

Get the execution device of the current Testrun object.

Example
var { runDTest } = require("sigma/mte");

// Search for all connected devices
var devices = Device.searchObject(tcConst.DevAll);

// Run test on each device using 'facebook.tpf' and 'Testenv.js'
var objArr = runDTest('Hello', 'facebook.tpf', 'Testenv.js', 'login', devices);

// Wait for tasks to start
delay(1000);

// Output device serial numbers
for (let i = 0; i < objArr.length; i++) {
  print("Device SN is: " + objArr[i].getDevice().SN);
}

// Contents of 'Testenv.js':

define("requireVersion","1.5.0.2865");
define("version","6.5.0.2886");
define("verbose",0);
define("resolution","1080*1920");

var { Testrun } = require("sigma/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!");

getMessage

Get instant messages for the specified Testrun object.

This message reflects the current execution state of the Testrun,
such as "1:Running" or "0:Stopped", or any custom value set via setMessage().

Example
var { Testrun } = require("sigma/mte");

// Create and run a test run named "Hello"
try {
  const testrunObj = new Testrun("Hello", "facebook.tpf", "Testenv.js", "login");
} catch (e) {
  print("Error:" + e);
  print(lastError());
}

// Get the status message of the test run
var msg = testrunObj.getMessage();
print("Testrun status message: " + msg);

// 'Testenv.js' might include logic like:
define("requireVersion", "1.5.0.2865");
define("version", "6.5.0.2886");
define("verbose", 0);
define("resolution", "1080*1920");

var { Testrun } = require("sigma/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!");

// If it executes successfully, `getMessage()` may return:
// "1:Running", "0:Stopped", or any custom message set by the script

getStatus

Get the current execution status of this Testrun instance.

The returned value reflects the current state of the test run, such as:

  • "1:Running": The test is currently executing.
  • "0:Stopped": The test has been stopped.
  • Custom messages previously set using setStatus() or setMessage().

This method is useful for monitoring the test progress or result after execution.

Example
var { Testrun } = require("sigma/mte");

// Create a new Testrun instance
try {
  const testrunObj = new Testrun("Hello", "facebook.tpf", "Testenv.js", "login");
} catch (e) {
  print("Error: " + e);
  print(lastError());
}

// Get the status after test starts
var status = testrunObj.getStatus();
print("Current test status: " + status);

// 'Testenv.js' script file content:
define("requireVersion", "1.5.0.2865");
define("version", "6.5.0.2886");
define("verbose", 0);
define("resolution", "1080*1920");

var { Testrun } = require("sigma/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!");

// If successful, `getStatus()` may return:
"1:Running", "0:Stopped", or a custom status string

name :string

The name of the test run instance.

This name must be globally unique within the current script execution context.
It is used for task registration, duplicate check, runtime status management, and as an identifier in logs or error messages.

If multiple tests are running in parallel (e.g., via runDTest or runCTest), this name will typically be suffixed (e.g., Hello0, Hello1, ...).

Type:
  • string
Example
var testrun = new Testrun("Hello007", "mte.tpf", "sample.js", "qqmusic");
print("Testrun name is: " + testrun.name); // Output: Hello007

setMessage

Set up an instant message for the specified Testrun object.

Example
var { Testrun } = require("sigma/mte");

// Create a new Testrun instance
try {
  const testrunObj = new Testrun("Hello", "facebook.tpf", "Testenv.js", "login");
} catch (e) {
  print("Error: " + e);
  print(lastError());
}

// Set a custom status or message for this run
testrunObj.setMessage("Testmessage");

// Later, you can retrieve this message using:
print(testrunObj.getMessage());

// 'Testenv.js' file content:
define("requireVersion", "1.5.0.2865");
define("version", "6.5.0.2886");
define("verbose", 0);
define("resolution", "1080*1920");

var { Testrun } = require("sigma/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!");

setStatus

Set up an instant status message for the specified Testrun object.

Example
var { Testrun } = require("sigma/mte");

// Create a Testrun instance for the 'login' config in 'facebook.tpf'
try {
  const testrunObj = new Testrun("Hello", "facebook.tpf", "Testenv.js", "login");
} catch (e) {
  print("Error: " + e);
  print(lastError());
}

// Set a test status or description message
testrunObj.setStatus("TestMessage1");

// Later, retrieve the status
print(testrunObj.getStatus());  // Output: TestMessage1

// 'Testenv.js' script content:
define("requireVersion", "1.5.0.2865");
define("version", "6.5.0.2886");
define("verbose", 0);
define("resolution", "1080*1920");

var { Testrun } = require("sigma/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!");

stop

Stops the currently running test script associated with this Testrun instance.

This method attempts to terminate the script process and update its internal status message.

If the script is already stopped or not found, it will return false and log an error via lastError().

Example
// Example: Execute a Testrun and stop it via instance method
var { Testrun } = require("sigma/mte");

try {
  // Create a new Testrun instance using 'facebook.tpf' and run 'Testenv.js'
  const testrunObj = new Testrun('Hello', 'facebook.tpf', 'Testenv.js', 'login');

  // Stop the Testrun by calling the instance method
  testrunObj.stop();
} catch (e) {
  print("Error: " + e);
  print(lastError());
}

// Set custom status after stopping
testrunObj.setStatus('TestMessage1');

// Testenv.js script example:

define("requireVersion","1.5.0.2865");
define("version","6.5.0.2886");
define("verbose",0);
define("resolution","1080*1920");

var { Testrun } = require("sigma/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!");