diff --git a/tests/base/devtools.spec.ts b/tests/base/devtools.spec.ts deleted file mode 100644 index 6f546fa..0000000 --- a/tests/base/devtools.spec.ts +++ /dev/null @@ -1,99 +0,0 @@ -import {test as base, expect} from '@playwright/test'; -import {ProductPage} from './fixtures/product.page'; -import {DevTools} from './fixtures/devtools.page'; - -import slugs from './config/slugs.json'; -import selectors from './config/selectors/selectors.json'; - -//TODO: Write gherkin feature descriptions -base.describe('Price checking tests', () => { - - // Test: Configurable Product Input check from PDP to checkout - // test.step: add configurable product to cart, return priceOnPDP and productAmount as variables - // test.step: call function retrieveCheckoutPrices() to go to checkout, retrieve values - // test.step: call function compareRetrievedPrices() to compare price on PDP to price in checkout - - /** - * @feature Simple Product price/amount check from PDP to Checkout - * @given none - * @when I go to a (simple) product page - * @and I add one or more to my cart - * @when I go to the checkout - * @then the amount of the product should be the same - * @and the price in the checkout should equal the price of the product * the amount of the product - */ - base('Simple product input to cart is consistent from PDP to checkout', async ({page}) => { - var productPagePrice: string; - var productPageAmount: string; - var checkoutProductDetails: string[]; - - const devTools = new DevTools(page); - - await base.step('Step: Add simple product to cart', async () =>{ - const productPage = new ProductPage(page); - await page.goto(slugs.productpage.simpleProductSlug); - // set quantity to 2 so we can see that the math works - await page.getByLabel('Quantity').fill('2'); - - productPagePrice = await page.locator(selectors.productPage.simpleProductPrice).innerText(); - productPageAmount = await page.getByLabel(selectors.productPage.quantityFieldLabel).inputValue(); - await productPage.addSimpleProductToCart(); - - }); - - await base.step('Step: go to checkout, get values', async () =>{ - await page.goto(slugs.checkoutSlug); - await page.waitForLoadState(); - - // returns productPriceInCheckout and productQuantityInCheckout - checkoutProductDetails = await devTools.getCheckoutValues(selectors.productPage.simpleProductTitle, productPagePrice, productPageAmount); - }); - - await base.step('Step: Calculate and check expectations', async () =>{ - await devTools.calculateProductPricesAndCompare(productPagePrice, productPageAmount, checkoutProductDetails[0], checkoutProductDetails[1]); - }); - - }); - - /** - * @feature Configurable Product price/amount check from PDP to Checkout - * @given none - * @when I go to a (configurable) product page - * @and I add one or more to my cart - * @when I go to the checkout - * @then the amount of the product should be the same - * @and the price in the checkout should equal the price of the product * the amount of the product - */ - base('Configurable product input to cart is consistent from PDP to checkout', async ({page}) => { - var productPagePrice: string; - var productPageAmount: string; - var checkoutProductDetails: string[]; - - const devTools = new DevTools(page); - - await base.step('Step: Add configurable product to cart', async () =>{ - const productPage = new ProductPage(page); - await page.goto(slugs.productpage.configurableProductSlug); - // set quantity to 2 so we can see that the math works - await page.getByLabel('Quantity').fill('2'); - - productPagePrice = await page.locator(selectors.productPage.simpleProductPrice).innerText(); - productPageAmount = await page.getByLabel(selectors.productPage.quantityFieldLabel).inputValue(); - await productPage.addConfigurableProductToCart(); - - }); - - await base.step('Step: go to checkout, get values', async () =>{ - await page.goto(slugs.checkoutSlug); - await page.waitForLoadState(); - - // returns productPriceInCheckout and productQuantityInCheckout - checkoutProductDetails = await devTools.getCheckoutValues(selectors.productPage.configurableProductTitle, productPagePrice, productPageAmount); - }); - - await base.step('Step: Calculate and check expectations', async () =>{ - await devTools.calculateProductPricesAndCompare(productPagePrice, productPageAmount, checkoutProductDetails[0], checkoutProductDetails[1]); - }); - - }); -}); \ No newline at end of file diff --git a/tests/base/fixtures/devtools.page.ts b/tests/base/fixtures/devtools.page.ts deleted file mode 100644 index 61535ee..0000000 --- a/tests/base/fixtures/devtools.page.ts +++ /dev/null @@ -1,62 +0,0 @@ -import {expect, type Locator, type Page} from '@playwright/test'; - -import selectors from '../config/selectors/selectors.json'; - -export class DevTools{ - readonly page: Page; - productPagePrice: string; - productPageAmount: string; - productQuantityInCheckout: string; - productPriceInCheckout: string; - - constructor(page: Page){ - this.page = page; - } - - async getCheckoutValues(productName:string, pricePDP:string, amountPDP:string){ - // Open minicart based on amount of products in cart - let cartItemAmount = await this.page.locator(selectors.miniCart.minicartAmountBubbleLocator).count(); - if(cartItemAmount == 1) { - await this.page.getByLabel(`${selectors.checkout.openCartButtonLabel} ${cartItemAmount} ${selectors.checkout.openCartButtonLabelCont}`).click(); - } else { - await this.page.getByLabel(`${selectors.checkout.openCartButtonLabel} ${cartItemAmount} ${selectors.checkout.openCartButtonLabelContMultiple}`).click(); - } - - // Get values from checkout page - let productInCheckout = this.page.locator(selectors.checkout.cartDetailsLocator).filter({ hasText: productName }).nth(1); - this.productPriceInCheckout = await productInCheckout.getByText(selectors.general.genericPriceSymbol).innerText(); - this.productPriceInCheckout = this.productPriceInCheckout.trim(); - let productImage = this.page.locator(selectors.checkout.cartDetailsLocator) - .filter({ has: this.page.getByRole('img', { name: productName })}); - this.productQuantityInCheckout = await productImage.locator('> span').innerText(); - - // if(simpleProduct){ - // let simpleProductInCheckout = this.page.locator(selectors.checkout.cartDetailsLocator).filter({ hasText: selectors.productPage.simpleProductTitle }).nth(1); - // this.productPriceInCheckout = await simpleProductInCheckout.getByText(selectors.general.genericPriceSymbol).innerText(); - // this.productPriceInCheckout = this.productPriceInCheckout.trim(); - // let simpleProductImage = this.page.locator(selectors.checkout.cartDetailsLocator) - // .filter({ has: this.page.getByRole('img', { name: selectors.productPage.simpleProductTitle })}); - // this.productQuantityInCheckout = await simpleProductImage.locator('> span').innerText(); - // } else { - // let confProductInCheckout = this.page.locator(selectors.checkout.cartDetailsLocator).filter({ hasText: selectors.productPage.configurableProductTitle }).nth(1); - // this.productPriceInCheckout = await confProductInCheckout.getByText(selectors.general.genericPriceSymbol).innerText(); - // this.productPriceInCheckout = this.productPriceInCheckout.trim(); - // let confProductImage = this.page.locator(selectors.checkout.cartDetailsLocator) - // .filter({ has: this.page.getByRole('img', { name: selectors.productPage.configurableProductTitle })}); - // this.productQuantityInCheckout = await confProductImage.locator('> span').innerText(); - // } - - return [this.productPriceInCheckout, this.productQuantityInCheckout]; - } - - async calculateProductPricesAndCompare(pricePDP: string, amountPDP:string, priceCheckout:string, amountCheckout:string){ - // perform magic to calculate price * amount and mold it into the correct form again - pricePDP = pricePDP.replace(selectors.general.genericPriceSymbol,''); - let pricePDPInt = Number(pricePDP); - let quantityPDPInt = +amountPDP; - let calculatedPricePDP = `${selectors.general.genericPriceSymbol}` + (pricePDPInt * quantityPDPInt).toFixed(2); - - expect(amountPDP,`Amount on PDP (${amountPDP}) equals amount in checkout (${amountCheckout})`).toEqual(amountPDP); - expect(calculatedPricePDP, `Price * qty on PDP (${calculatedPricePDP}) equals price * qty in checkout (${priceCheckout})`).toEqual(priceCheckout); - } -} \ No newline at end of file