wc-e2e-page-objects
Version:
WooCommerce Page Objects to be used on end-to-end tests with Selenium WebDriver
184 lines (137 loc) • 7.45 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 _componentCartTotals = require('../components/component-cart-totals');
var _componentCartTotals2 = _interopRequireDefault(_componentCartTotals);
var _componentCartItem = require('../components/component-cart-item');
var _componentCartItem2 = _interopRequireDefault(_componentCartItem);
var _checkoutPage = require('./checkout-page');
var _checkoutPage2 = _interopRequireDefault(_checkoutPage);
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 CartPage
*/
/**
* External dependencies
*/
/**
* Internal dependencies
*/
var CART_EMPTY_SELECTOR = _seleniumWebdriver.By.css('.cart-empty');
var RETURN_TO_SHOP_SELECTOR = _seleniumWebdriver.By.css('.return-to-shop');
var UPDATE_CART_SELECTOR = _seleniumWebdriver.By.css('[name="update_cart"]');
var PROCEED_TO_CHECKOUT_SELECTOR = _seleniumWebdriver.By.css('.checkout-button');
var defaultArgs = {
components: {
cartTotals: _componentCartTotals2.default
}
};
/**
* The front-end Cart page.
*
* @extends Page
*/
var CartPage = function (_Page) {
_inherits(CartPage, _Page);
/**
* @param {WebDriver} driver - Instance of WebDriver.
* @param {object} args - Configuration arguments.
*/
function CartPage(driver) {
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, CartPage);
args = Object.assign(defaultArgs, args);
return _possibleConstructorReturn(this, (CartPage.__proto__ || Object.getPrototypeOf(CartPage)).call(this, driver, args));
}
/**
* Click the "Return to Shop" link.
*
* @return {Promise} Promise that evaluates to `true` if link is clicked successfully, `false` otherwise.
*/
_createClass(CartPage, [{
key: 'returnToShop',
value: function returnToShop() {
return _wpE2eWebdriver.WebDriverHelper.clickWhenClickable(this.driver, RETURN_TO_SHOP_SELECTOR);
}
/**
* Check whether the cart is empty.
*
* @return {Promise} Promise that evaluates to `true` if cart is empty, `false` otherwise.
*/
}, {
key: 'hasNoItem',
value: function hasNoItem() {
return _wpE2eWebdriver.WebDriverHelper.isEventuallyPresentAndDisplayed(this.driver, CART_EMPTY_SELECTOR);
}
/**
* Check whether a specific item is in the cart.
*
* @param {string} productTitle - The product title to look for.
* @param {object} args - Config options. Default { qty: 1 }.
* @return {Promise} Promise that evaluates to `true` if item is displayed in the cart, `false` otherwise.
*/
}, {
key: 'hasItem',
value: function hasItem(productTitle) {
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { qty: 1 };
var item = new _componentCartItem2.default(this.driver, productTitle, args);
return item.displayed();
}
/**
* Get the ComponentCartItem object for a product.
*
* @param {string} productTitle - The title of the product to associate with the object.
* @param {object} args - Config options. Default { qty: 1 }.
* @return {ComponentCartItem} ComponentCartItem.
*/
}, {
key: 'getItem',
value: function getItem(productTitle) {
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { qty: 1 };
return new _componentCartItem2.default(this.driver, productTitle, args);
}
/**
* Click the "Update cart" button.
*
* @return {Promise} Promise that evaluates to `true` if button successfully clicked, `false` otherwise.
*/
}, {
key: 'update',
value: function update() {
_wpE2eWebdriver.WebDriverHelper.clickWhenClickable(this.driver, UPDATE_CART_SELECTOR);
return _wpE2eWebdriver.WebDriverHelper.isEventuallyPresentAndDisplayed(this.driver, _seleniumWebdriver.By.xpath('//div[@class="woocommerce-message" and contains(text(), "Cart updated")]'));
}
/**
* Check whether the cart has a certain subtotal.
*
* @param {string} subtotal - The amount to look for.
* @return {Promise} Promise that evaluates to `true` if the subtotal is present, `false` otherwise.
*/
}, {
key: 'hasSubtotal',
value: function hasSubtotal(subtotal) {
return this.components.cartTotals.hasSubtotal(subtotal);
}
/**
* Click the "Proceed to checkout" button.
*
* @return {Promise} Promise that evaluates to `true` if button successfully clicked, `false` otherwise.
*/
}, {
key: 'checkout',
value: function checkout() {
_wpE2eWebdriver.WebDriverHelper.clickWhenClickable(this.driver, PROCEED_TO_CHECKOUT_SELECTOR);
return new _checkoutPage2.default(this.driver, { visit: false });
}
}]);
return CartPage;
}(_wpE2ePageObjects.Page);
exports.default = CartPage;
module.exports = exports['default'];
;