获取已执行的规范文件的文件名

Get file names of executed spec files

本文关键字:文件 文件名 范文件 执行 获取      更新时间:2023-09-26

如何获得当前执行的spec的文件名?例如:我运行:protractor conf.js --specs ./spec/first_spec.js,./spec/second_spec.js

所以我想检索数组['first_spec','second_spec'],因为我想在report.html中显示它。这是一种很好的思考方式,还是在最近的运行中有一个内置的文件名函数?我是量角器和角的新手,我只找到了一种提取单个describe的方法,这对我没有什么帮助。我把这个写在protractor-angular-screenshot-reporter上面

这是一种方法。读取从CLI参数传递的测试用例数组,并根据您的方便使用它

onPrepare: function() {
var testCaseArr
    for (i = 0; i < process.argv.length; i++) {
        argument = process.argv[i];
        // if "specs" are found we know that the immediate following object is the array of test scenarios
        if (argument.indexOf('specs')>0) {
            specIndex = i + 1;
            testCaseArr = process.argv[i+1];
            break;
        }
    }
    // This will output - ['first_spec','second_spec']
    console.log(testCaseArr)
},

详情请参考我的博客。