UNPKG

wc-e2e-page-objects

Version:

WooCommerce Page Objects to be used on end-to-end tests with Selenium WebDriver

291 lines (233 loc) 12.6 kB
'use strict'; 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 _helper = require('../../helper'); var wcHelper = _interopRequireWildcard(_helper); var _wpAdminWcSettings = require('./wp-admin-wc-settings'); var _wpAdminWcSettings2 = _interopRequireDefault(_wpAdminWcSettings); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } 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 WPAdminWCSettingsGeneral */ /** * External dependencies */ /** * Internal Dependencies */ var BASE_LOCATION_SELECTOR = wcHelper.getSelect2ToggleSelectorByName('woocommerce_default_country'); var SELLING_LOCATION_SELECTOR = wcHelper.getSelect2ToggleSelectorByName('woocommerce_allowed_countries'); var SELL_TO_SPECIFIC_COUNTRIES_SELECTOR = wcHelper.getSelect2ToggleSelectorByName('woocommerce_specific_allowed_countries[]', { multiple: true }); var ENABLE_TAXES_SELECTOR = _seleniumWebdriver.By.css('#woocommerce_calc_taxes'); var STORE_NOTICE_SELECTOR = _seleniumWebdriver.By.css('#woocommerce_demo_store'); var CURRENCY_SELECTOR = wcHelper.getSelect2ToggleSelectorByName('woocommerce_currency'); var CURRENCY_POSITION_SELECTOR = wcHelper.getSelect2ToggleSelectorByName('woocommerce_currency_pos'); var THOUSAND_SEPARATOR_SELECTOR = _seleniumWebdriver.By.css('#woocommerce_price_thousand_sep'); var DECIMAL_SEPARATOR_SELECTOR = _seleniumWebdriver.By.css('#woocommerce_price_decimal_sep'); var NUMBER_OF_DECIMALS_SELECTOR = _seleniumWebdriver.By.css('#woocommerce_price_num_decimals'); var defaultArgs = { url: '', visit: true }; /** * The General admin settings screen * * @extends WPAdminWCSettings */ var WPAdminWCSettingsGeneral = function (_WPAdminWCSettings) { _inherits(WPAdminWCSettingsGeneral, _WPAdminWCSettings); /** * @param {WebDriver} driver - Instance of WebDriver. * @param {object} args - Configuration arguments. */ function WPAdminWCSettingsGeneral(driver) { var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck(this, WPAdminWCSettingsGeneral); args = Object.assign(defaultArgs, args); return _possibleConstructorReturn(this, (WPAdminWCSettingsGeneral.__proto__ || Object.getPrototypeOf(WPAdminWCSettingsGeneral)).call(this, driver, args)); } /** * Select the base location. * * @param {string} keyword - Text to enter in the search field. * @param {string} exactOption - Text of option to select. * @return {Promise} Promise that evaluates to `true` if base location selected successfully, `false` otherwise. */ _createClass(WPAdminWCSettingsGeneral, [{ key: 'selectBaseLocation', value: function selectBaseLocation(keyword, exactOption) { return wcHelper.select2OptionWithSearch(this.driver, BASE_LOCATION_SELECTOR, keyword, exactOption); } /** * Select the selling location preferences. * * @param {string} option - Text of option to select. * @return {Promise} Promise that evaluates to `true` if selling location preferences selected successfully, `false` otherwise. */ }, { key: 'selectSellingLocation', value: function selectSellingLocation(option) { return wcHelper.select2Option(this.driver, SELLING_LOCATION_SELECTOR, option); } /** * Select a country to use for a selling location. * * @param {string} keyword - Text to enter in the search field. * @param {string} exactOption - Text of option to select. * @return {Promise} Promise that evaluates to `true` if specified country selected successfully, `false` otherwise. */ }, { key: 'setSellToSpecificCountries', value: function setSellToSpecificCountries(keyword, exactOption) { _wpE2eWebdriver.WebDriverHelper.waitTillPresentAndDisplayed(this.driver, SELL_TO_SPECIFIC_COUNTRIES_SELECTOR); _wpE2eWebdriver.WebDriverHelper.clickWhenClickable(this.driver, SELL_TO_SPECIFIC_COUNTRIES_SELECTOR); // Wait till search results visible before typing the keyword. _wpE2eWebdriver.WebDriverHelper.waitTillPresentAndDisplayed(this.driver, _seleniumWebdriver.By.css('.select2-results')); var searchSelector = _seleniumWebdriver.By.css('.select2-container--open input.select2-search__field'); _wpE2eWebdriver.WebDriverHelper.setWhenSettable(this.driver, searchSelector, keyword); var optionSelector = _seleniumWebdriver.By.xpath('//li[contains(@class, "select2-results__option") and matches(.,"' + exactOption + '")]'); // Make it doesn't trigger error when element is not found. return this.driver.findElement(optionSelector).then(function (el) { return el.click().then(function () { return true; }, function () { return false; }); }, function () { return false; }); } /** * Unset a country from the selling locations. * * @param {string} choice - Text of option to select. * @return {Promise} Promise that evaluates to `true` if specified country is/gets unselected, `false` otherwise. */ }, { key: 'removeChoiceInSellToSpecificCountries', value: function removeChoiceInSellToSpecificCountries(choice) { // TODO: maybe move this to wcHelper. var selector = _seleniumWebdriver.By.xpath('//select[@name="woocommerce_specific_allowed_countries[]"]' + '/preceding-sibling::div[contains(@class, "wc-enhanced-select")]' + ('//div[contains(.,"' + choice + '")]') + '/following-sibling::a[contains(@class, "select2-search-choice-close")]'); // Make it doesn't trigger error when element is not found. return this.driver.findElement(selector).then(function (el) { return el.click().then(function () { return true; }, function () { return false; }); }, function () { return false; }); } /** * Check the "Enable taxes" checkbox. * * @return {Promise} Promise that evaluates to `true` if box is/gets checked successfully, `false` otherwise. */ }, { key: 'checkEnableTaxes', value: function checkEnableTaxes() { _wpE2eWebdriver.WebDriverHelper.unsetCheckbox(this.driver, ENABLE_TAXES_SELECTOR); return _wpE2eWebdriver.WebDriverHelper.setCheckbox(this.driver, ENABLE_TAXES_SELECTOR); } /** * Uncheck the "Enable taxes" checkbox. * * @return {Promise} Promise that evaluates to `true` if box is/gets unchecked successfully, `false` otherwise. */ }, { key: 'uncheckEnableTaxes', value: function uncheckEnableTaxes() { _wpE2eWebdriver.WebDriverHelper.setCheckbox(this.driver, ENABLE_TAXES_SELECTOR); return _wpE2eWebdriver.WebDriverHelper.unsetCheckbox(this.driver, ENABLE_TAXES_SELECTOR); } /** * Check the "Store notice" checkbox. * * @return {Promise} Promise that evaluates to `true` if box is/gets checked successfully, `false` otherwise. */ }, { key: 'checkStoreNotice', value: function checkStoreNotice() { _wpE2eWebdriver.WebDriverHelper.unsetCheckbox(this.driver, STORE_NOTICE_SELECTOR); return _wpE2eWebdriver.WebDriverHelper.setCheckbox(this.driver, STORE_NOTICE_SELECTOR); } /** * Uncheck the "Store notice" checkbox. * * @return {Promise} Promise that evaluates to `true` if box is/gets checked successfully, `false` otherwise. */ }, { key: 'uncheckStoreNotice', value: function uncheckStoreNotice() { _wpE2eWebdriver.WebDriverHelper.setCheckbox(this.driver, STORE_NOTICE_SELECTOR); return _wpE2eWebdriver.WebDriverHelper.unsetCheckbox(this.driver, STORE_NOTICE_SELECTOR); } /** * Select a shop currency. * * @param {string} keyword - Text to enter in the search field. * @param {string} exactOption - Text of option to select. * @return {Promise} Promise that evaluates to `true` if specified currency selected successfully, `false` otherwise. */ }, { key: 'selectCurrency', value: function selectCurrency(keyword, exactOption) { return wcHelper.select2OptionWithSearch(this.driver, CURRENCY_SELECTOR, keyword, exactOption); } /** * Select a shop currency position. * * @param {string} position - Text of position to select. * @return {Promise} Promise that evaluates to `true` if specified currency position selected successfully, `false` otherwise. */ }, { key: 'selectCurrencyPosition', value: function selectCurrencyPosition(position) { return wcHelper.select2Option(this.driver, CURRENCY_POSITION_SELECTOR, position); } /** * Set the thousand separator input. * * @param {string} separator - What to use for the separator. * @return {Promise} Promise that evaluates to `true` if separator set successfully, `false` otherwise. */ }, { key: 'setThousandSeparator', value: function setThousandSeparator(separator) { return _wpE2eWebdriver.WebDriverHelper.setWhenSettable(this.driver, THOUSAND_SEPARATOR_SELECTOR, separator); } /** * Set the decimal separator input. * * @param {string} separator - What to use for the separator. * @return {Promise} Promise that evaluates to `true` if separator set successfully, `false` otherwise. */ }, { key: 'setDecimalSeparator', value: function setDecimalSeparator(separator) { return _wpE2eWebdriver.WebDriverHelper.setWhenSettable(this.driver, DECIMAL_SEPARATOR_SELECTOR, separator); } /** * Set the number of decimals input. * * @param {number} num - Number of decimals. * @return {Promise} Promise that evaluates to `true` if number of decimals set successfully, `false` otherwise. */ }, { key: 'setNumberOfDecimals', value: function setNumberOfDecimals(num) { return _wpE2eWebdriver.WebDriverHelper.setWhenSettable(this.driver, NUMBER_OF_DECIMALS_SELECTOR, num); } }]); return WPAdminWCSettingsGeneral; }(_wpAdminWcSettings2.default); exports.default = WPAdminWCSettingsGeneral; module.exports = exports['default'];