nightwatch
Version:
Easy to use Node.js based end-to-end testing solution for web applications using the W3C WebDriver API.
55 lines (43 loc) • 1.69 kB
JavaScript
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;