diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 6fc67e5..e60026a 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -18,7 +18,7 @@ jobs: - name: Install Playwright Browsers run: npx playwright install --with-deps - name: Cucumber-Tests - run: npm run lunaapp + run: cucumber:luma - uses: actions/upload-artifact@v4 if: always() with: diff --git a/logger/logger.ts b/logger/logger.ts index dba4ab6..7e3c5a5 100644 --- a/logger/logger.ts +++ b/logger/logger.ts @@ -3,7 +3,7 @@ import { allColors } from 'winston/lib/winston/config'; const { combine, timestamp, printf, colorize, splat } = format; -const createCustomLogger = (scenarioName: string) => { +const createCustomLogger = () => { const customFormat = printf(({ timestamp, level, message,}) => { return ` [${timestamp}] ${level} ${message}`; }); @@ -27,7 +27,8 @@ const createCustomLogger = (scenarioName: string) => { ) }), new transports.File({ - filename: `test-results/logs/${scenarioName}/log.log`, + filename: `test-results/logs/log.log`, + options: { flags: 'w' }, level: 'info', format: format.combine( timestamp({ diff --git a/package.json b/package.json index 2a05bac..131bd89 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,9 @@ "version": "1.0.0", "main": "index.js", "scripts": { - "lunaapp": "cucumber-js --config=config/cucumber.js", - "lunaapp:tags": "cucumber-js --config=config/cucumber.js --tags ", - "lunaapp:debug": "cucumber-js --config=config/cucumber.js --tags @debug" + "cucumber:luma": "cucumber-js --config=config/cucumber.js", + "cucumber:luma:tags": "cucumber-js --config=config/cucumber.js --tags ", + "cucumber:luma:debug": "cucumber-js --config=config/cucumber.js --tags @MenShopping" }, "keywords": [], "author": "", diff --git a/playwright.config.ts b/playwright.config.ts index a970899..6843b24 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,13 +1,12 @@ import { LaunchOptions } from "@playwright/test"; import createCustomLogger from "./logger/logger"; -let scenarioName; -const logger = createCustomLogger(scenarioName); +const logger = createCustomLogger(); export const config: LaunchOptions = { timeout: 600000, headless: true, - // args:['--window-position=-1070,-100'], // customized for left-sided portrait monitor. + // args:['--window-position=-1070,-100'], //* customized for left-sided portrait monitor. slowMo: 300, logger: { isEnabled: (name, severity) => name === 'api', diff --git a/src/test/features/UserShopping.feature b/src/test/features/UserShopping.feature index 1b470fc..1574d78 100644 --- a/src/test/features/UserShopping.feature +++ b/src/test/features/UserShopping.feature @@ -11,7 +11,7 @@ Feature: Verify that the user is able to purchase some item. Scenario: User shops for Men Jackets. When The user clicks on the "
" section and the user clicks on "" option. And The products are shown and user navigates to a product. - And The price of that product is shown. + And The price, size of that product is shown. Examples: | Section | Attire | @@ -21,7 +21,7 @@ Feature: Verify that the user is able to purchase some item. Scenario: User shops for Women Jackets. When The user clicks on the "
" section and the user clicks on "" option. And The products are shown and user navigates to a product. - And The price of that product is shown. + And The price, size of that product is shown. Examples: | Section | Attire | diff --git a/src/test/hooks/hooks.ts b/src/test/hooks/hooks.ts index ff3293e..88ee293 100644 --- a/src/test/hooks/hooks.ts +++ b/src/test/hooks/hooks.ts @@ -8,17 +8,16 @@ let browser: Browser; let context: BrowserContext; BeforeAll(async function () { + pageFixture.logger = createCustomLogger(); + pageFixture.logger.info('----------------- New Test Run -----------------'); browser = await chromium.launch(config); }); -Before(async function ({ pickle }) { - const scenarioName = pickle.name + pickle.id; +Before(async function () { context = await browser.newContext({viewport: null}); const page = await context.newPage(); pageFixture.page = page; - pageFixture.logger = createCustomLogger(scenarioName) - - // pageFixture.logger = createLogger(options(scenarioName)); + // pageFixture.logger = createCustomLogger(); }); After(async function ({ pickle, result }) { diff --git a/src/test/pages/UserShopping.ts b/src/test/pages/UserShopping.ts index 1853760..d2a6322 100644 --- a/src/test/pages/UserShopping.ts +++ b/src/test/pages/UserShopping.ts @@ -37,7 +37,9 @@ import { Page, expect } from "@playwright/test"; productShown:() => pageFixture.page.locator(getResource('productsShown').selectorValue), productPrice:() => pageFixture.page.locator(getResource('productPrice').selectorValue), shoppingList:() => pageFixture.page.locator(getResource('shoppingList').selectorValue), - productSize:() => pageFixture.page.locator(getResource('productSize').selectorValue) + productSize:() => pageFixture.page.locator(getResource('productSize').selectorValue), + getProductSize:() => pageFixture.page.locator(getResource('getProductSize').selectorValue), + getProductSizesAvailable:() => pageFixture.page.locator(getResource('getProductSizesAvailable').selectorValue) }; @@ -89,7 +91,14 @@ import { Page, expect } from "@playwright/test"; const regEx = /\$\d+\.\d{2}/; const matchPriceText = priceText.match(regEx); console.log("The price of the product -> "+matchPriceText[0]); - const text = (await this.menSectionLocators.productSize().textContent()).trim(); - console.log(text) + const sizeText = (await this.menSectionLocators.productSize().textContent()).trim(); + const getSizes = await this.menSectionLocators.getProductSizesAvailable().count(); + console.log(sizeText+'s' + ' available are: '); + for(let i=1;i<=getSizes;i++){ + const el = await pageFixture.page.locator(getResource('getProductSize').selectorValue.replace('FLAG', i.toString())).allTextContents(); + for (const text of el) { + console.log(''+i +")" + " " + text.trim()); + }; + } }; }; \ No newline at end of file diff --git a/src/test/resources/userShoppingPage.json b/src/test/resources/userShoppingPage.json index 6ff473c..e2bf022 100644 --- a/src/test/resources/userShoppingPage.json +++ b/src/test/resources/userShoppingPage.json @@ -33,6 +33,14 @@ { "elementName": "productSize", "selectorValue": "//div[contains(@class,'swatch-attribute size')]//span[contains(.,'Size')]" + }, + { + "elementName": "getProductSize", + "selectorValue": "//div[contains(@class,'swatch-option text')][FLAG]" + }, + { + "elementName": "getProductSizesAvailable", + "selectorValue": "//div[contains(@class,'swatch-option text')]" } ] } \ No newline at end of file diff --git a/src/test/steps/userShopping.ts b/src/test/steps/userShopping.ts index 56f161e..c19888d 100644 --- a/src/test/steps/userShopping.ts +++ b/src/test/steps/userShopping.ts @@ -14,6 +14,6 @@ When("The products are shown and user navigates to a product.", async function ( await categoryAndProductSectionFacade.selectRandomItem(); }); -When("The price of that product is shown.", async function (){ +When("The price, size of that product is shown.", async function (){ await userShopping.getProductPrice(); }); \ No newline at end of file