repo_description: Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
repo_topics: automated-testing chromedriver end-to-end-testing hacktoberfest javascript nightwatch nightwatchjs nodejs selenium selenium-server selenium-webdriver testing w3c-webdriver webdriver
code: const Element = require('../element');
  const CommandWrapper = require('./command-wrapper.js');
  const ScopedElementAPILoader = require('../api/_loaders/element-api');
  
  /**
   * Class that all sections subclass from
   *
   * @param {Object} definition User-defined section options defined in page object
   * @param {Object} options Additional options to be given to the section.
   * @constructor
   */
  class Section extends Element {
    get section() {
      return this.sections;
    }
  
    /**
     * A shallow copy of the page-object api is sufficient because the wrapping of api commands (e.g. .elements()) is only one-level
     */
    createApiShallowCopy() {
      return Object.assign({}, this.parent.api);
    }
  
  
    constructor(definition, options) {
      super(definition, options);
  
      this.client = this.parent.client;
      this.api = this.createApiShallowCopy();
      this.commandLoader = this.parent.commandLoader;
  
      const BaseObject = require('./base-object.js');
      this.props = BaseObject.createProps(this, definition.props);
      this.elements = BaseObject.createElements(this, definition.elements);
      this.sections = BaseObject.createSections(this, definition.sections);
  
      BaseObject.addCommands(this, definition.commands || []);
  
      CommandWrapper.addWrappedCommands(this, this.commandLoader);
      CommandWrapper.wrapProtocolCommands(this, this.api, BaseObject.WrappedProtocolCommands);
      CommandWrapper.wrapScopedElementApi(this, this.api, ScopedElementAPILoader.availableElementCommands);
  
      Object.defineProperty(this, 'element', {
        get() {
          return this.api.element;
        },
        enumerable: true,
        configurable: false
      });
    }
  }
  
  
  module.exports = Section;
  