3

How do I get a file name of currently executed spec? For example: I run: protractor conf.js --specs ./spec/first_spec.js,./spec/second_spec.js

so I want to retrieve array ['first_spec','second_spec'], because I want to show it in a report.html. Is this a good way of thinking or is there a built-in function for file names in the latest run? I'm new to protractor and angular, and I found only a way to extract individual describe which doesn't really help me. I write this on top of protractor-angular-screenshot-reporter.

FCin
  • 3,804
  • 4
  • 20
  • 49

1 Answers1

4

This is one way of doing it. Read the array of test cases passed from CLI arguments and use it as per your convenience

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)
},

Please refer my blog post for more details on the same.

AdityaReddy
  • 3,625
  • 12
  • 25