wc-e2e-page-objects
Version:
WooCommerce Page Objects to be used on end-to-end tests with Selenium WebDriver
155 lines (116 loc) • 6.31 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');
var _componentMyAccountLoginForm = require('../components/component-my-account-login-form');
var _componentMyAccountLoginForm2 = _interopRequireDefault(_componentMyAccountLoginForm);
var _componentMyAccountMenu = require('../components/component-my-account-menu');
var _componentMyAccountMenu2 = _interopRequireDefault(_componentMyAccountMenu);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 MyAccountPage
*/
/**
* External dependencies
*/
/**
* Internal dependencies
*/
var defaultArgs = {
url: '',
visit: true,
components: {
loginForm: _componentMyAccountLoginForm2.default,
menu: _componentMyAccountMenu2.default
}
};
/**
* The front-end My Account page
*
* @extends Page
*/
var MyAccountPage = function (_Page) {
_inherits(MyAccountPage, _Page);
/**
* @param {WebDriver} driver - Instance of WebDriver.
* @param {object} args - Configuration arguments.
*/
function MyAccountPage(driver) {
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, MyAccountPage);
args = Object.assign(defaultArgs, args);
var _this = _possibleConstructorReturn(this, (MyAccountPage.__proto__ || Object.getPrototypeOf(MyAccountPage)).call(this, driver, args));
_wpE2eWebdriver.WebDriverHelper.clearCookiesAndDeleteLocalStorage(driver);
return _this;
}
/**
* Log in a user using the form.
*
* @param {string} username - The user's username.
* @param {string} password - The user's password.
* @return {Promise} Promise that evaluates to `true` if form is filled and submitted successfully, `false` otherwise.
*/
_createClass(MyAccountPage, [{
key: 'login',
value: function login(username, password) {
this.components.loginForm.setUsername(username);
this.components.loginForm.setPassword(password);
this.components.loginForm.login();
return this;
}
/**
* Log out a user using the Logout link.
*
* @return {Promise} Promise that evaluates to `true` if form is filled and submitted successfully, `false` otherwise.
*/
}, {
key: 'logout',
value: function logout() {
this.clickMenu('Logout');
_wpE2eWebdriver.WebDriverHelper.waitTillPresentAndDisplayed(this.driver, _seleniumWebdriver.By.css('.woocommerce-message'));
return this._confirmLogout();
}
}, {
key: '_confirmLogout',
value: function _confirmLogout() {
var selector = _seleniumWebdriver.By.xpath(this._getConfirmLogoutXpathExpression());
return _wpE2eWebdriver.WebDriverHelper.clickWhenClickable(this.driver, selector);
}
}, {
key: '_getConfirmLogoutXpathExpression',
value: function _getConfirmLogoutXpathExpression() {
return '//div[@class="woocommerce-message"]//a[contains(text(), "Confirm and log out")]]';
}
/**
* Check whether a menu item is present.
*
* @param {string} menu - Text for the menu item.
* @return {Promise} Promise that evaluates to `true` if menu item is present, `false` otherwise.
*/
}, {
key: 'hasMenu',
value: function hasMenu(menu) {
return this.components.menu.hasMenu(menu);
}
/**
* Click a menu item.
*
* @param {string} menu - Text for the menu item.
* @return {Promise} Promise that evaluates to `true` if menu item is clicked successfully, `false` otherwise.
*/
}, {
key: 'clickMenu',
value: function clickMenu(menu) {
return this.components.menu.click(menu);
}
}]);
return MyAccountPage;
}(_wpE2ePageObjects.Page);
exports.default = MyAccountPage;
module.exports = exports['default'];
;