UNPKG

hae-uitest

Version:

A UI Test Framework for Huawei HAE

67 lines (54 loc) 1.68 kB
//hae-uitest var fs = require('fs'); var path = require('path'); var merge = require('merge'); var config = require('./config'); var taskRunner = require('./lib/taskRunner'); module.exports = function(program) { var filePath = path.resolve(process.cwd(), program.taskFile); var fileExtName = path.extname(program.taskFile).toLowerCase(); var coustomTaskConf = null; //默认任务配置 var defaultTaskConf = { wtsPath: path.normalize(__dirname + '/wts'), screenshotPath: path.normalize(__dirname + '/screenshots'), reportPath: path.normalize(__dirname + '/reports'), logPath: path.normalize(__dirname + '/logs'), reporter: 'json' } //默认 TML 配置 var defaultTmlConf = config.capabilities; //判断文件类型 switch (fileExtName) { case '.json': //检查文件是否存在 if (!fs.existsSync(filePath)) { throw new Error('the test task file does not exist.'); } //来自任务文件的配置 try { coustomTaskConf = require(filePath); } catch (e) { throw new Error('illeage test task file.'); } break; case '.tml': //检查文件是否存在 if (!fs.existsSync(filePath)) { throw new Error('the TML file does not exist.'); } //为 TML 构建任务配置 coustomTaskConf = { testScripts: [ merge({filePath: filePath}, defaultTmlConf) ] } break; default: throw new Error('invalid file format.') } //合并任务配置 var taskConf = merge({}, defaultTaskConf, coustomTaskConf); //TML 相对路径 taskConf.tmlBasePath = path.dirname(filePath); //执行测试任务 taskRunner(taskConf); }