wc-e2e-page-objects
Version:
WooCommerce Page Objects to be used on end-to-end tests with Selenium WebDriver
191 lines (151 loc) • 8.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _seleniumWebdriver = require('selenium-webdriver');
var _wpE2eWebdriver = require('wp-e2e-webdriver');
var _wpE2ePageObjects = require('wp-e2e-page-objects');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @module WPAdminWCSettings
*/
/**
* External dependencies
*/
var SAVE_CHANGES_SELECTOR = _seleniumWebdriver.By.css('.submit [type="submit"]');
/**
* A WooCommerce admin Settings screen
*
* @extends WPAdminSettings
*/
var WPAdminWCSettings = function (_WPAdminSettings) {
_inherits(WPAdminWCSettings, _WPAdminSettings);
/**
* @param {WebDriver} driver - Instance of WebDriver.
* @param {object} args - Configuration arguments.
*/
function WPAdminWCSettings(driver) {
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, WPAdminWCSettings);
return _possibleConstructorReturn(this, (WPAdminWCSettings.__proto__ || Object.getPrototypeOf(WPAdminWCSettings)).call(this, driver, args));
}
/**
* Check whether a settings tab is present.
*
* @param {string} tab - Text in the tab.
* @return {Promise} Promise that evaluates to `true` if tab is present and displayed, `false` otherwise.
*/
_createClass(WPAdminWCSettings, [{
key: 'hasTab',
value: function hasTab(tab) {
return _wpE2eWebdriver.WebDriverHelper.isEventuallyPresentAndDisplayed(this.driver, this._getTabSelector(tab));
}
/**
* Check whether a settings sub-tab is present.
*
* @param {string} subTab - Text in the sub-tab.
* @return {Promise} Promise that evaluates to `true` if sub-tab is present and displayed, `false` otherwise.
*/
}, {
key: 'hasSubTab',
value: function hasSubTab(subTab) {
return _wpE2eWebdriver.WebDriverHelper.isEventuallyPresentAndDisplayed(this.driver, this._getSubTabSelector(subTab, { active: false }));
}
/**
* Check whether a settings tab is the current tab.
*
* @param {string} tab - Text in the tab.
* @return {Promise} Promise that evaluates to `true` if tab is active, `false` otherwise.
*/
}, {
key: 'hasActiveTab',
value: function hasActiveTab(tab) {
return _wpE2eWebdriver.WebDriverHelper.isEventuallyPresentAndDisplayed(this.driver, this._getTabSelector(tab, { active: true }));
}
/**
* Check whether a settings sub-tab is the current sub-tab.
*
* @param {string} subTab - Text in the sub-tab.
* @return {Promise} Promise that evaluates to `true` if sub-tab is active, `false` otherwise.
*/
}, {
key: 'hasActiveSubTab',
value: function hasActiveSubTab(subTab) {
return _wpE2eWebdriver.WebDriverHelper.isEventuallyPresentAndDisplayed(this.driver, this._getSubTabSelector(subTab, { active: true }));
}
/**
* Click a settings tab.
*
* @param {string} tab - Text in the tab.
* @return {Promise} Promise that evaluates to `true` if tab is successfully clicked, `false` otherwise.
*/
}, {
key: 'clickTab',
value: function clickTab(tab) {
return _wpE2eWebdriver.WebDriverHelper.clickWhenClickable(this.driver, this._getTabSelector(tab));
}
/**
* Click a settings sub-tab.
*
* @param {string} subTab - Text in the sub-tab.
* @return {Promise} Promise that evaluates to `true` if sub-tab is successfully clicked, `false` otherwise.
*/
}, {
key: 'clickSubTab',
value: function clickSubTab(subTab) {
return _wpE2eWebdriver.WebDriverHelper.clickWhenClickable(this.driver, this._getSubTabSelector(subTab));
}
/**
* Get the tab selector for a settings tab (Internal use only).
*
* @param {string} tab - Text in the tab.
* @param {object} args - Options. Default { active = false }.
* @return {object} Selector object.
*/
}, {
key: '_getTabSelector',
value: function _getTabSelector(tab, _ref) {
var _ref$active = _ref.active,
active = _ref$active === undefined ? false : _ref$active;
var exp = '//nav[contains(@class, "woo-nav-tab-wrapper")]//a[contains(@class, "nav-tab") and contains(text(), ' + tab + ')]';
if (active) {
exp = '//nav[contains(@class, "woo-nav-tab-wrapper")]//a[contains(@class, "nav-tab-active") and contains(text(), ' + tab + ')]';
}
return _seleniumWebdriver.By.xpath(exp);
}
/**
* Get the sub-tab selector for a settings sub-tab (Internal use only).
*
* @param {string} subTab - Text in the sub-tab.
* @param {object} args - Options. Default { active = false }.
* @return {object} Selector object.
*/
}, {
key: '_getSubTabSelector',
value: function _getSubTabSelector(subTab, _ref2) {
var _ref2$active = _ref2.active,
active = _ref2$active === undefined ? false : _ref2$active;
var exp = '//ul[contains(@class, "subsubsub")]/li/a[contains(text(), "' + subTab + '")]';
if (active) {
exp = '//ul[contains(@class, "subsubsub")]/li/a[contains(@class, "current") and contains(text(), "' + subTab + '")]';
}
return _seleniumWebdriver.By.xpath(exp);
}
/**
* Click save changes button.
*
* @return {Promise} Promise that evaluates to `true` if save change button is successfully clicked, `false` otherwise.
*/
}, {
key: 'saveChanges',
value: function saveChanges() {
_wpE2eWebdriver.WebDriverHelper.mouseMoveTo(this.driver, SAVE_CHANGES_SELECTOR);
return _wpE2eWebdriver.WebDriverHelper.clickWhenClickable(this.driver, SAVE_CHANGES_SELECTOR);
}
}]);
return WPAdminWCSettings;
}(_wpE2ePageObjects.WPAdminSettings);
exports.default = WPAdminWCSettings;
module.exports = exports['default'];