Code coverage report for hodman/lib/pageObjects/panelObject.js

Statements: 18.75% (3 / 16)      Branches: 0% (0 / 12)      Functions: 0% (0 / 3)      Lines: 18.75% (3 / 16)      Ignored: none     

All files » hodman/lib/pageObjects/ » panelObject.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83      1           1                                                                                                                                               1  
// Copyright 2014, Yahoo! Inc.
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.
 
var ViewObject = require('./viewObject');
 
/**
 * @class PanelObject
 * @extends ViewObject
 */
var PanelObject = ViewObject.extend(
 
	/**
	 * Panel-object constructor
	 *
	 * @constructor
	 * @param {Element} [root]
	 * @param {int} [timeOut]
	 * @param {int} [waitInMs]
	 */
	function (root, timeOut, waitInMs) {
		this.__super(this._getPanelRootElement(root, timeOut, waitInMs), timeOut, waitInMs);
	},
 
	{
		/**
		 * Gets the root element of the panel-object
		 *
		 * @method _getPanelRootElement
		 * @param {Element} context
		 * @param {int} [timeOut]
		 * @param {int} [waitInMs]
		 * @return {Element}
		 * @private
		 */
		_getPanelRootElement: function (context, timeOut, waitInMs) {
			var selector = this.constructor.SELECTOR,
				elements;
 
			context = context || this.getAdapter().getPageContext();
 
			if (selector) {
 
				this.waitUntil(function () {
					elements = context.getElements(selector);
					return elements.length > 0;
				}, timeOut, waitInMs);
 
				if (elements && elements.length === 1) {
					return elements[0];
 
				} else if (elements && elements.length > 1) {
					throw new Error("Panel-object selector is not specific enough. '" + selector + "'");
 
				} else {
					throw new Error("Root element for panel-object could not be found. '" + selector + "'");
				}
 
			} else {
				return context;
			}
		}
	},
 
	{
		/**
		 * @property TYPE
		 * @type {string}
		 * @static
		 */
		TYPE: 'PanelObject',
 
		/**
		 * Selector for panel object
		 *
		 * @property SELECTOR
		 * @type {string}
		 * @static
		 */
		SELECTOR: undefined
	});
 
module.exports = PanelObject;