Using the value of the Protractor parameter in the plugin configuration in conf.js

I would like my protractor-screenshoter-plugin to create a report directory with the specification name as the directory name. The specification name should be passed as a parameter when Protractor starts:
protractor --specs my_spec.js conf.js

After calling the above command, I want my test to run and the report to be created in the my_spec.js (or my_spec) directory.
Plugin configuration is included in conf.js :

plugins: [{
    package: 'protractor-screenshoter-plugin',
    screenshotOnExpect: 'failure+success',
    screenshotOnSpec: 'failure',
    withLogs: false,
    htmlReport: true,
    screenshotPath: '',//I would like to put the --specs parameter value here
    writeReportFreq: 'end',
    clearFoldersBeforeTest: true
}]

Any ideas how to do this? How to access the parameter value of the "contractor" procedure parameter in conf.js?

+4
1

CLI, Protractor process.argv, ,

. Nodejs process.argv

process.argv , , Node.js. process.execPath. . Process.argv0, argv [0]. JavaScript. .

protractor conf.js --spec demo2.js

console.log(process.argv) conf.js -

[ 'C:\\Program Files\\nodejs\\node.exe',
  'C:\\Users\\aditya\\AppData\\Roaming\\npm\\node_modules\\protractor\\bin\\protractor',
  'conf.js',
  '--specs',
  'demo2.js' ]

, . specs ( , ),

function getSpecsFromCLIArg() {
    for (i = 0; i < process.argv.length; i++) {
        if (process.argv[i] === '--specs') {
            var specFile = process.argv[i + 1];
            return specFile.substr(0, specFile.indexOf('.'));
        }
    }
}
console.log(getSpecsFromCLIArg())

plugins: [{
    package: 'protractor-screenshoter-plugin',
    screenshotOnExpect: 'failure+success',
    screenshotOnSpec: 'failure',
    withLogs: false,
    htmlReport: true,
    screenshotPath: getSpecsFromCLIArg(),
    writeReportFreq: 'end',
    clearFoldersBeforeTest: true
}]
0

Source: https://habr.com/ru/post/1664687/


All Articles