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

Statements: 25% (5 / 20)      Branches: 0% (0 / 6)      Functions: 0% (0 / 4)      Lines: 25% (5 / 20)      Ignored: none     

All files » hodman/lib/pageObjects/ » genericPageObject.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 84 85 86 87 88 89 90 91 92 93      1 1 1                 1                                                                                                                                                         1  
// Copyright 2014, Yahoo! Inc.
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.
 
var BaseObject = require('./baseObject');
var PanelObject = require('./panelObject');
var _ = require('underscore');
 
/**
 * @class GenericPageObject
 * @extends PanelObject
 *
 * @property {string} _navigationUrl
 * @property {string} _expectedUrl
 */
var GenericPageObject = PanelObject.extend(
 
	/**
	 * Generic page-object constructor
	 *
	 * @constructor
	 * @param {string} navigationUrl
	 * @param {string} [expectedUrl=navigationUrl]
	 * @param {int} [timeOut]
	 * @param {int} [waitInMs]
	 */
	function (navigationUrl, expectedUrl, timeOut, waitInMs) {
 
		this._navigationUrl = navigationUrl;
		this._expectedUrl = expectedUrl;
 
		this.__super(null, timeOut, waitInMs);
	},
 
	{
		/**
		 * Verifies that the page-object and its sub-dom-elements are loaded as expected
		 *
		 * @method verifyIsLoaded
		 * @param {int} [timeOut]
		 * @param {int} [waitInMs]
		 * @return {GenericPageObject}
		 * @private
		 */
		verifyIsLoaded: function (timeOut, waitInMs) {
 
			var navigationUrl = this._navigationUrl,
				expectedUrl = this._expectedUrl;
 
			expectedUrl = expectedUrl || navigationUrl;
 
			if (expectedUrl !== "*") {
				this.waitUntil(function () {
					var url = this.getAdapter().getCurrentUrl();
 
					if (_.isString(expectedUrl)) {
						expectedUrl = new RegExp(expectedUrl);
					}
					return !!url.match(expectedUrl);
				}.bind(this), timeOut, waitInMs);
			}
 
			return this.__super(timeOut, waitInMs);
		}
	},
 
	{
		/**
		 * @property TYPE
		 * @type {string}
		 * @static
		 */
		TYPE: 'GenericPageObject',
 
		/**
		 * Navigates to the given url and check the expected url
		 *
		 * @method navigate
		 * @param {string} navigationUrl
		 * @param {string} [expectedUrl=navigationUrl]
		 * @param {int} [timeOut]
		 * @param {int} [waitInMs]
		 * @return {GenericPageObject}
		 * @static
		 */
		navigate: function (navigationUrl, expectedUrl, timeOut, waitInMs) {
			var Class = this;
			BaseObject.getDriverAdapter().navigateTo(navigationUrl);
			return new Class(navigationUrl, expectedUrl, timeOut, waitInMs);
		}
	});
 
module.exports = GenericPageObject;