command_definition.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const path_1 = require("path");
  4. class CommandDefinition {
  5. constructor(name, params, method, path, preprocessParams = (x) => x) {
  6. this.name = name;
  7. this.params = params;
  8. this.method = method;
  9. this.path = path;
  10. this.preprocessParams = preprocessParams;
  11. }
  12. compile(extender, silentFailure) {
  13. try {
  14. extender.defineCommand(this.name, this.params, this.method, path_1.posix.join('/session/:sessionId', this.path));
  15. return (...args) => {
  16. return extender.execCommand(this.name, this.method, this.preprocessParams(args));
  17. };
  18. }
  19. catch (e) {
  20. if (silentFailure) {
  21. return (...args) => {
  22. throw new Error('Command "' + this.name + '" could not be extended onto WebDriver instance. ' +
  23. 'This is generally a result of using `directConnect` in protractor.');
  24. };
  25. }
  26. else {
  27. throw e;
  28. }
  29. }
  30. }
  31. }
  32. exports.CommandDefinition = CommandDefinition;
  33. //# sourceMappingURL=command_definition.js.map