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

Statements: 27.27% (6 / 22)      Branches: 0% (0 / 6)      Functions: 0% (0 / 8)      Lines: 27.27% (6 / 22)      Ignored: none     

All files » hodman/lib/pageObjects/ » pageObject.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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156      1 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 utils = require('preceptor-core').utils;
var _ = require('underscore');
 
/**
 * @class PageObject
 * @extends PanelObject
 */
var PageObject = PanelObject.extend(
 
	/**
	 * Page-object constructor
	 *
	 * @constructor
	 * @param {int} [timeOut]
	 * @param {int} [waitInMs]
	 */
	function (timeOut, waitInMs) {
		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 {PageObject}
		 */
		verifyIsLoaded: function (timeOut, waitInMs) {
 
			var expectedUrl = this.constructor.getExpectedUrl();
 
			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: 'PageObject',
 
 
		/**
		 * Base of page-object (optional)
		 *
		 * Note:
		 * config.baseUrl is used as default, but it can be overwritten with this value for each page
		 *
		 * @property BASE
		 * @type {string}
		 * @static
		 */
		BASE: undefined,
 
		/**
		 * Url of page-object
		 *
		 * @property URL
		 * @type {string}
		 * @static
		 */
		URL: undefined,
 
		/**
		 * Expected url of page-object (optional)
		 *
		 * @property EXPECTED_URL
		 * @type {string}
		 * @static
		 */
		EXPECTED_URL: undefined,
 
 
		/**
		 * Navigate the browser to the page-object
		 *
		 * @method navigate
		 * @param {int} [timeOut]
		 * @param {int} [waitInMs]
		 * @return {PageObject}
		 * @static
		 */
		navigate: function (timeOut, waitInMs) {
			var Class = this;
			BaseObject.getDriverAdapter().navigateTo(this.getNavigationUrl());
			return new Class(timeOut, waitInMs);
		},
 
 
		/**
		 * Get the base-url of the page-object
		 *
		 * @method getBaseUrl
		 * @return {string}
		 * @static
		 */
		getBaseUrl: function () {
			return this.BASE;
		},
 
		/**
		 * Get the navigation-url for the page-object
		 *
		 * @method getNavigationUrl
		 * @return {string}
		 * @static
		 */
		getNavigationUrl: function () {
			return utils.combine("/", this.getBaseUrl(), this.getUrl());
		},
 
		/**
		 * Gets the url of the page-object
		 *
		 * @method getUrl
		 * @return {string}
		 * @static
		 */
		getUrl: function () {
			return this.URL;
		},
 
		/**
		 * Gets the expected url
		 *
		 * @method getExpectedUrl
		 * @return {string}
		 * @static
		 */
		getExpectedUrl: function () {
			return this.EXPECTED_URL || this.getNavigationUrl();
		}
	});
 
module.exports = PageObject;