section.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. var PageUtils = require('./page-utils.js');
  2. var CommandWrapper = require('./command-wrapper.js');
  3. /**
  4. * Class that all sections subclass from
  5. *
  6. * @param {Object} options Section options defined in page object
  7. * @constructor
  8. */
  9. function Section(options) {
  10. this.parent = options.parent;
  11. this.client = this.parent.client;
  12. if(!options.selector) {
  13. throw new Error('No selector property for section "' + options.name +
  14. '" Instead found properties: ' + Object.keys(options));
  15. }
  16. this.name = options.name;
  17. this.selector = options.selector;
  18. this.locateStrategy = options.locateStrategy || 'css selector';
  19. this.api = this.parent.api;
  20. this.commandLoader = this.parent.commandLoader;
  21. PageUtils
  22. .createProps(this, options.props || {})
  23. .createElements(this, options.elements || {})
  24. .createSections(this, options.sections || {})
  25. .addCommands(this, options.commands || []);
  26. CommandWrapper.addWrappedCommands(this, this.commandLoader);
  27. }
  28. Section.prototype.toString = function() {
  29. return 'Section[name=' + this.name + ']';
  30. };
  31. module.exports = Section;