diff --git a/context/context.js b/context/context.js new file mode 100644 index 0000000..f6026fd --- /dev/null +++ b/context/context.js @@ -0,0 +1,8 @@ + +class SharedContext { + constructor() { + this.newTextPost = null; + } +} + +module.exports = new SharedContext(); \ No newline at end of file diff --git a/helpers/common-actions.js b/helpers/common-actions.js index 2695d9c..cc2e7e3 100644 --- a/helpers/common-actions.js +++ b/helpers/common-actions.js @@ -1,23 +1,8 @@ -const colors = require('colors'); const envconfig = require('../envConfigs')[process.env.NODE_ENV]; -const moment = require("moment"); - const { - DEFAULT_TIMEOUT, - LOGIN_ROLES + DEFAULT_TIMEOUT } = require(`./${envconfig.e2eConst}`); - - - -/** - * @summary The method goto page and set local storage. - * - * @param {Page} page the page's object. - * @param {string} path the path. - * - * - * */ async function gotoPage(page, path) { try { let timeout = process.env.APP_LOAD_TIMEOUT ? process.env.APP_LOAD_TIMEOUT : DEFAULT_TIMEOUT @@ -30,23 +15,12 @@ async function gotoPage(page, path) { } } - async function isVisible(page, locator) { // await page.waitForLoadState("state:load","timeout:800") - await waitForTimeout(page,3000); + await waitForTimeout(page,10000); const visible = await page.isVisible(locator) return expect(visible).to.equal(true, '\n[Failure Message]: Element is not visible. \n[Locator]: ' + locator); } - -/** - * @summary The method clicks the element. - * - * @param {Page} page the page's object. - * @param {string} locator the locator. - * @throws {CustomException} the customer error. - * - * - * */ async function clickElement(page, locator) { try { return await page.locator(locator).click() @@ -54,16 +28,6 @@ async function clickElement(page, locator) { CustomException('Failed to click the element', locator, exec) } } - -/** - * @summary The method double clicks the element. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @throws {CustomException} the customer error. - * - * - * */ async function doubleClickElement(page, locator) { try { return await page.locator(locator).dblclick() @@ -71,16 +35,6 @@ async function doubleClickElement(page, locator) { CustomException('Failed to double click the element', locator, exec) } } - -/** - * @summary The method clicks the element by dispatch event that is it directly dispatch the click event on the element. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @throws {CustomException} the customer error. - * - * - * */ async function clickElementByDispatchEvent(page, locator) { try { return await page.dispatchEvent(locator, 'click') @@ -88,16 +42,6 @@ async function clickElementByDispatchEvent(page, locator) { CustomException('Failed to click the element by dispatch event', locator, exec) } } - -/** - * @summary The method focus on the element. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @throws {CustomException} the customer error. - * - * - * */ async function focusOnElement(page, locator) { try { return await page.locator(locator).focus() @@ -120,17 +64,6 @@ async function getUserWithFunds(userType) { } } - -/** - * @summary The method clears the text tex box and then enters the provided input text. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {string} inputText the text to enter. - * @throws {CustomException} the customer error. - * - * - * */ async function clearAndInputText(page, locator, inputText) { try { let element = await page.locator(locator) @@ -141,16 +74,6 @@ async function clearAndInputText(page, locator, inputText) { } } -/** - * @summary The method enters the provided input text in the text box. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {string} inputText the text to enter. - * @throws {CustomException} the customer error. - * - * - * */ async function inputText(page, locator, inputText) { try { await page.locator(locator).fill(inputText) @@ -159,14 +82,6 @@ async function inputText(page, locator, inputText) { } } -/** - * @summary This method use fill and type to emulate real user interaction with delay - * @param page - * @param locator - * @param text - * @param delay - * @returns {Promise} - */ async function inputValueByType(page, locator, text, delay) { try { @@ -184,16 +99,6 @@ async function inputValueByType(page, locator, text, delay) { } } -/** - * @summary The method enters waits until the element is present. That is it checks if the element is attached to the DOM. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to to check if element is attached to the DOM. Optional parameter. - * @throws {CustomException} the customer error. - * - * - * */ async function waitForElementToBePresent(page, locator, timeout) { try { if (typeof (timeout) === 'undefined') { @@ -206,16 +111,6 @@ async function waitForElementToBePresent(page, locator, timeout) { } } -/** - * @summary The method waits until the element is not present. That is it checks if the element is detached from the DOM. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to to check if element is detached from the DOM. Optional parameter. - * @throws {CustomException} the customer error. - * - * - * */ async function waitForElementToBeNotPresent(page, locator, timeout) { try { if (typeof (timeout) === 'undefined') { @@ -227,17 +122,6 @@ async function waitForElementToBeNotPresent(page, locator, timeout) { CustomException('Element is present.', locator, exec) } } - -/** - * @summary The method enters waits until the element is visible. That is it checks if the element is visible in the DOM. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to to check if element is visible in the DOM. Optional parameter. - * @throws {CustomException} the customer error. - * - * - * */ async function waitForElementToBeVisible(page, locator, timeout) { try { if (typeof (timeout) === 'undefined') { @@ -249,17 +133,6 @@ async function waitForElementToBeVisible(page, locator, timeout) { CustomException('Element is not visible.', locator, exec) } } - -/** - * @summary The method enters waits until the element is visible. That is it checks if the element is hidden in the DOM. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to to check if element is hidden in the DOM. Optional parameter. - * @throws {CustomException} the customer error. - * - * - * */ async function waitForElementToBeHidden(page, locator, timeout) { try { if (typeof (timeout) === 'undefined') { @@ -271,29 +144,10 @@ async function waitForElementToBeHidden(page, locator, timeout) { CustomException('Element is not hidden.', locator, exec) } } - -/** - * @summary The method enters waits until the element is visible. That is it checks if the element is hidden in the DOM. - * - * @param {Page} page the page's object. - * @param {number} timeout the max amount of time to wait for in milliseconds. - * @throws {CustomException} the customer error. - * - * - * */ async function waitForTimeout(page, timeout) { await page.waitForTimeout(timeout) } -/** - * @summary The method waits for the load event to be fired - * - * @param {Page} page the page's object. - * @param {number} [timeout] the max amount of time to wait for in milliseconds. Optional parameter. - * @throws {CustomException} the customer error. - * - * - * */ async function waitForLoadState(page, timeout) { try { if (typeof (timeout) === 'undefined') { @@ -305,16 +159,6 @@ async function waitForLoadState(page, timeout) { CustomException('Error occurred while waiting for the load state: load', undefined, exec) } } - -/** - * @summary The method enters waits until there are no network connections for at least 500 ms. - * - * @param {Page} page the page's object. - * @param {number} [timeout] the max amount of time to wait for in milliseconds. Optional parameter. - * @throws {CustomException} the customer error. - * - * - * */ async function waitForNetworkIdleState(page, timeout) { try { if (typeof (timeout) === 'undefined') { @@ -326,16 +170,6 @@ async function waitForNetworkIdleState(page, timeout) { CustomException('Error occurred while waiting for the load state: networkidle', undefined, exec) } } - -/** - * @summary The method waits for the DOMContentLoaded event to be fired. - * - * @param {Page} page the page's object. - * @param {number} [timeout] the max amount of time to wait for in milliseconds. Optional parameter. - * @throws {CustomException} the customer error. - * - * - * */ async function waitForDomContentLoadedState(page, timeout) { try { if (typeof (timeout) === 'undefined') { @@ -347,16 +181,6 @@ async function waitForDomContentLoadedState(page, timeout) { CustomException('Error occurred while waiting for the load state: domcontentloaded', undefined, exec) } } - -/** - * @summary The method waits for network response to be received and when the document started loading. - * - * @param {Page} page the page's object. - * @param {number} [timeout] the max amount of time to wait for in milliseconds. Optional parameter. - * @throws {CustomException} the customer error. - * - * - * */ async function waitForCommitState(page, timeout) { try { if (typeof (timeout) === 'undefined') { @@ -368,17 +192,6 @@ async function waitForCommitState(page, timeout) { CustomException('Error occurred while waiting for the load state: domcontentloaded', undefined, exec) } } - -/** - * @summary The method gets the element's text. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @throws {CustomException} the customer error. - * @returns {string} the text of the element. - * - * - * */ async function getElementText(page, locator) { try { return await page.locator(locator).textContent() @@ -386,17 +199,6 @@ async function getElementText(page, locator) { CustomException('Failed to fetch element text.', locator, exec) } } - -/** - * @summary The method gets the element's inner text. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @throws {CustomException} the customer error. - * @returns {string} the inner text of the element. - * - * - * */ async function getElementInnerText(page, locator) { try { return await page.locator(locator).innerText() @@ -404,18 +206,6 @@ async function getElementInnerText(page, locator) { CustomException('Failed to fetch element inner-text.', locator, exec) } } - -/** - * @summary The method gets the element's attribute value. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {string} attributeName the attribute name whose value needs to be fetched. - * @throws {CustomException} the customer error. - * @returns {string} the value of the attribute. - * - * - * */ async function getElementAttributeValue(page, locator, attributeName) { try { return await page.locator(locator).getAttribute(attributeName) @@ -423,18 +213,6 @@ async function getElementAttributeValue(page, locator, attributeName) { CustomException('Failed to fetch attribute value for ' + attributeName, locator, exec) } } - - -/** - * @summary The method selects from the drop down by it's value. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {string} value the value in the drop down. - * @throws {CustomException} the customer error. - * - * - * */ async function selectFromDropDownByValue(page, locator, value) { try { return await page.locator(locator).selectOption({value: value}) @@ -442,17 +220,6 @@ async function selectFromDropDownByValue(page, locator, value) { CustomException('Failed to select from drop down by value, ' + value, locator, exec) } } - -/** - * @summary The method selects from the drop down by it's label. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {string} label the label in the drop down. - * @throws {CustomException} the customer error. - * - * - * */ async function selectFromDropDownByLabel(page, locator, label) { try { return await page.locator(locator).selectOption({label: label}) @@ -460,17 +227,6 @@ async function selectFromDropDownByLabel(page, locator, label) { CustomException('Failed to select from drop down by label, ' + label, locator, exec) } } - -/** - * @summary The method selects from the drop down by it's index. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} index the index to select in the drop down. - * @throws {CustomException} the customer error. - * - * - * */ async function selectFromDropDownByIndex(page, locator, index) { try { return await page.locator(locator).selectOption({index: index}) @@ -478,17 +234,6 @@ async function selectFromDropDownByIndex(page, locator, index) { CustomException('Failed to select from drop down by index, ' + index, locator, exec) } } - -/** - * @summary The method enters the text in the text box by using page class. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {string} text the text to enter. - * @throws {CustomException} the customer error. - * - * - * */ async function inputTextByPageFill(page, locator, text) { try { await page.fill(locator, text) @@ -496,18 +241,6 @@ async function inputTextByPageFill(page, locator, text) { CustomException('Failed to input text, ' + text, locator, exec) } } - -/** - * @summary The method checks if the actual and expected values are equal. If not equal, either the expect fails with the custom message passed or with the pre-defined message. - * - * @param {object} actualValue The actual value. - * @param {object} expectedValue The expected value. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * @param {string} [key] The key. Optional argument. - * - * - * - */ function expectValuesEqual(actualValue, expectedValue, customMessage, key) { if (customMessage === undefined) { if (key !== undefined) @@ -521,17 +254,6 @@ function expectValuesEqual(actualValue, expectedValue, customMessage, key) { expect(actualValue, '\n[Failure Message]: ' + customMessage + '\n').to.equal(expectedValue) } } - -/** - * @summary The method checks if the actual and expected values are not equal. If equal, either the expect fails with the custom message passed or with the pre-defined message. - * - * @param {object} actualValue The actual value. - * @param {object} expectedValue The expected value. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * @param {string} [key] The key. Optional argument. - * - * - */ function expectValuesNotEqual(actualValue, expectedValue, customMessage, key) { if (customMessage === undefined) { if (key !== undefined) @@ -545,16 +267,6 @@ function expectValuesNotEqual(actualValue, expectedValue, customMessage, key) { expect(actualValue, '\n[Failure Message]: ' + customMessage + '\n').to.not.equal(expectedValue) } } - -/** - * @summary The method checks if the value is True. If not, either the expect fails with the custom message passed or with the pre-defined message. - * - * @param {boolean} value The actual value to verify. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * @param {string} [key] The key. Optional argument. - * - * - */ function expectValueIsTrue(value, customMessage, key) { if (customMessage === undefined) { if (key !== undefined) @@ -568,16 +280,6 @@ function expectValueIsTrue(value, customMessage, key) { expect(value, '\n[Failure Message]: ' + customMessage + '\n').to.be.true; } } - -/** - * @summary The method checks if the value is False. If not, either the expect fails with the custom message passed or with the pre-defined message. - * - * @param {boolean} value The actual value to verify. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * @param {string} [key] The key. Optional argument. - * - * - */ function expectValueIsFalse(value, customMessage, key) { if (customMessage === undefined) { if (key !== undefined) @@ -591,16 +293,6 @@ function expectValueIsFalse(value, customMessage, key) { expect(value, '\n[Failure Message]: ' + customMessage + '\n').to.be.false; } } - -/** - * @summary The method checks if the value is Null. If not, either the expect fails with the custom message passed or with the pre-defined message. - * - * @param {object} value The actual value to verify. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * @param {string} [key] The key. Optional argument. - * - * - */ function expectValueIsNull(value, customMessage, key) { if (customMessage === undefined) { if (key !== undefined) @@ -614,16 +306,6 @@ function expectValueIsNull(value, customMessage, key) { expect(value, '\n[Failure Message]: ' + customMessage + '\n').to.be.null; } } - -/** - * @summary The method checks if the value is not Null. If not, either the expect fails with the custom message passed or with the pre-defined message. - * - * @param {object} value The actual value to verify. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * @param {string} [key] The key. Optional argument. - * - * - */ function expectValueIsNotNull(value, customMessage, key) { if (customMessage === undefined) { if (key !== undefined) @@ -637,16 +319,6 @@ function expectValueIsNotNull(value, customMessage, key) { expect(value, '\n[Failure Message]: ' + customMessage + '\n').to.not.be.null; } } - -/** - * @summary The method checks if the value is undefined. If not, either the expect fails with the custom message passed or with the pre-defined message. - * - * @param {object} value The actual value to verify. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * @param {string} [key] The key. Optional argument. - * - * - */ function expectValueIsUndefined(value, customMessage, key) { if (customMessage === undefined) { if (key !== undefined) @@ -660,16 +332,6 @@ function expectValueIsUndefined(value, customMessage, key) { expect(value, '\n[Failure Message]: ' + customMessage + '\n').to.be.undefined; } } - -/** - * @summary The method checks if the value is empty. If not, either the expect fails with the custom message passed or with the pre-defined message. - * - * @param {object} value The actual value to verify. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * @param {string} [key] The key. Optional argument. - * - * - */ function expectValueIsEmpty(value, customMessage, key) { if (customMessage === undefined) { if (key !== undefined) @@ -683,16 +345,6 @@ function expectValueIsEmpty(value, customMessage, key) { expect(value, '\n[Failure Message]: ' + customMessage + '\n').to.be.empty; } } - -/** - * @summary The method checks if the value is not empty. If not, either the expect fails with the custom message passed or with the pre-defined message. - * - * @param {object} value The actual value to verify. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * @param {string} [key] The key. Optional argument. - * - * - */ function expectValueIsNotEmpty(value, customMessage, key) { if (customMessage === undefined) { if (key !== undefined) @@ -706,16 +358,6 @@ function expectValueIsNotEmpty(value, customMessage, key) { expect(value, '\n[Failure Message]: ' + customMessage + '\n').not.empty; } } - -/** - * @summary The method checks if the field contain a string. If not, either the expect fails with the custom message passed or with the pre-defined message. - * - * @param {string} string The field whose contains operation needs to be performed. - * @param {string} stringToCheck The string to check if it is present in the field value. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * - * - */ function expectStringContains(string, stringToCheck, customMessage) { if (customMessage === undefined) { expect(string, '\n[Failure Message]: ' + string + ' does not contain string ' + stringToCheck + '\n').to.have.string(stringToCheck); @@ -723,18 +365,6 @@ function expectStringContains(string, stringToCheck, customMessage) { expect(string, '\n[Failure Message]: ' + customMessage + '\n').to.have.string(stringToCheck); } } - -/** - * @summary The method checks if the field's value is within start and finish value. If not, either the expect fails with the custom message passed or with the pre-defined message. - * - * @param {object} actualValue The actual value. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * @param {number} start The start value. - * @param {number} finish The finish value. - * @param {string} [key] The key. Optional argument. - * - * - */ function expectValueIsWithin(actualValue, start, finish, customMessage, key) { if (customMessage === undefined) { if (key !== undefined) @@ -748,17 +378,6 @@ function expectValueIsWithin(actualValue, start, finish, customMessage, key) { expect(actualValue, '\n[Failure Message]: ' + customMessage + '\n').to.be.within(start, finish); } } - -/** - * @summary The method checks if the actual and expected array values are equal. If not equal, either the expect fails with the custom message passed or with the pre-defined message. - * - * @param {Array} actualArray The actual array. - * @param {Array} expectedArray The expected array. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * @param {string} [key] The key. Optional argument. - * - * - */ function expectArraysEqual(actualArray, expectedArray, customMessage, key) { if (customMessage === undefined) { if (key !== undefined) @@ -773,28 +392,10 @@ function expectArraysEqual(actualArray, expectedArray, customMessage, key) { } } - -/** - * @summary The method checks performs a expect failure with the message supplied. - * - * @param {string} failureMessage The custom message to be displayed on failure. - * - * - */ function expectFail(failureMessage) { expect.fail(failureMessage) } - -/** - * @summary The method checks if the object includes the value. - * - * @param objectToSearchIn The object to search the value in. - * @param valueToSearch The value to search. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * - * - */ function expectIncludes(objectToSearchIn, valueToSearch, customMessage) { if (customMessage === undefined) { expect(objectToSearchIn, '\n[Failure Message]: ' + objectToSearchIn + ' does not includes value ' + valueToSearch + '\n').to.include(valueToSearch) @@ -803,88 +404,34 @@ function expectIncludes(objectToSearchIn, valueToSearch, customMessage) { } } -/** - * @summary The method logs warning message with a specific color. - * - * @param {string} message the message. - * - * - * */ function logWarning(message) { if (message) console.warn("[WARN]: ".gray + message.brightYellow); } -/** - * @summary The method logs error message with a specific color. - * - * @param {string} message the message. - * - * - * */ function logError(message) { if (message) console.error("[ERROR]: ".gray + message.brightRed); } -/** - * @summary The method logs info message with a specific color. - * - * @param {string} message the message. - * - * - * */ + function logInfo(message) { if (message) console.info("[INFO]: ".gray + message.cyan); } - -/** - * @summary The method logs success message with a specific color. - * - * @param {string} message the message. - * - * - * */ function logSuccess(message) { if (message) console.info("[SUCCESS]: ".gray + message.green); } - -/** - * @summary The method logs debug message with a specific color. - * - * @param {string} message the message. - * - * - * */ function logDebug(message) { if (message) console.debug("[DEBUG]: ".gray + message.yellow); } - -/** - * @summary The method prints a message. - * - * @param {string} message the message. - * - * - * */ function logMessage(message) { if (message) console.info("[MESSAGE]: ".blue.bold + message.blue.bold); } -/** - * @summary The method throws an custom error. - * - * @param {string} failureMessage the custom failure message to be thrown. - * @param {string} locator the element locator. - * @param {Object} exception. - * @throws {Error} the custom error details. - * - * - * */ function CustomException(failureMessage, locator, exception) { if (typeof locator !== 'undefined') throw new Error(('\n[Failure Message]: ' + failureMessage + '\n[Locator]: ' + locator + '\n[Details]: ' + exception).brightRed) @@ -892,15 +439,6 @@ function CustomException(failureMessage, locator, exception) { throw new Error(('\n[Failure Message]: ' + failureMessage + '\n[Details]: ' + exception).brightRed) } -/** - * @summary The method return the list of element. It uses locator class to find the elements. - * - * @param {Page} page the page object. - * @param {string} locator the element locator. - * @throws {CustomException} the customer error. - * - * - * */ async function getListOfElements(page, locator) { try { return await page.locator(locator) @@ -908,16 +446,6 @@ async function getListOfElements(page, locator) { CustomException('Failed to get the elements list.', locator, exec) } } - -/** - * @summary The method verifies if the element is enabled. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @throws {CustomException} the customer error. - * - * - * */ async function verifyElementEnabled(page, locator) { try { expectValueIsTrue(await page.locator(locator).isEnabled(), 'Element is not enabled.') @@ -925,17 +453,6 @@ async function verifyElementEnabled(page, locator) { CustomException('Element is not enabled.', locator, exec) } } - -/** - * @summary The method finds the element and returns the object of ElementHandle. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @returns {elementHandle} the element handle object. - * @throws {CustomException} the customer error. - * - * - * */ async function getElementHandle(page, locator) { try { return await page.$(locator) @@ -943,17 +460,6 @@ async function getElementHandle(page, locator) { CustomException('Failed to get the element', locator, exec) } } - -/** - * @summary The method finds the list of elements and returns the object of ElementHandles. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @returns {elementHandle} the list of element handle object. - * @throws {CustomException} the customer error. - * - * - * */ async function getElementHandles(page, locator) { try { return await page.$$(locator) @@ -961,16 +467,6 @@ async function getElementHandles(page, locator) { CustomException('Failed to get the elements list', locator, exec) } } - -/** - * @summary The method clicks the element by using ElementHandle class. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @throws {CustomException} the customer error. - * - * - * */ async function clickElementByElementHandle(page, locator) { try { let elementHandle = await getElementHandle(page, locator) @@ -980,15 +476,6 @@ async function clickElementByElementHandle(page, locator) { CustomException('Failed to click element by ElementHandle', locator, exec) } } - -/** - * @summary The method performs a page refresh - * - * @param {Page} page the page's object. - * @throws {CustomException} the customer error. - * - * - * */ async function refreshPage(page) { try { return await page.reload() @@ -996,12 +483,7 @@ async function refreshPage(page) { CustomException('Failed refresh the page', undefined, exec) } } - -/** - * @summary The method generates random email for testing purpose - * - * */ -async function generateRandomEmail() { +async function generateRandomText() { const length = 6 let result = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; @@ -1009,17 +491,9 @@ async function generateRandomEmail() { for (let i = 0; i < length; i++) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } - return "test" + result + "@testemail.com" + return "e2e_Post_Test_" + result + "test" } -/** - * - * @summary The method ticks(checks) checkbox element - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * - * - * */ async function tickCheckBox(page, locator) { try { await page.check(locator) @@ -1028,38 +502,16 @@ async function tickCheckBox(page, locator) { } } -/** - * @summary The method generates random number - * @param {number} length of the number - * - * */ + async function generateRandomNumber(length) { return Math.floor(Math.pow(10, length - 1) + Math.random() * 9 * Math.pow(10, length - 1)); } - -/** - * @summary The method navigates to the given url. - * @param {Page} page the page's object. - * @param {string} url the url to navigate to. - * @param {string} [path] the path to append to the url. - * @return {Promise} - * - * - */ async function navigateTo(page, url, path) { if ((typeof path) === 'undefined') await page.goto(url) else await page.goto(url + path) } - -/** - * @summary The method checks if the given number starts with 0 and updates it to a non zero starting number. - * @param {string} number the number - * @return {string} the number that does not start with a zero. - * - * - */ function checkIfNumberStartsWithZeroAndGetANewOne(number) { if (number.startsWith('0')) { logWarning('Phone number, ' + number + ', starts with 0. Getting a new one') @@ -1068,13 +520,6 @@ function checkIfNumberStartsWithZeroAndGetANewOne(number) { return number } -/** - * @summary The methods generates random alpha string for the given length - * @param {number} length the length. - * @return {string} random alpha string of given length. - * - * - */ function randAlphaString(length) { let ans = ''; let arr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; @@ -1084,13 +529,6 @@ function randAlphaString(length) { return ans; } -/** - * @summary The methods generates random number string for the given length - * @param {number} length the length. - * @return {string} random number string of given length. - * - * - */ function randNumberString(length) { let result = ''; let numbers = '0123456789'; @@ -1101,35 +539,16 @@ function randNumberString(length) { return result; } -/** - * @summary This function is used to press Enter Key - * @returns {Promise} - */ async function pressEnter() { await page.keyboard.down('Enter') await page.keyboard.up('Enter') } -/** - * @summary The method generates random number between min and max value - * @param {number} min value - * @param {number} max value - * */ async function generateRandomNumberBetween(min, max) { return Math.floor((Math.random() * max) + 1); } -/** - * @summary The method checks if the element is visible. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to to check if element is visible. Optional parameter. - * @throws {CustomException} the customer error. - * @returns {Promise} - * - * - * */ + async function isElementVisible(page, locator, timeout) { try { if (typeof (timeout) === 'undefined') { @@ -1141,103 +560,22 @@ async function isElementVisible(page, locator, timeout) { CustomException('Error occurred while checking if element is not visible.', locator, exec) } } - -/** - * @summary The method gets the input value for the selected input or textarea or select element. More details: https://playwright.dev/docs/api/class-locator#locator-input-value - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @throws {CustomException} the customer error. - * @returns {Promise} the input value from the input or textarea or select element. - * - * - * */ async function getInputValue(page, locator) { return await page.locator(locator).inputValue() } -/** - * @summary The method removes non numeric characters from the string. - * @returns {string} the string that contains only numbers. - * - * - */ function removeNonNumericCharacter(string) { return string.replace(/\D/g, ''); } -/** - * @summary The method formats the date to given format. - * @param {Date} dateToFormat the date to format. - * @param {string} dateFormat the date format. - * @returns {string} the formatted date. - * - * - */ function formatDate(dateToFormat, dateFormat) { return moment(dateToFormat).format(dateFormat) } -/** - * @summary The method gets the Country code based on the environment. - * - * @return {string} country code. - * - * - * */ -function getCountryCodeBasedOnEnv() { - let countryCode = '' - if (env.toLowerCase().includes('nigeria')) - countryCode = config.countryCodes.nigeria - else if (env.toLowerCase().includes('kenya')) - countryCode = config.countryCodes.kenya - else if (env.toLowerCase().includes('ghana')) - countryCode = config.countryCodes.ghana - else if (env.toLowerCase().includes('ethiopia')) - countryCode = config.countryCodes.ethiopia - return countryCode -} - - -/** - * @summary The method gets the Country dial prefix based on the environment. - * - * @return {string} dial prefix - * - * - * */ -function getCountryDialPrefixBasedOnEnv() { - let dialPrefix = '' - if (env.toLowerCase().includes('nigeria')) - dialPrefix = config.countryDialPrefix.nigeria - else if (env.toLowerCase().includes('kenya')) - dialPrefix = config.countryDialPrefix.kenya - else if (env.toLowerCase().includes('ghana')) - dialPrefix = config.countryDialPrefix.ghana - else if (env.toLowerCase().includes('ethiopia')) - dialPrefix = config.countryDialPrefix.ethiopia - return dialPrefix -} - -/** - * @summary The method will sleep(stop test execution) for time given in milliseconds - * @param {number} timeout in milliseconds - * - */ async function sleep(timeout) { const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) await sleep(timeout); } - -/** - * @summary The method checks if the actual and expected values are equal. If not equal, either the expect fails with the custom message passed or with the pre-defined message. - * - * @param {(number,Date)} actualValue The actual value. - * @param {(number,Date)} expectedValue The expected value. - * @param {string} [customMessage] The custom message to be displayed on failure. Optional argument. - * - * - */ function expectValueToBeAbove(actualValue, expectedValue, customMessage) { if (customMessage === undefined) { expect(actualValue, '\n[Failure Message]: Actual and expected values are not equal.\nActual value: ' + actualValue + '\nExpected value: ' + expectedValue + '\n').to.be.above(expectedValue) @@ -1245,15 +583,6 @@ function expectValueToBeAbove(actualValue, expectedValue, customMessage) { expect(actualValue, '\n[Failure Message]: ' + customMessage + '\n').to.equal(expectedValue) } } - -/** - * @summary The method gets the element from Iframe. - * - * @param {Page} page the page's object. - * @param {string} frameLocator the element locator. - * @param {string} iLocator the element locator. - * - */ async function getIFrameElement(page, frameLocator, iLocator) { try { const fLocator = await page.frameLocator(frameLocator); @@ -1262,16 +591,6 @@ async function getIFrameElement(page, frameLocator, iLocator) { CustomException('Failed to find locator', framelocator, iLocator, exec) } } - -/** - * @summary The method gets the element from Iframe and runs defined action. await helpers.iframeAction(page,frameLocator,iLocator,'type',text); - * - * @param {Page} page the page's object. - * @param {string} frameLocator the iframe locator. - * @param {string} iLocator locator inside the iframe. - * @param {Array} ...args Array of elements action || action, text - * - * */ async function iframeAction(page, frameLocator, iLocator, ...args) { try { const fLocator = await page.frameLocator(frameLocator); @@ -1288,38 +607,6 @@ async function iframeAction(page, frameLocator, iLocator, ...args) { } } - -/** - * @summary The method return name of the country from env. - * - * - */ -function getCountryName() { - let countryName = '' - if (env.toLowerCase().includes('nigeria')) - countryName = "nigeria" - else if (env.toLowerCase().includes('kenya')) - countryName = "kenya" - else if (env.toLowerCase().includes('ghana')) - countryName = "ghana" - else if (env.toLowerCase().includes('ethiopia')) - countryName = "ethiopia" - return countryName -} - - - -/** - * @summary The method checks if the element is disabled. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to to check if element is disabled. Optional parameter. - * @throws {CustomException} the customer error. - * @returns {Promise} - * - * - * */ async function isElementDisabled(page, locator, timeout) { try { if (typeof (timeout) === 'undefined') { @@ -1331,34 +618,10 @@ async function isElementDisabled(page, locator, timeout) { CustomException('Error occurred while checking if element is disabled.', locator, exec) } } - -/** - * @summary The method verifies/asserts the element is disabled - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to to check if element is disabled. Optional parameter. - * @throws {CustomException} the customer error. - * @returns {Promise} - * - * - * */ async function verifyElementIsDisabled(page, locator, timeout) { if (!await isElementDisabled(page, locator, timeout)) expectFail('[Failure Message]: The element is not disabled.\n[Expected value]: The element should be disabled.\n[Locator]: ' + locator) } - -/** - * @summary The method checks if the element is checked. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to to check if element is disabled. Optional parameter. - * @throws {CustomException} the customer error. - * @returns {Promise} - * - * - * */ async function isElementChecked(page, locator, timeout) { try { if (typeof (timeout) === 'undefined') { @@ -1371,50 +634,16 @@ async function isElementChecked(page, locator, timeout) { } } -/** - * @summary The method verifies/asserts the element is checked. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to to check if element is checked. Optional parameter. - * @throws {CustomException} the customer error. - * @returns {Promise} - * - * - * */ async function verifyElementIsChecked(page, locator, timeout) { if (!await isElementChecked(page, locator, timeout)) expectFail('[Failure Message]: The element is not checked.\n[Expected value]: Element should be checked.\n[Locator]: ' + locator) } -/** - * @summary The method verifies/asserts the element is disabled. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to to check if element is disabled. Optional parameter. - * @throws {CustomException} the customer error. - * @returns {Promise} - * - * - * */ async function verifyElementIsUnChecked(page, locator, timeout) { if (await isElementChecked(page, locator, timeout)) expectFail('[Failure Message]: The element is checked.\n[Expected value]: Element should not be checked.\n[Locator]: ' + locator) } -/** - * @description The method checks a radio button or a checkbox. This method can be used with input[type=checkbox], input[type=radio], - * [role=checkbox] or label associated with checkbox or radio button. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to to check if element is disabled. Optional parameter. - * @throws {CustomException} the customer error. - * @returns {Promise} - * - * - * */ async function checkRadioOrCheckbox(page, locator, timeout) { try { if (typeof (timeout) === 'undefined') { @@ -1427,18 +656,6 @@ async function checkRadioOrCheckbox(page, locator, timeout) { } } -/** - * @description The method checks a radio button or a checkbox. This method can be used with input[type=checkbox], input[type=radio], - * [role=checkbox] or label associated with checkbox or radio button. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to to check if element is disabled. Optional parameter. - * @throws {CustomException} the customer error. - * @returns {Promise} - * - * - * */ async function uncheckRadioOrCheckbox(page, locator, timeout) { try { if (typeof (timeout) === 'undefined') { @@ -1451,50 +668,17 @@ async function uncheckRadioOrCheckbox(page, locator, timeout) { } } -/** - * @description The method function converts the string array to float array - * - * @param {array} stringArray - * - * - * */ function convertStringArrayToFloatArray(stringArray) { return stringArray.map(Number) } -/** - * @description The method will get max value from number array - * - * @param {array} - * - * - * */ function getMaxValueFromNumberArray(array) { return Math.max.apply(Math, array) } - -/** - * @description The method will get min value from number array - * - * @param {array} - * - * - * */ function getMinValueFromNumberArray(array) { return Math.min.apply(Math, array) } - -/** - * @description The method gets all the attribute names of the element as an Array of strings. - * If the element has no attributes it returns an empty array. - * - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @throws {CustomException} the customer error. - * - * - * */ async function getElementAttributeNames(page, locator) { try { let element = await page.locator(locator) @@ -1504,26 +688,10 @@ async function getElementAttributeNames(page, locator) { } } -/** - * @summary The method checks if typeof key is undefined. And returns boolean value - * @param key the key to check for undefined. - * @return {boolean} true is undefined else false. - * - * - */ function isKeyUndefined(key) { return typeof (key) === 'undefined' } -/** - * @summary The method gets the locator object. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @throws {CustomException} the customer error. - * @return {Promise<*>} - * - * - */ async function getElementLocator(page, locator) { try { return await page.locator(locator) @@ -1531,17 +699,6 @@ async function getElementLocator(page, locator) { CustomException('Error occurred while getting the element locator.', locator, exec) } } - -/** - * @summary The method uses playwright expect and asserts the element is checked or unchecked. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is checked. Optional parameter. - * @param {boolean} [shouldBeChecked] if value undefined or not passed by default method asserts element is checked. If value is false, then method asserts element is unchecked. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeChecked(page, locator, timeout, shouldBeChecked) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout) && (isKeyUndefined(shouldBeChecked) || shouldBeChecked === true)) { @@ -1558,20 +715,6 @@ async function expectElementToBeChecked(page, locator, timeout, shouldBeChecked) } } -/** - * @description The method uses playwright expect and asserts the element is disabled. - *
- *     a. Element is disabled if it has "disabled" attribute or is disabled via 'aria-disabled'.
- *     b. Only native control elements such as HTML button, input, select, textarea, option, optgroup can be disabled by setting "disabled" attribute.
- *     c. "disabled" attribute on other elements is ignored by the browser.
- * 
- * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is disabled. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeDisabled(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1580,20 +723,6 @@ async function expectElementToBeDisabled(page, locator, timeout) { await pwExpect(elementLocator, '[Failure Message]: Element is not disabled.\n[Expected]: Element should be disabled.').toBeDisabled({timeout: timeout}) } -/** - * @description The method uses playwright expect and asserts the element is not disabled. - *
- *     a. Element is disabled if it has "disabled" attribute or is disabled via 'aria-disabled'.
- *     b. Only native control elements such as HTML button, input, select, textarea, option, optgroup can be disabled by setting "disabled" attribute.
- *     c. "disabled" attribute on other elements is ignored by the browser.
- * 
- * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is disabled. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeNotDisabled(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1602,15 +731,6 @@ async function expectElementToBeNotDisabled(page, locator, timeout) { await pwExpect(elementLocator, '[Failure Message]: Element is disabled.\n[Expected]: Element should not be disabled.').not.toBeDisabled({timeout: timeout}) } -/** - * @summary The method uses playwright expect and asserts the element is editable. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is editable. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeEditable(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1618,16 +738,6 @@ async function expectElementToBeEditable(page, locator, timeout) { else await pwExpect(elementLocator, '[Failure Message]: Element is not editable.\n[Expected]: Element should be editable.').toBeEditable({timeout: timeout}) } - -/** - * @summary The method uses playwright expect and asserts the element is not editable. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is editable. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeNotEditable(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1636,15 +746,6 @@ async function expectElementToBeNotEditable(page, locator, timeout) { await pwExpect(elementLocator, '[Failure Message]: Element is editable.\n[Expected]: Element should be not editable.').not.toBeEditable({timeout: timeout}) } -/** - * @description The method uses playwright expect and asserts the element is empty. That is it ensures the locator points to an empty editable element or to a DOM node that has no text. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is empty. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeEmpty(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1653,15 +754,6 @@ async function expectElementToBeEmpty(page, locator, timeout) { await pwExpect(elementLocator, '[Failure Message]: Element is not empty.\n[Expected]: Element should be empty.').toBeEmpty({timeout: timeout}) } -/** - * @description The method uses playwright expect and asserts the element is not empty. That is it ensures the locator points to an empty editable element or to a DOM node that has text. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is not empty. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeNotEmpty(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1670,15 +762,6 @@ async function expectElementToBeNotEmpty(page, locator, timeout) { await pwExpect(elementLocator, '[Failure Message]: Element is empty.\n[Expected]: Element should not be empty.').not.toBeEmpty({timeout: timeout}) } -/** - * @description The method uses playwright expect and asserts the element is enabled. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is enabled. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeEnabled(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1686,16 +769,6 @@ async function expectElementToBeEnabled(page, locator, timeout) { else await pwExpect(elementLocator, '[Failure Message]: Element is not enabled.\n[Expected]: Element should be enabled.').toBeEnabled({timeout: timeout}) } - -/** - * @description The method uses playwright expect and asserts the element is not enabled. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is not enabled. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeNotEnabled(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1703,16 +776,6 @@ async function expectElementToBeNotEnabled(page, locator, timeout) { else await pwExpect(elementLocator, '[Failure Message]: Element is enabled.\n[Expected]: Element should not be enabled.').not.toBeEnabled({timeout: timeout}) } - -/** - * @description The method uses playwright expect and asserts the element is focused. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is focused. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeFocused(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1720,16 +783,6 @@ async function expectElementToBeFocused(page, locator, timeout) { else await pwExpect(elementLocator, '[Failure Message]: Element is not focused.\n[Expected]: Element should be focused.').toBeFocused({timeout: timeout}) } - -/** - * @description The method uses playwright expect and asserts the element is not focused. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is not focused. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeNotFocused(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1737,16 +790,6 @@ async function expectElementToBeNotFocused(page, locator, timeout) { else await pwExpect(elementLocator, '[Failure Message]: Element is focused.\n[Expected]: Element should not be focused.').not.toBeFocused({timeout: timeout}) } - -/** - * @description The method uses playwright expect and asserts the element is hidden. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is hidden. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeHidden(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1754,16 +797,6 @@ async function expectElementToBeHidden(page, locator, timeout) { else await pwExpect(elementLocator, '[Failure Message]: Element is not hidden.\n[Expected]: Element should be hidden.').toBeHidden({timeout: timeout}) } - -/** - * @description The method uses playwright expect and asserts the element is not hidden. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is not hidden. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeNotHidden(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1771,16 +804,6 @@ async function expectElementToBeNotHidden(page, locator, timeout) { else await pwExpect(elementLocator, '[Failure Message]: Element is hidden.\n[Expected]: Element should not be hidden.').not.toBeHidden({timeout: timeout}) } - -/** - * @description The method uses playwright expect and asserts the element is visible. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is visible. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeVisible(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1788,16 +811,6 @@ async function expectElementToBeVisible(page, locator, timeout) { else await pwExpect(elementLocator, '[Failure Message]: Element is not visible.\n[Expected]: Element should be visible.').toBeVisible({timeout: timeout}) } - -/** - * @description The method uses playwright expect and asserts the element is not visible. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element is not visible. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToBeNotVisible(page, locator, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1805,18 +818,6 @@ async function expectElementToBeNotVisible(page, locator, timeout) { else await pwExpect(elementLocator, '[Failure Message]: Element is visible.\n[Expected]: Element should not be visible.').not.toBeVisible({timeout: timeout}) } - -/** - * @summary The method uses playwright expect and asserts the element contains the text. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element contains the text. Optional parameter. - * @param {string, Array, RegExp} expected the expected substring or regex or list of those. - * @param {boolean} [shouldUseInnerText] whether to use element.innerText instead of element.textContent when retrieving DOM node text. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToContainText(page, locator, expected, timeout, shouldUseInnerText) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(shouldUseInnerText)) @@ -1840,18 +841,6 @@ async function expectElementToContainText(page, locator, expected, timeout, shou }) } } - -/** - * @summary The method uses playwright expect and asserts the element does not contains the text. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element does not contains the text. Optional parameter. - * @param {string, Array, RegExp} expected the expected substring or regex or list of those. - * @param {boolean} [shouldUseInnerText] whether to use element.innerText instead of element.textContent when retrieving DOM node text. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToNotContainText(page, locator, expected, timeout, shouldUseInnerText) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(shouldUseInnerText)) @@ -1875,18 +864,6 @@ async function expectElementToNotContainText(page, locator, expected, timeout, s }) } } - -/** - * @summary The method uses playwright expect and asserts the element attribute key has the value. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element has attribute. Optional parameter. - * @param {string} attributeKey the attribute key. - * @param {string, RegExp} attributeValue the expected attribute value. - * @return {Promise} - * - * - */ async function expectElementToHaveAttribute(page, locator, attributeKey, attributeValue, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1894,17 +871,6 @@ async function expectElementToHaveAttribute(page, locator, attributeKey, attribu else await pwExpect(elementLocator, '[Failure Message]: Element attribute, ' + attributeKey + ', does not have value:' + attributeValue + '\n[Expected]: Element attribute, ' + attributeKey + ', should have value:' + attributeValue).toHaveAttribute(attributeKey, attributeValue, {timeout: timeout}) } - -/** - * @summary The method uses playwright expect and asserts the element has the exact number of DOM nodes. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element has count. Optional parameter. - * @param {number} expectedCount the expected count. - * @return {Promise} - * - * - */ async function expectElementToHaveCount(page, locator, expectedCount, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1912,17 +878,6 @@ async function expectElementToHaveCount(page, locator, expectedCount, timeout) { else await pwExpect(elementLocator, '[Failure Message]: Element does not have count: ' + expectedCount + '\n[Expected]: Element should have count: ' + expectedCount).toHaveCount(expectedCount, {timeout: timeout}) } - -/** - * @summary The method uses playwright expect and asserts the element does not have the exact number of DOM nodes. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element does not have the count. Optional parameter. - * @param {number} expectedCount the expected count. - * @return {Promise} - * - * - */ async function expectElementToNotHaveCount(page, locator, expectedCount, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1930,18 +885,6 @@ async function expectElementToNotHaveCount(page, locator, expectedCount, timeout else await pwExpect(elementLocator, '[Failure Message]: Element has count: ' + expectedCount + '\n[Expected]: Element should not have count: ' + expectedCount).not.toHaveCount(expectedCount, {timeout: timeout}) } - -/** - * @summary The method uses playwright expect and asserts the element has css. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element has css. Optional parameter. - * @param {string} cssPropertyKey the css property key. - * @param {string, RegExp} cssPropertyValue the css property value. - * @return {Promise} - * - * - */ async function expectElementToHaveCSS(page, locator, cssPropertyKey, cssPropertyValue, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1949,19 +892,6 @@ async function expectElementToHaveCSS(page, locator, cssPropertyKey, cssProperty else await pwExpect(elementLocator, '[Failure Message]: Element CSS property, ' + cssPropertyKey + ', does not have value:' + cssPropertyValue + '\n[Expected]: Element CSS property, ' + cssPropertyKey + ', should have value:' + cssPropertyValue).toHaveCSS(cssPropertyKey, cssPropertyValue, {timeout: timeout}) } - -/** - * @description The method uses playwright expect and asserts the element does not have css. - * Ensures the locator resolves to an element with the given computed CSS style. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element does not have css. Optional parameter. - * @param {string} cssPropertyKey the css property key. - * @param {string, RegExp} cssPropertyValue the css property value. - * @return {Promise} - * - * - */ async function expectElementToNotHaveCSS(page, locator, cssPropertyKey, cssPropertyValue, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1969,19 +899,6 @@ async function expectElementToNotHaveCSS(page, locator, cssPropertyKey, cssPrope else await pwExpect(elementLocator, '[Failure Message]: Element CSS property, ' + cssPropertyKey + ', has value:' + cssPropertyValue + '\n[Expected]: Element CSS property, ' + cssPropertyKey + ', should have value:' + cssPropertyValue).not.toHaveCSS(cssPropertyKey, cssPropertyValue, {timeout: timeout}) } - -/** - * @description The method uses playwright expect and asserts the element has js property.Ensures the Locator points to an element with given JavaScript property. - * Note that this property can be of a primitive type as well as a plain serializable JavaScript object. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element has js property. Optional parameter. - * @param {string} propertyKey the js property key. - * @param {string, RegExp} propertyValue the property value. - * @return {Promise} - * - * - */ async function expectElementToHaveJSProperty(page, locator, propertyKey, propertyValue, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -1990,18 +907,6 @@ async function expectElementToHaveJSProperty(page, locator, propertyKey, propert await pwExpect(elementLocator, '[Failure Message]: Element JS property, ' + propertyKey + ', does not have value:' + propertyValue + '\n[Expected]: Element JS property, ' + propertyKey + ', should have value:' + propertyValue).toHaveJSProperty(propertyKey, propertyValue, {timeout: timeout}) } -/** - * @description The method uses playwright expect and asserts the element does not have js property.Ensures the Locator points to an element with given JavaScript property. - * Note that this property can be of a primitive type as well as a plain serializable JavaScript object. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element does not js property. Optional parameter. - * @param {string} propertyKey the js property key. - * @param {string, RegExp} propertyValue the property value. - * @return {Promise} - * - * - */ async function expectElementToNotHaveJSProperty(page, locator, propertyKey, propertyValue, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -2009,18 +914,6 @@ async function expectElementToNotHaveJSProperty(page, locator, propertyKey, prop else await pwExpect(elementLocator, '[Failure Message]: Element JS property, ' + propertyKey + ', has value:' + propertyValue + '\n[Expected]: Element JS property, ' + propertyKey + ', should not have value:' + propertyValue).not.toHaveJSProperty(propertyKey, propertyValue, {timeout: timeout}) } - -/** - * @summary The method uses playwright expect and asserts the element has the text. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element has the text. Optional parameter. - * @param {string, Array, RegExp} expected the expected substring or regex or list of those. - * @param {boolean} [shouldUseInnerText] whether to use element.innerText instead of element.textContent when retrieving DOM node text. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToHaveText(page, locator, expected, timeout, shouldUseInnerText) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(shouldUseInnerText)) @@ -2044,18 +937,6 @@ async function expectElementToHaveText(page, locator, expected, timeout, shouldU }) } } - -/** - * @summary The method uses playwright expect and asserts the element does not have the text. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element does not have the text. Optional parameter. - * @param {string, Array, RegExp} expected the expected substring or regex or list of those. - * @param {boolean} [shouldUseInnerText] whether to use element.innerText instead of element.textContent when retrieving DOM node text. Optional parameter. - * @return {Promise} - * - * - */ async function expectElementToNotHaveText(page, locator, expected, timeout, shouldUseInnerText) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(shouldUseInnerText)) @@ -2079,17 +960,6 @@ async function expectElementToNotHaveText(page, locator, expected, timeout, shou }) } } - -/** - * @summary The method uses playwright expect and asserts the element has the given input value.. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element has the value. Optional parameter. - * @param {string, Array, RegExp} expected the expected substring or regex or list of those. - * @return {Promise} - * - * - */ async function expectElementToHaveValue(page, locator, expected, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -2097,17 +967,6 @@ async function expectElementToHaveValue(page, locator, expected, timeout) { else await pwExpect(elementLocator, '[Failure Message]: Element does not have value: ' + expected + '\n[Expected]: Element should have value: ' + expected).toHaveValue(expected, {timeout: timeout}) } - -/** - * @summary The method uses playwright expect and asserts the element does not have the given input value.. - * @param {Page} page the page's object. - * @param {string} locator the element locator. - * @param {number} [timeout] the max amount of time to assert element does not the value. Optional parameter. - * @param {string, Array, RegExp} expected the expected substring or regex or list of those. - * @return {Promise} - * - * - */ async function expectElementToNotHaveValue(page, locator, expected, timeout) { let elementLocator = await getElementLocator(page, locator) if (isKeyUndefined(timeout)) @@ -2115,32 +974,12 @@ async function expectElementToNotHaveValue(page, locator, expected, timeout) { else await pwExpect(elementLocator, '[Failure Message]: Element has value: ' + expected + '\n[Expected]: Element should not have value: ' + expected).not.toHaveValue(expected, {timeout: timeout}) } - -/** - * @summary The method uses playwright expect and asserts the page has the given title. - * @param {Page} page the page's object. - * @param {number} [timeout] the max amount of time to assert page has title. Optional parameter. - * @param {string, RegExp} titleOrRegExp the expected title. - * @return {Promise} - * - * - */ async function expectPageHasTitle(page, titleOrRegExp, timeout) { if (isKeyUndefined(timeout)) await pwExpect(page, '[Failure Message]: Page does not have title: ' + titleOrRegExp + '\n[Expected]: Page should have title: ' + titleOrRegExp).toHaveTitle(titleOrRegExp) else await pwExpect(page, '[Failure Message]: Page does not have title: ' + titleOrRegExp + '\n[Expected]: Page should have title: ' + titleOrRegExp).toHaveTitle(titleOrRegExp, {timeout: timeout}) } - -/** - * @summary The method uses playwright expect and asserts the page does have the given title. - * @param {Page} page the page's object. - * @param {number} [timeout] the max amount of time to assert page does not have title. Optional parameter. - * @param {string, RegExp} titleOrRegExp the expected title. - * @return {Promise} - * - * - */ async function expectPageDoesNotHaveTitle(page, titleOrRegExp, timeout) { if (isKeyUndefined(timeout)) await pwExpect(page, '[Failure Message]: Page has title: ' + titleOrRegExp + '\n[Expected]: Page should not have title: ' + titleOrRegExp).not.toHaveTitle(titleOrRegExp) @@ -2148,46 +987,19 @@ async function expectPageDoesNotHaveTitle(page, titleOrRegExp, timeout) { await pwExpect(page, '[Failure Message]: Page has title: ' + titleOrRegExp + '\n[Expected]: Page should not have title: ' + titleOrRegExp).not.toHaveTitle(titleOrRegExp, {timeout: timeout}) } -/** - * @summary The method uses playwright expect and asserts the page is navigated to the given url. - * @param {Page} page the page's object. - * @param {number} [timeout] the max amount of time to assert page has url. Optional parameter. - * @param {string, RegExp} urlOrRegExp the expected url. - * @return {Promise} - * - * - */ + async function expectPageHasUrl(page, urlOrRegExp, timeout) { if (isKeyUndefined(timeout)) await pwExpect(page, '[Failure Message]: Page is not navigated to url: ' + urlOrRegExp + '\n[Expected]: Page should have been navigated to: ' + urlOrRegExp).toHaveURL(urlOrRegExp) else await pwExpect(page, '[Failure Message]: Page is not navigated to url: ' + urlOrRegExp + '\n[Expected]: Page should have been navigated to: ' + urlOrRegExp).toHaveURL(urlOrRegExp, {timeout: timeout}) } - -/** - * @summary The method uses playwright expect and asserts the page is not navigated to the given url. - * @param {Page} page the page's object. - * @param {number} [timeout] the max amount of time to assert page has url. Optional parameter. - * @param {string, RegExp} urlOrRegExp the expected url. - * @return {Promise} - * - * - */ async function expectPageDoesNotHaveUrl(page, urlOrRegExp, timeout) { if (isKeyUndefined(timeout)) await pwExpect(page, '[Failure Message]: Page is navigated to url: ' + urlOrRegExp + '\n[Expected]: Page should not have been navigated to: ' + urlOrRegExp).not.toHaveURL(urlOrRegExp) else await pwExpect(page, '[Failure Message]: Page is navigated to url: ' + urlOrRegExp + '\n[Expected]: Page should not have been navigated to: ' + urlOrRegExp).not.toHaveURL(urlOrRegExp, {timeout: timeout}) } - -/** - * @summary The method gets the element from Iframe and runs defined action. await helpers.iframeAction(page,frameLocator,iLocator,'type',text); - * - * @param {Page} page the page's object. - * @param {string} iLocator locator inside the iframe. - * @param {Array} ...args Array - * - * */ async function expectListOfElements(page, locator, args) { const listOfElements = await getListOfElements(page, locator) const count = await listOfElements.count() @@ -2201,121 +1013,10 @@ async function expectListOfElements(page, locator, args) { module.exports = { isVisible, clickElement, - getUserWithFunds, getText, gotoPage, - waitForElementToBePresent, - waitForElementToBeVisible, - inputText, clearAndInputText, - expectValuesEqual, - expectIncludes, - expectValueIsUndefined, - expectFail, - expectStringContains, - expectValueIsNotNull, - expectArraysEqual, - expectValueIsNull, - expectValueIsTrue, - expectValuesNotEqual, - expectValueIsWithin, - expectValueIsEmpty, - expectValueIsFalse, - getElementText, - getElementInnerText, - logError, - logMessage, - logInfo, - logWarning, - logDebug, - logSuccess, - getElementAttributeValue, - selectFromDropDownByValue, - selectFromDropDownByIndex, - inputTextByPageFill, - waitForElementToBeNotPresent, - selectFromDropDownByLabel, - waitForElementToBeHidden, waitForTimeout, waitForLoadState, - waitForNetworkIdleState, - waitForDomContentLoadedState, - waitForCommitState, - getListOfElements, - clickElementByDispatchEvent, - focusOnElement, - doubleClickElement, - inputValueByType, - verifyElementEnabled, - clickElementByElementHandle, - getElementHandle, - getElementHandles, - refreshPage, - generateRandomEmail, - tickCheckBox, - generateRandomNumber, - navigateTo, - generateRandomNumberBetween, - checkIfNumberStartsWithZeroAndGetANewOne, - randAlphaString, - randNumberString, - expectValueIsNotEmpty, - pressEnter, - getInputValue, - isElementVisible, - getCountryCodeBasedOnEnv, - getCountryDialPrefixBasedOnEnv, - sleep, - expectValueToBeAbove, - removeNonNumericCharacter, - formatDate, - getIFrameElement, - iframeAction, - getCountryName, - isElementDisabled, - verifyElementIsDisabled, - isElementChecked, - verifyElementIsChecked, - verifyElementIsUnChecked, - checkRadioOrCheckbox, - uncheckRadioOrCheckbox, - convertStringArrayToFloatArray, - getMaxValueFromNumberArray, - getMinValueFromNumberArray, - getElementAttributeNames, - getElementLocator, - isKeyUndefined, - expectElementToBeChecked, - expectElementToBeDisabled, - expectElementToBeNotDisabled, - expectElementToBeEditable, - expectElementToBeNotEditable, - expectElementToBeEmpty, - expectElementToBeNotEmpty, - expectElementToBeEnabled, - expectElementToBeNotEnabled, - expectElementToBeFocused, - expectElementToBeNotFocused, - expectElementToBeHidden, - expectElementToBeNotHidden, - expectElementToBeVisible, - expectElementToBeNotVisible, - expectElementToContainText, - expectElementToNotContainText, - expectElementToHaveAttribute, - expectElementToHaveCount, - expectElementToNotHaveCount, - expectElementToHaveCSS, - expectElementToNotHaveCSS, - expectElementToHaveJSProperty, - expectElementToNotHaveJSProperty, - expectElementToHaveText, - expectElementToNotHaveText, - expectElementToHaveValue, - expectElementToNotHaveValue, - expectPageHasTitle, - expectPageDoesNotHaveTitle, - expectPageHasUrl, - expectPageDoesNotHaveUrl, - expectListOfElements + generateRandomText }; diff --git a/package.json b/package.json index 2ec89ef..e15e44c 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { - "name": "my-pw-fw", + "name": "e2e-automation-tests", "version": "1.0.0", "description": "Automation testing with JavaScript, Playwright and CucumberJs", "main": "index.js", "scripts": { "**********************************************AUTOMATION******************************************************************************************************": "Test scripts", - "pretest:automationpractice:desktop": "node preExecutionCleanup.js", - "test:automationpractice:desktop": "cross-env NODE_ENV=test_environment PWVIDEO=y BROWSER='' LANGUAGE=english REPORT_FILE_NAME=automationpractice_DESKTOP cucumber-js --parallel 1 -p e2eTestForBoost || true", - "posttest:automationpractice:desktop": "cross-env NODE_ENV=test_environment BROWSER='' LANGUAGE=english REPORT_FILE_NAME=e2eTestForBoost node reporter.js " + "pretest:automation:desktop": "node preExecutionCleanup.js", + "test:automation:desktop": "cross-env NODE_ENV=test_environment BROWSER='' REPORT_FILE_NAME=automation_DESKTOP cucumber-js --parallel 1 -p e2eTestForBoost || true", + "posttest:automation:desktop": "cross-env NODE_ENV=test_environment BROWSER='' REPORT_FILE_NAME=e2eTestForBoost node reporter.js " }, "author": "", "license": "ISC", diff --git a/setup/hooks.js b/setup/hooks.js index 1fc87a4..b9c32e3 100644 --- a/setup/hooks.js +++ b/setup/hooks.js @@ -4,9 +4,7 @@ const { BeforeAll, Before, After, AfterAll , Status, setDefaultTimeout } = requi const cucumber = require('../cucumber'); const helpers = require('../helpers/common-actions') -// const { World } = require('@cucumber/cucumber') -// Launch options. const options = { // If HEADLESS is not passed through env then it is set to false. headless: process.env.HEADLESS === 'true', @@ -20,21 +18,10 @@ BeforeAll(async () => { //global.browser = await playwright[].launch(options); global.browser = await playwright[browser].launch(options); - if(process.env.LANGUAGE.toLowerCase() === 'english'){ - global.coreLanguageConstant = require('../tests/constants/englishLanguageConstants') - } }); // Create a fresh browser context for each test. Before(async (scenario) => { - if (process.env.PWVIDEO) { - global.context = await global.browser.newContext({viewport: null, - recordVideo : {dir: 'videos/'+scenario.pickle.name} - }); - } else { - helpers.logWarning("PWVIDEO is not defined as environment variable: Video will not be created.") - - } global.context = await global.browser.newContext({viewport: null }); await context.setHTTPCredentials({ username: 'bandlab', @@ -44,12 +31,6 @@ Before(async (scenario) => { await helpers.gotoPage(page,global.BASE_URL) }); -// close the page and context after each test. -/*After(async () => { - await global.page.close(); - await global.context.close(); -});*/ - After(async function (scenario) { if (scenario.result.status === Status.FAILED) { var buffer = await global.page.screenshot({ path: `reports/${scenario.pickle.name}.png`, fullPage: true }) diff --git a/shared/config.test.js b/shared/config.test.js new file mode 100644 index 0000000..163ab63 --- /dev/null +++ b/shared/config.test.js @@ -0,0 +1,10 @@ +const config = { + alice: { + username:"bandlabbackendtest@outlook.com", + name: "backendtest", + password: "testingbackend123", + userId: "097996e2-ce2e-4103-9eb0-f2f62d64f33a" + }, +} + +module.exports = config; \ No newline at end of file diff --git a/tests-examples/demo-todo-app.spec.js b/tests-examples/demo-todo-app.spec.js deleted file mode 100644 index e2eb87c..0000000 --- a/tests-examples/demo-todo-app.spec.js +++ /dev/null @@ -1,449 +0,0 @@ -// @ts-check -const { test, expect } = require('@playwright/test'); - -test.beforeEach(async ({ page }) => { - await page.goto('https://demo.playwright.dev/todomvc'); -}); - -const TODO_ITEMS = [ - 'buy some cheese', - 'feed the cat', - 'book a doctors appointment' -]; - -test.describe('New Todo', () => { - test('should allow me to add todo items', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // Create 1st todo. - await newTodo.fill(TODO_ITEMS[0]); - await newTodo.press('Enter'); - - // Make sure the list only has one todo item. - await expect(page.getByTestId('todo-title')).toHaveText([ - TODO_ITEMS[0] - ]); - - // Create 2nd todo. - await newTodo.fill(TODO_ITEMS[1]); - await newTodo.press('Enter'); - - // Make sure the list now has two todo items. - await expect(page.getByTestId('todo-title')).toHaveText([ - TODO_ITEMS[0], - TODO_ITEMS[1] - ]); - - await checkNumberOfTodosInLocalStorage(page, 2); - }); - - test('should clear text input field when an item is added', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // Create one todo item. - await newTodo.fill(TODO_ITEMS[0]); - await newTodo.press('Enter'); - - // Check that input is empty. - await expect(newTodo).toBeEmpty(); - await checkNumberOfTodosInLocalStorage(page, 1); - }); - - test('should append new items to the bottom of the list', async ({ page }) => { - // Create 3 items. - await createDefaultTodos(page); - - // create a todo count locator - const todoCount = page.getByTestId('todo-count') - - // Check test using different methods. - await expect(page.getByText('3 items left')).toBeVisible(); - await expect(todoCount).toHaveText('3 items left'); - await expect(todoCount).toContainText('3'); - await expect(todoCount).toHaveText(/3/); - - // Check all items in one call. - await expect(page.getByTestId('todo-title')).toHaveText(TODO_ITEMS); - await checkNumberOfTodosInLocalStorage(page, 3); - }); -}); - -test.describe('Mark all as completed', () => { - test.beforeEach(async ({ page }) => { - await createDefaultTodos(page); - await checkNumberOfTodosInLocalStorage(page, 3); - }); - - test.afterEach(async ({ page }) => { - await checkNumberOfTodosInLocalStorage(page, 3); - }); - - test('should allow me to mark all items as completed', async ({ page }) => { - // Complete all todos. - await page.getByLabel('Mark all as complete').check(); - - // Ensure all todos have 'completed' class. - await expect(page.getByTestId('todo-item')).toHaveClass(['completed', 'completed', 'completed']); - await checkNumberOfCompletedTodosInLocalStorage(page, 3); - }); - - test('should allow me to clear the complete state of all items', async ({ page }) => { - const toggleAll = page.getByLabel('Mark all as complete'); - // Check and then immediately uncheck. - await toggleAll.check(); - await toggleAll.uncheck(); - - // Should be no completed classes. - await expect(page.getByTestId('todo-item')).toHaveClass(['', '', '']); - }); - - test('complete all checkbox should update state when items are completed / cleared', async ({ page }) => { - const toggleAll = page.getByLabel('Mark all as complete'); - await toggleAll.check(); - await expect(toggleAll).toBeChecked(); - await checkNumberOfCompletedTodosInLocalStorage(page, 3); - - // Uncheck first todo. - const firstTodo = page.getByTestId('todo-item').nth(0); - await firstTodo.getByRole('checkbox').uncheck(); - - // Reuse toggleAll locator and make sure its not checked. - await expect(toggleAll).not.toBeChecked(); - - await firstTodo.getByRole('checkbox').check(); - await checkNumberOfCompletedTodosInLocalStorage(page, 3); - - // Assert the toggle all is checked again. - await expect(toggleAll).toBeChecked(); - }); -}); - -test.describe('Item', () => { - - test('should allow me to mark items as complete', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // Create two items. - for (const item of TODO_ITEMS.slice(0, 2)) { - await newTodo.fill(item); - await newTodo.press('Enter'); - } - - // Check first item. - const firstTodo = page.getByTestId('todo-item').nth(0); - await firstTodo.getByRole('checkbox').check(); - await expect(firstTodo).toHaveClass('completed'); - - // Check second item. - const secondTodo = page.getByTestId('todo-item').nth(1); - await expect(secondTodo).not.toHaveClass('completed'); - await secondTodo.getByRole('checkbox').check(); - - // Assert completed class. - await expect(firstTodo).toHaveClass('completed'); - await expect(secondTodo).toHaveClass('completed'); - }); - - test('should allow me to un-mark items as complete', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // Create two items. - for (const item of TODO_ITEMS.slice(0, 2)) { - await newTodo.fill(item); - await newTodo.press('Enter'); - } - - const firstTodo = page.getByTestId('todo-item').nth(0); - const secondTodo = page.getByTestId('todo-item').nth(1); - const firstTodoCheckbox = firstTodo.getByRole('checkbox'); - - await firstTodoCheckbox.check(); - await expect(firstTodo).toHaveClass('completed'); - await expect(secondTodo).not.toHaveClass('completed'); - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - - await firstTodoCheckbox.uncheck(); - await expect(firstTodo).not.toHaveClass('completed'); - await expect(secondTodo).not.toHaveClass('completed'); - await checkNumberOfCompletedTodosInLocalStorage(page, 0); - }); - - test('should allow me to edit an item', async ({ page }) => { - await createDefaultTodos(page); - - const todoItems = page.getByTestId('todo-item'); - const secondTodo = todoItems.nth(1); - await secondTodo.dblclick(); - await expect(secondTodo.getByRole('textbox', { name: 'Edit' })).toHaveValue(TODO_ITEMS[1]); - await secondTodo.getByRole('textbox', { name: 'Edit' }).fill('buy some sausages'); - await secondTodo.getByRole('textbox', { name: 'Edit' }).press('Enter'); - - // Explicitly assert the new text value. - await expect(todoItems).toHaveText([ - TODO_ITEMS[0], - 'buy some sausages', - TODO_ITEMS[2] - ]); - await checkTodosInLocalStorage(page, 'buy some sausages'); - }); -}); - -test.describe('Editing', () => { - test.beforeEach(async ({ page }) => { - await createDefaultTodos(page); - await checkNumberOfTodosInLocalStorage(page, 3); - }); - - test('should hide other controls when editing', async ({ page }) => { - const todoItem = page.getByTestId('todo-item').nth(1); - await todoItem.dblclick(); - await expect(todoItem.getByRole('checkbox')).not.toBeVisible(); - await expect(todoItem.locator('label', { - hasText: TODO_ITEMS[1], - })).not.toBeVisible(); - await checkNumberOfTodosInLocalStorage(page, 3); - }); - - test('should save edits on blur', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).dblclick(); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill('buy some sausages'); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).dispatchEvent('blur'); - - await expect(todoItems).toHaveText([ - TODO_ITEMS[0], - 'buy some sausages', - TODO_ITEMS[2], - ]); - await checkTodosInLocalStorage(page, 'buy some sausages'); - }); - - test('should trim entered text', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).dblclick(); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill(' buy some sausages '); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).press('Enter'); - - await expect(todoItems).toHaveText([ - TODO_ITEMS[0], - 'buy some sausages', - TODO_ITEMS[2], - ]); - await checkTodosInLocalStorage(page, 'buy some sausages'); - }); - - test('should remove the item if an empty text string was entered', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).dblclick(); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill(''); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).press('Enter'); - - await expect(todoItems).toHaveText([ - TODO_ITEMS[0], - TODO_ITEMS[2], - ]); - }); - - test('should cancel edits on escape', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).dblclick(); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill('buy some sausages'); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).press('Escape'); - await expect(todoItems).toHaveText(TODO_ITEMS); - }); -}); - -test.describe('Counter', () => { - test('should display the current number of todo items', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // create a todo count locator - const todoCount = page.getByTestId('todo-count') - - await newTodo.fill(TODO_ITEMS[0]); - await newTodo.press('Enter'); - await expect(todoCount).toContainText('1'); - - await newTodo.fill(TODO_ITEMS[1]); - await newTodo.press('Enter'); - await expect(todoCount).toContainText('2'); - - await checkNumberOfTodosInLocalStorage(page, 2); - }); -}); - -test.describe('Clear completed button', () => { - test.beforeEach(async ({ page }) => { - await createDefaultTodos(page); - }); - - test('should display the correct text', async ({ page }) => { - await page.locator('.todo-list li .toggle').first().check(); - await expect(page.getByRole('button', { name: 'Clear completed' })).toBeVisible(); - }); - - test('should remove completed items when clicked', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).getByRole('checkbox').check(); - await page.getByRole('button', { name: 'Clear completed' }).click(); - await expect(todoItems).toHaveCount(2); - await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[2]]); - }); - - test('should be hidden when there are no items that are completed', async ({ page }) => { - await page.locator('.todo-list li .toggle').first().check(); - await page.getByRole('button', { name: 'Clear completed' }).click(); - await expect(page.getByRole('button', { name: 'Clear completed' })).toBeHidden(); - }); -}); - -test.describe('Persistence', () => { - test('should persist its data', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - for (const item of TODO_ITEMS.slice(0, 2)) { - await newTodo.fill(item); - await newTodo.press('Enter'); - } - - const todoItems = page.getByTestId('todo-item'); - const firstTodoCheck = todoItems.nth(0).getByRole('checkbox'); - await firstTodoCheck.check(); - await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[1]]); - await expect(firstTodoCheck).toBeChecked(); - await expect(todoItems).toHaveClass(['completed', '']); - - // Ensure there is 1 completed item. - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - - // Now reload. - await page.reload(); - await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[1]]); - await expect(firstTodoCheck).toBeChecked(); - await expect(todoItems).toHaveClass(['completed', '']); - }); -}); - -test.describe('Routing', () => { - test.beforeEach(async ({ page }) => { - await createDefaultTodos(page); - // make sure the app had a chance to save updated todos in storage - // before navigating to a new view, otherwise the items can get lost :( - // in some frameworks like Durandal - await checkTodosInLocalStorage(page, TODO_ITEMS[0]); - }); - - test('should allow me to display active items', async ({ page }) => { - const todoItem = page.getByTestId('todo-item'); - await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); - - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - await page.getByRole('link', { name: 'Active' }).click(); - await expect(todoItem).toHaveCount(2); - await expect(todoItem).toHaveText([TODO_ITEMS[0], TODO_ITEMS[2]]); - }); - - test('should respect the back button', async ({ page }) => { - const todoItem = page.getByTestId('todo-item'); - await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); - - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - - await test.step('Showing all items', async () => { - await page.getByRole('link', { name: 'All' }).click(); - await expect(todoItem).toHaveCount(3); - }); - - await test.step('Showing active items', async () => { - await page.getByRole('link', { name: 'Active' }).click(); - }); - - await test.step('Showing completed items', async () => { - await page.getByRole('link', { name: 'Completed' }).click(); - }); - - await expect(todoItem).toHaveCount(1); - await page.goBack(); - await expect(todoItem).toHaveCount(2); - await page.goBack(); - await expect(todoItem).toHaveCount(3); - }); - - test('should allow me to display completed items', async ({ page }) => { - await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - await page.getByRole('link', { name: 'Completed' }).click(); - await expect(page.getByTestId('todo-item')).toHaveCount(1); - }); - - test('should allow me to display all items', async ({ page }) => { - await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - await page.getByRole('link', { name: 'Active' }).click(); - await page.getByRole('link', { name: 'Completed' }).click(); - await page.getByRole('link', { name: 'All' }).click(); - await expect(page.getByTestId('todo-item')).toHaveCount(3); - }); - - test('should highlight the currently applied filter', async ({ page }) => { - await expect(page.getByRole('link', { name: 'All' })).toHaveClass('selected'); - - //create locators for active and completed links - const activeLink = page.getByRole('link', { name: 'Active' }); - const completedLink = page.getByRole('link', { name: 'Completed' }); - await activeLink.click(); - - // Page change - active items. - await expect(activeLink).toHaveClass('selected'); - await completedLink.click(); - - // Page change - completed items. - await expect(completedLink).toHaveClass('selected'); - }); -}); - -async function createDefaultTodos(page) { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - for (const item of TODO_ITEMS) { - await newTodo.fill(item); - await newTodo.press('Enter'); - } -} - -/** - * @param {import('@playwright/test').Page} page - * @param {number} expected - */ - async function checkNumberOfTodosInLocalStorage(page, expected) { - return await page.waitForFunction(e => { - return JSON.parse(localStorage['react-todos']).length === e; - }, expected); -} - -/** - * @param {import('@playwright/test').Page} page - * @param {number} expected - */ - async function checkNumberOfCompletedTodosInLocalStorage(page, expected) { - return await page.waitForFunction(e => { - return JSON.parse(localStorage['react-todos']).filter(i => i.completed).length === e; - }, expected); -} - -/** - * @param {import('@playwright/test').Page} page - * @param {string} title - */ -async function checkTodosInLocalStorage(page, title) { - return await page.waitForFunction(t => { - return JSON.parse(localStorage['react-todos']).map(i => i.title).includes(t); - }, title); -} diff --git a/tests/constants/englishLanguageConstants.js b/tests/constants/englishLanguageConstants.js deleted file mode 100644 index e69de29..0000000 diff --git a/tests/e2eTestForBoost/base-setup/baseSetup.js b/tests/e2eTestForBoost/base-setup/baseSetup.js index a9ed597..12dabb6 100644 --- a/tests/e2eTestForBoost/base-setup/baseSetup.js +++ b/tests/e2eTestForBoost/base-setup/baseSetup.js @@ -1,19 +1,20 @@ const { BeforeAll } = require('@cucumber/cucumber') const {Feeds} = require("../pages/boostPage"); const {OrderSummary, campaignDashboard} = require("../pages/OrderSummary"); -const {Boost, BoostPost} = require("../pages/boostPost"); +const {Boost, BoostPost, Login} = require("../pages/login"); +const {CampaignPerformance} = require("../pages/campaignPerformance"); BeforeAll(async function () { - const {BoostPost} = require("../pages/boostPost") + const {Login} = require("../pages/login") const {Feeds} = require("../pages/feeds") const {BoostPage}=require("../pages/boostPage") const {OrderSummary}=require("../pages/orderSummary") const {campaignDashboard} = require("../pages/campaignDashboard") - global.boostPostPage = new BoostPost() - global.myFeedPage=new Feeds() - global.boostPage=new BoostPage() - global.orderSummaryPage=new OrderSummary() - global.campaignDashboardPage=new campaignDashboard() - + global.loginPage= new Login() + global.feedPage= new Feeds() + global.boostPage= new BoostPage() + global.orderSummaryPage= new OrderSummary() + global.campaignDashboardPage= new campaignDashboard() + global.campaignPerformancePage= new CampaignPerformance() }) \ No newline at end of file diff --git a/tests/e2eTestForBoost/commonMethods.js b/tests/e2eTestForBoost/commonMethods.js deleted file mode 100644 index 139597f..0000000 --- a/tests/e2eTestForBoost/commonMethods.js +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/tests/e2eTestForBoost/features/desktop/boostPost.feature b/tests/e2eTestForBoost/features/desktop/boostPost.feature index bc8f765..4f42dbe 100644 --- a/tests/e2eTestForBoost/features/desktop/boostPost.feature +++ b/tests/e2eTestForBoost/features/desktop/boostPost.feature @@ -1,13 +1,13 @@ Feature: Boost a Post Feature - Scenario Outline: Boost a Non-music Post - Given Login with and - When Create a text post - And I click the boost button - When I check the Boost Campaign Details - And Complete the Boost payment process - - Examples: - |username| |password| - |moryani | | test@1234| - + Scenario: Boost a Non-Music Post + Given I login as Alice + When I create a text post + And I click the Boost button + When I set the Budget & Duration for my Boost Campaign + And I complete the Boost payment process + When I click on the Campaign Dashboard button + Then Boost Post campaign is shown on Boost Dashboard + When I click on the Boost button again + Then Campaign Performance page should be displayed with status In-Review + And I delete the post created for clean-up \ No newline at end of file diff --git a/tests/e2eTestForBoost/pages/OrderSummary.js b/tests/e2eTestForBoost/pages/OrderSummary.js index 8b8d37e..c474123 100644 --- a/tests/e2eTestForBoost/pages/OrderSummary.js +++ b/tests/e2eTestForBoost/pages/OrderSummary.js @@ -1,28 +1,21 @@ +const assert = require("assert"); const helpers = require("../../../helpers/common-actions") -const {waitForLoadState} = require("../../../helpers/common-actions"); -const productPageLocators = { - product: function (productName) { - return '(//a[@title="' + productName + '"])[2]' - } -} - -const completePurchase = { - orderSummary: "//div[text()='Order summary']", - - completePurchaseButton:"//span[text()='Complete Purchase']" +const completePurchase= { + orderSummary_locator: "//div[text()='Order summary']", + completePurchaseButton_locator:"//span[text()='Complete Purchase']" } - class OrderSummary { - - async VerifyOrderSummary(){ - const verifyOrderSummary = await helpers.getText(page, completePurchase.orderSummary) + async verifyOrderSummary(){ + // @ts-ignore + const verifyOrderSummary = await helpers.getText(page, completePurchase.orderSummary_locator) console.log("Order Summary page ->"+verifyOrderSummary); assert.strictEqual(verifyOrderSummary,"Order summary", "Order summary Page is Successful") } - async CompletePurchase(){ - await helpers.clickElement(page, completePurchase.completePurchaseButton) + async completePurchase(){ + // @ts-ignore + await helpers.clickElement(page, completePurchase.completePurchaseButton_locator) } } -module.exports= {OrderSummary} \ No newline at end of file +module.exports= { OrderSummary } \ No newline at end of file diff --git a/tests/e2eTestForBoost/pages/boostPage.js b/tests/e2eTestForBoost/pages/boostPage.js index 03c2fc7..ca6d0cf 100644 --- a/tests/e2eTestForBoost/pages/boostPage.js +++ b/tests/e2eTestForBoost/pages/boostPage.js @@ -1,25 +1,17 @@ const helpers = require("../../../helpers/common-actions") const {waitForLoadState} = require("../../../helpers/common-actions"); -const productPageLocators = { - product: function (productName) { - return '(//a[@title="' + productName + '"])[2]' - } -} const boostLocators = { - - setPostBoostBudgetText: "//h1[text()='Set Your Post Boost Budget and Period']", - - nextButton:"//button[contains(@class,'ds-button ds-button-primary')]", + setPostBoostBudgetText_locator: "//h1[text()='Set Your Post Boost Budget and Period']", + nextButton_locator:"//button[contains(@class,'ds-button ds-button-primary')]", } class BoostPage { - async VerifySetBudgetAndDuration(){ - const budgetText= await helpers.getText(page, boostLocators.setPostBoostBudgetText) - console.log("budget Text -> "+budgetText); + async verifySetBudgetAndDuration(){ + const budgetText= await helpers.getText(page, boostLocators.setPostBoostBudgetText_locator) assert.strictEqual(budgetText, "Set Your Post Boost Budget and Period", "Correct Page displayed") } async setBudgetAndDuration(){ - await helpers.clickElement(page, boostLocators.nextButton) + await helpers.clickElement(page, boostLocators.nextButton_locator) } } diff --git a/tests/e2eTestForBoost/pages/boostPost.js b/tests/e2eTestForBoost/pages/boostPost.js deleted file mode 100644 index 6a3a11a..0000000 --- a/tests/e2eTestForBoost/pages/boostPost.js +++ /dev/null @@ -1,22 +0,0 @@ -//const LoginBase = require('../pages-base/loginBase') -const helpers = require('../../../helpers/common-actions') -const commonMethods = require('../commonMethods') - -const loginPageLocators = { - loginLink:"//*[contains(text(),'Log in')]", - usernameTextBox: '#username', - passwordTextBox: '#password', - loginButton: "//*[contains(text(),'Log in')]", -} - -class BoostPost { - - async performLogin(username, password) { - await helpers.clickElement(page,loginPageLocators.loginLink) - await helpers.clearAndInputText(page, loginPageLocators.usernameTextBox, username) - await helpers.clearAndInputText(page, loginPageLocators.passwordTextBox, password) - await helpers.clickElement(page, loginPageLocators.loginButton) - } -} - -module.exports = { BoostPost } diff --git a/tests/e2eTestForBoost/pages/campaignDashboard.js b/tests/e2eTestForBoost/pages/campaignDashboard.js index 124579d..9954567 100644 --- a/tests/e2eTestForBoost/pages/campaignDashboard.js +++ b/tests/e2eTestForBoost/pages/campaignDashboard.js @@ -1,30 +1,25 @@ const helpers = require("../../../helpers/common-actions") -const {waitForLoadState} = require("../../../helpers/common-actions"); -const productPageLocators = { - product: function (productName) { - return '(//a[@title="' + productName + '"])[2]' - } -} +const context = require('../../../context/context'); const campaignDashboardLocators = { - setPageText: "//div[text()='You’re all set!']", - campaignDashboardButton: "(//button[@type='button'])[1]", - allFilterDropdown: "//a[@dropdown-direction='down']", - inReviewFilterDropdown: "//a[contains(text(),'In Review')]", - firstCampaignInDashboard: "//span[text()='e2e_test_Post']" + campaignDashboardButton_locator: "//button[contains(@class,'ds-button ds-button-primary')]", + firstCampaignInDashboard_locator: "(//span[@class='text-wrap'])[1]", + boostCampaignFilter_locator: "(//a[@class='side-nav-item ng-scope'])[1]", + campaignState_locator: "(//span[text()='In Review'])[1]" } class campaignDashboard { async campaignDashBoardButton(){ - - await helpers.clickElement(page, campaignDashboardLocators.campaignDashboardButton) + await helpers.clickElement(page, campaignDashboardLocators.campaignDashboardButton_locator) } - async campaignDashboardPage(){ - await helpers.clickElement(page, campaignDashboardLocators.allFilterDropdown) - await helpers.clickElement(page, campaignDashboardLocators.inReviewFilterDropdown) - await helpers.waitForTimeout(page,5000); - const createdCampaign = await helpers.getText(campaignDashboardLocators.firstCampaignInDashboard) - console.log("createdCampaign -> "+createdCampaign); - assert.strictEqual(createdCampaign,"e2e_test_Post","Boost Post Campaign returned in the Campaign Dashboard InReview state") + async campaignDashboardPage(expectedValue){ + await helpers.clickElement(page, campaignDashboardLocators.boostCampaignFilter_locator) + const createdBoostCampaign =await helpers.getText(page, campaignDashboardLocators.firstCampaignInDashboard_locator) + const inReviewCampaign = await helpers.getText(page, campaignDashboardLocators.campaignState_locator); + console.log("context -> "+context.randomPostText); + assert.strictEqual(createdBoostCampaign, context.randomPostText,"Boost Post Campaign returned in the Campaign Dashboard"); + console.log("context 1-> "+context.randomPostText); + assert.strictEqual(inReviewCampaign, "In Review", "State is InReview as expected") } } -module.exports= {campaignDashboard} \ No newline at end of file + +module.exports= { campaignDashboard } \ No newline at end of file diff --git a/tests/e2eTestForBoost/pages/campaignPerformance.js b/tests/e2eTestForBoost/pages/campaignPerformance.js new file mode 100644 index 0000000..35937f9 --- /dev/null +++ b/tests/e2eTestForBoost/pages/campaignPerformance.js @@ -0,0 +1,25 @@ +const helpers = require("../../../helpers/common-actions") +const {waitForLoadState} = require("../../../helpers/common-actions"); +const context = require('../../../context/context'); + +const campaignPerformance = { + boostedPost_locator: "//div[@class='promote-tile-img-container']/following-sibling::div[1]", + boostPostStatus_locator: "//span[text()='In Review']", + totalBudget_locator: "(//span[text()='$50'])[1]", + backToFeed_locator: "//button[contains(@class,'button-scd button-round-32')]" +} + +class CampaignPerformance { + async verifyCampaignDetails(){ + const boostedPost= await helpers.getText(page, campaignPerformance.boostedPost_locator) + assert.strictEqual(boostedPost, context.newTextPost, "Boosted text Post returned successfully") + } + async campaignStatus(){ + await helpers.clickElement(page, campaignPerformance.boostPostStatus_locator) + } + async backToFeed(){ + await helpers.clickElement(page, campaignPerformance.backToFeed_locator) + } +} + +module.exports= { CampaignPerformance } \ No newline at end of file diff --git a/tests/e2eTestForBoost/pages/feeds.js b/tests/e2eTestForBoost/pages/feeds.js index 3a019df..0dd01e7 100644 --- a/tests/e2eTestForBoost/pages/feeds.js +++ b/tests/e2eTestForBoost/pages/feeds.js @@ -1,30 +1,46 @@ const helpers = require("../../../helpers/common-actions"), { - waitForLoadState, - getText -} = require("../../../helpers/common-actions"), feedLocators = { - inputPost: ".post-create-caption>span", - feedText: ".form-field.textarea-emoji-wrapper>textarea", - postButton: "(//span[@class='ds-button-text'])[3]", - boostButton: "(//span[text()='Boost'])[1]", - postTitle: "(//p[text()='e2e_test_Post'])[1]" -}; + } = require("../../../helpers/common-actions"); +const context = require('../../../context/context'); -class Feeds { - async CreatePost(){ - await helpers.clickElement(page, feedLocators.inputPost); - await helpers.clearAndInputText(page, feedLocators.feedText, "e2e_test_Post"); - await helpers.clickElement(page, feedLocators.postButton); + feedLocators = { + inputPost_locator: "//span[text()='What’s new?']", + feedText_locator: "//textarea[@aria-label='What’s new?']", + postButton_locator: "//span[text()='Post']", + boostButton_locator: "(//span[text()='Boost'])[1]", + postTitle_locator: "(//post-card-caption[@text='vm.post.caption']//div)[2]", + feedHome_locator: "(//a[@ui-sref='feed'])[1]", + threeDotsMenu_locator: "(//div[contains(@class,'button-transparent button-height-32')]//i)[1]", + deletePost: "//a[@class='dropdown-menu-link ng-scope']//span[1]", + confirmationPopUp: "//h2[text()='Delete this post?']", + confirmDelete: "//button[text()='Delete']" + }; + class Feeds { + async createPost(){ + await helpers.clickElement(page, feedLocators.inputPost_locator); + context.newTextPost = await helpers.generateRandomText(); + context.variable = context.newTextPost; + await helpers.clearAndInputText(page, feedLocators.feedText_locator, context.newTextPost); + await helpers.clickElement(page, feedLocators.postButton_locator); } - - async CreatePostFunc(){ - const post = await helpers.getText(page, feedLocators.postTitle); - console.log("actualText -> "+post); - assert.strictEqual(post, "e2e_test_Post", "Post created successfully") + async validateCreatedPost(){ + const post = await helpers.getText(page, feedLocators.postTitle_locator); + assert.strictEqual(post, context.newTextPost, "Post created successfully") } - async clickBoost(){ - await helpers.clickElement(page,feedLocators.boostButton) + await helpers.clickElement(page, feedLocators.boostButton_locator) + } + async feed(){ + await helpers.clickElement(page, feedLocators.feedHome_locator) + } + async deletePost(){ + await helpers.clickElement(page, feedLocators.threeDotsMenu_locator); + await helpers.clickElement(page, feedLocators.deletePost); + await helpers.waitForLoadState(page, 10000); + const confirmDeletePopUp = await helpers.getText(page, feedLocators.confirmationPopUp); + assert.strictEqual(confirmDeletePopUp, "Delete this post?", "Pass"); + await helpers.waitForLoadState(page, 3000); + await helpers.clickElement(page, feedLocators.confirmDelete); } } -module.exports = {Feeds} \ No newline at end of file +module.exports = { Feeds } \ No newline at end of file diff --git a/tests/e2eTestForBoost/pages/login.js b/tests/e2eTestForBoost/pages/login.js new file mode 100644 index 0000000..9e1d2a8 --- /dev/null +++ b/tests/e2eTestForBoost/pages/login.js @@ -0,0 +1,23 @@ +const helpers = require('../../../helpers/common-actions') + +const loginPageLocators = { + loginLink_locator:"//*[contains(text(),'Log in')]", + usernameTextBox_locator: '#username', + passwordTextBox_locator: '#password', + loginButton_locator: "//*[contains(text(),'Log in')]", +} + +class Login { + async login(username, password) { + // @ts-ignore + await helpers.clickElement(page,loginPageLocators.loginLink_locator) + // @ts-ignore + await helpers.clearAndInputText(page, loginPageLocators.usernameTextBox_locator, username) + // @ts-ignore + await helpers.clearAndInputText(page, loginPageLocators.passwordTextBox_locator, password) + // @ts-ignore + await helpers.clickElement(page, loginPageLocators.loginButton_locator) + } +} + +module.exports = { Login } diff --git a/tests/e2eTestForBoost/step-definitions/boost.steps.js b/tests/e2eTestForBoost/step-definitions/boost.steps.js index 37cc448..e57fafc 100644 --- a/tests/e2eTestForBoost/step-definitions/boost.steps.js +++ b/tests/e2eTestForBoost/step-definitions/boost.steps.js @@ -1,39 +1,45 @@ const {Given, When, Then} = require('@cucumber/cucumber') let helpers = require('../../../helpers/common-actions'); -const assert = require('assert'); - -Given(/^Login with (.*) and (.*)$/, async (username, password) => { - await boostPostPage.performLogin(username, password) +const config = require('../../../shared/config.test'); +Given(/^I login as Alice$/, async () => { + await loginPage.login(config.alice.username, config.alice.password) }) - -Then (/^Create a text post$/,async function (){ - await myFeedPage.CreatePost() - await helpers.waitForTimeout(page,5000); - await myFeedPage.CreatePostFunc(); +Then(/^I create a text post$/,async function (){ + await feedPage.createPost(); + await helpers.waitForLoadState(page, 5000); + await feedPage.validateCreatedPost(); }) - -Then (/^I click the boost button$/,async function (){ - await myFeedPage.clickBoost(); +Then(/^I click the Boost button$/,async function (){ + await feedPage.clickBoost(); }) - -When (/^I check the Boost Campaign Details$/,async function (){ - await boostPage.VerifySetBudgetAndDuration(); +When(/^I set the Budget & Duration for my Boost Campaign$/,async function (){ + await boostPage.verifySetBudgetAndDuration(); await boostPage.setBudgetAndDuration(); }) - -When (/^Complete the Boost payment process$/,async function (){ - await helpers.waitForTimeout(page,5000); - await orderSummaryPage.VerifyOrderSummary(); - await orderSummaryPage.CompletePurchase(); +When(/^I complete the Boost payment process$/,async function (){ + await orderSummaryPage.verifyOrderSummary(); + await orderSummaryPage.completePurchase(); }) - When(/^I click on the Campaign Dashboard button$/,async function (){ - await helpers.waitForTimeout(page,10000); await campaignDashboardPage.campaignDashBoardButton(); }) - -Then (/^Boost Post Campaign is returned should be returned in the Campaign Dashboard$/,async function (){ - await helpers.waitForTimeout(page,10000); +Then(/^Boost Post campaign is shown on Boost Dashboard$/,async function (){ + await helpers.waitForTimeout(page,20000); await campaignDashboardPage.campaignDashboardPage(); }) +When(/^I click on the Boost button again$/, async function(){ + await feedPage.feed(); + await helpers.waitForTimeout(page,20000); + await feedPage.clickBoost(); +}) +Then(/^Campaign Performance page should be displayed with status In-Review$/, async function(){ + await helpers.waitForTimeout(page,5000); + await campaignPerformancePage.campaignStatus(); + await campaignPerformancePage.verifyCampaignDetails(); +}) +Then(/^I delete the post created for clean-up$/, async function(){ + await helpers.waitForTimeout(page,5000); + await feedPage.feed(); + await feedPage.deletePost(); +}) \ No newline at end of file