cli.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const fs = require("fs");
  4. const path = require("path");
  5. const yargs = require("yargs");
  6. /**
  7. * The command line interface for interacting with the Protractor runner.
  8. * It takes care of parsing command line options.
  9. *
  10. * Values from command line options override values from the config.
  11. */
  12. let args = [];
  13. process.argv.slice(2).forEach(function (arg) {
  14. let flag = arg.split('=')[0];
  15. switch (flag) {
  16. case 'debug':
  17. args.push('--nodeDebug');
  18. args.push('true');
  19. break;
  20. case '-d':
  21. case '--debug':
  22. case '--debug-brk':
  23. args.push('--v8Debug');
  24. args.push('true');
  25. break;
  26. default:
  27. args.push(arg);
  28. break;
  29. }
  30. });
  31. // TODO(cnishina): Make cli checks better.
  32. let allowedNames = [
  33. 'seleniumServerJar',
  34. 'seleniumServerStartTimeout',
  35. 'localSeleniumStandaloneOpts',
  36. 'chromeDriver',
  37. 'seleniumAddress',
  38. 'seleniumSessionId',
  39. 'webDriverProxy',
  40. 'useBlockingProxy',
  41. 'blockingProxyUrl',
  42. 'sauceUser',
  43. 'sauceKey',
  44. 'sauceAgent',
  45. 'sauceBuild',
  46. 'sauceSeleniumUseHttp',
  47. 'sauceSeleniumAddress',
  48. 'browserstackUser',
  49. 'browserstackKey',
  50. 'browserstackProxy',
  51. 'kobitonUser',
  52. 'kobitonKey',
  53. 'testobjectUser',
  54. 'testobjectKey',
  55. 'directConnect',
  56. 'firefoxPath',
  57. 'noGlobals',
  58. 'specs',
  59. 'exclude',
  60. 'suites',
  61. 'suite',
  62. 'capabilities',
  63. 'multiCapabilities',
  64. 'getMultiCapabilities',
  65. 'maxSessions',
  66. 'verbose',
  67. 'verboseMultiSessions',
  68. 'baseUrl',
  69. 'rootElement',
  70. 'allScriptsTimeout',
  71. 'getPageTimeout',
  72. 'beforeLaunch',
  73. 'onPrepare',
  74. 'onComplete',
  75. 'onCleanUp',
  76. 'afterLaunch',
  77. 'params',
  78. 'resultJsonOutputFile',
  79. 'restartBrowserBetweenTests',
  80. 'untrackOutstandingTimeouts',
  81. 'ignoreUncaughtExceptions',
  82. 'framework',
  83. 'jasmineNodeOpts',
  84. 'mochaOpts',
  85. 'plugins',
  86. 'skipSourceMapSupport',
  87. 'disableEnvironmentOverrides',
  88. 'ng12Hybrid',
  89. 'seleniumArgs',
  90. 'jvmArgs',
  91. 'configDir',
  92. 'troubleshoot',
  93. 'seleniumPort',
  94. 'mockSelenium',
  95. 'v8Debug',
  96. 'nodeDebug',
  97. 'debuggerServerPort',
  98. 'frameworkPath',
  99. 'elementExplorer',
  100. 'debug',
  101. 'logLevel',
  102. 'disableChecks',
  103. 'browser',
  104. 'name',
  105. 'platform',
  106. 'platform-version',
  107. 'tags',
  108. 'build',
  109. 'grep',
  110. 'invert-grep',
  111. 'explorer',
  112. 'stackTrace'
  113. ];
  114. let yargsOptions = {
  115. describes: {
  116. help: 'Print Protractor help menu',
  117. version: 'Print Protractor version',
  118. browser: 'Browsername, e.g. chrome or firefox',
  119. seleniumAddress: 'A running selenium address to use',
  120. seleniumSessionId: 'Attaching an existing session id',
  121. seleniumServerJar: 'Location of the standalone selenium jar file',
  122. seleniumPort: 'Optional port for the selenium standalone server',
  123. baseUrl: 'URL to prepend to all relative paths',
  124. rootElement: 'Element housing ng-app, if not html or body',
  125. specs: 'Comma-separated list of files to test',
  126. exclude: 'Comma-separated list of files to exclude',
  127. verbose: 'Print full spec names',
  128. stackTrace: 'Print stack trace on error',
  129. params: 'Param object to be passed to the tests',
  130. framework: 'Test framework to use: jasmine, mocha, or custom',
  131. resultJsonOutputFile: 'Path to save JSON test result',
  132. troubleshoot: 'Turn on troubleshooting output',
  133. elementExplorer: 'Interactively test Protractor commands',
  134. debuggerServerPort: 'Start a debugger server at specified port instead of repl',
  135. disableChecks: 'Disable cli checks',
  136. logLevel: 'Define Protractor log level [ERROR, WARN, INFO, DEBUG]'
  137. },
  138. aliases: {
  139. browser: 'capabilities.browserName',
  140. name: 'capabilities.name',
  141. platform: 'capabilities.platform',
  142. 'platform-version': 'capabilities.version',
  143. tags: 'capabilities.tags',
  144. build: 'capabilities.build',
  145. grep: 'jasmineNodeOpts.grep',
  146. 'invert-grep': 'jasmineNodeOpts.invertGrep',
  147. explorer: 'elementExplorer'
  148. },
  149. strings: { 'capabilities.tunnel-identifier': '' }
  150. };
  151. yargs.usage('Usage: protractor [configFile] [options]\n' +
  152. 'configFile defaults to protractor.conf.js\n' +
  153. 'The [options] object will override values from the config file.\n' +
  154. 'See the reference config for a full list of options.');
  155. for (let key of Object.keys(yargsOptions.describes)) {
  156. yargs.describe(key, yargsOptions.describes[key]);
  157. }
  158. for (let key of Object.keys(yargsOptions.aliases)) {
  159. yargs.alias(key, yargsOptions.aliases[key]);
  160. }
  161. for (let key of Object.keys(yargsOptions.strings)) {
  162. yargs.string(key);
  163. }
  164. yargs.check(function (arg) {
  165. if (arg._.length > 1) {
  166. throw new Error('Error: more than one config file specified');
  167. }
  168. return true;
  169. });
  170. let argv = yargs.parse(args);
  171. if (argv.help) {
  172. yargs.showHelp();
  173. process.exit(0);
  174. }
  175. if (argv.version) {
  176. console.log('Version ' + require(path.resolve(__dirname, '../package.json')).version);
  177. process.exit(0);
  178. }
  179. // Check to see if additional flags were used.
  180. argv.unknownFlags_ = Object.keys(argv).filter((element) => {
  181. return element !== '$0' && element !== '_' && allowedNames.indexOf(element) === -1;
  182. });
  183. /**
  184. * Helper to resolve comma separated lists of file pattern strings relative to
  185. * the cwd.
  186. *
  187. * @private
  188. * @param {Array} list
  189. */
  190. function processFilePatterns_(list) {
  191. return list.split(',').map(function (spec) {
  192. return path.resolve(process.cwd(), spec);
  193. });
  194. }
  195. ;
  196. if (argv.specs) {
  197. argv.specs = processFilePatterns_(argv.specs);
  198. }
  199. if (argv.exclude) {
  200. argv.exclude = processFilePatterns_(argv.exclude);
  201. }
  202. if (argv.capabilities && argv.capabilities.chromeOptions) {
  203. // ensure that single options (which optimist parses as a string)
  204. // are passed in an array in chromeOptions when required:
  205. // https://sites.google.com/a/chromium.org/chromedriver/capabilities#TOC-chromeOptions-object
  206. ['args', 'extensions', 'excludeSwitches', 'windowTypes'].forEach((key) => {
  207. if (typeof argv.capabilities.chromeOptions[key] === 'string') {
  208. argv.capabilities.chromeOptions[key] = [argv.capabilities.chromeOptions[key]];
  209. }
  210. });
  211. }
  212. // Use default configuration, if it exists.
  213. let configFile = argv._[0];
  214. if (!configFile) {
  215. if (fs.existsSync('./protractor.conf.js')) {
  216. configFile = './protractor.conf.js';
  217. }
  218. }
  219. if (!configFile && !argv.elementExplorer && args.length < 3) {
  220. console.log('**you must either specify a configuration file ' +
  221. 'or at least 3 options. See below for the options:\n');
  222. yargs.showHelp();
  223. process.exit(1);
  224. }
  225. // Run the launcher
  226. const launcher = require("./launcher");
  227. launcher.init(configFile, argv);
  228. //# sourceMappingURL=cli.js.map