Automated Testing - Creating the First Test Case
Scripting
1. Create script directory
Firstly, create a folder in the directory %appdata%\Sigma-RT\Total Control\modules\test, for example, "testsuite," to store your scripts.
2. Write an automated test script
Create a script file with the extension js and begin writing your test case script.
For instance, you can create a script named scrollIntoViewTest.js containing two test cases:
/**
* Set up function called before any test.
*/
exports.setUp = function() {
print("setUp")
};
/**
* Test function to check to test restart app
*/
exports.test_restartapp = function() {
print("test_case1:open test app")
var alldevices = Device.searchObject(tcConst.DevAll)
alldevices.restartAppSync("com.sigma_rt.sigmatestapp");
delay(3000)
//start to check
for(var i=0;i < alldevices.length;i++){
var ret = alldevices[i].getForegroundApp();
if(ret!="com.sigma_rt.sigmatestapp"){
assert("Start app failed")
}
}
}
/**
* Test function to click CHECKBOX button
*/
exports.test_clickCHECKBOX = function() {
print("test_case1:open test app")
var alldevices = Device.searchObject(tcConst.DevAll)
alldevices.restartAppSync("com.sigma_rt.sigmatestapp");
delay(3000)
//start to click CHECKBOX button
alldevices.sendAai({query:"T:CHECKBOX",action:"click"});
delay(3000)
//start to check
for(var i=0;i < alldevices.length;i++){
var ret = alldevices[i].sendAai({query:"T:Radio Group"});
if(ret==null){
assert("Click CHECKBOX button failed")
}
}
}
/**
* Tear down function called after each test.
*/
exports.tearDown = function() {
// Navigate back
print("tearDown")
}
/**
* Module ID for exporting.
*/
exports.id = module.id;
Note:
3. Create a launch script
It is recommended to place the launch script in the default path of the executor. Open Total Control on your computer, click on "Scripts" to open the script window, and you can see the default path in the script window. This path can be modified.
Create a launch script named runcases.js with the following code:
Note: If you copy and use this script, change the script directory address in the first line of code to your actual address (i.e., the address of the testsuite directory you created in step 1). Otherwise, the script will not run correctly.
addToClasspath('C:/Users/admin/AppData/Roaming/Sigma-RT/Total Control/modules/test/testsuite');
exports.testScrollIntoView = require('scrollIntoViewTest');
//exports.testSettings = require('settings');
test = require('sigma/test');
logFilename = "D:/log.txt";
test.logFile(logFilename);
test.run(exports);
//print(require('fs').read(logFilename));
Note:
Running Script
Before running the script, please ensure that the testing devices are connected to Total Control. The current script can be executed simultaneously on all connected devices.
1. After creating the script, restart the script window. You should see the runcases.js script in the list. Click the button next to the script to create a task and click "Start."
2. The execution will begin. After completion, you can view the results, including the number of passed and failed test cases. Clicking the log icon allows you to view the log.