From 864b4c20ff358d28e5d00bec1d91ecd98e7e62b0 Mon Sep 17 00:00:00 2001 From: Shay Date: Mon, 13 Jan 2025 14:49:12 +0100 Subject: [PATCH] Fixed issues with price check tests --- .gitignore | 5 +---- tests/base/cart.spec.ts | 4 ++-- tests/base/config/selectors/selectors.json | 12 +++++------- tests/base/fixtures/product.page.ts | 7 ++++++- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index a6bb688..a0a2464 100644 --- a/.gitignore +++ b/.gitignore @@ -10,10 +10,7 @@ bypass-captcha.config.ts package-lock.json /tests/base/config/test-toggles.json /tests/custom/config/test-toggles.json -/tests/base/updated-account.spec.ts /tests/base/utils/AccountPage.ts .env .vscode -/tests/.auth/ -/tests/base/fixtures/devtools.page.ts -/test/base/devtools.spec.ts \ No newline at end of file +/tests/.auth/ \ No newline at end of file diff --git a/tests/base/cart.spec.ts b/tests/base/cart.spec.ts index 6efcf50..49eedc3 100644 --- a/tests/base/cart.spec.ts +++ b/tests/base/cart.spec.ts @@ -174,11 +174,11 @@ test.describe('Price checking tests', () => { 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'); + await page.getByLabel(selectors.productPage.quantityFieldLabel).fill('2'); productPagePrice = await page.locator(selectors.productPage.simpleProductPrice).innerText(); productPageAmount = await page.getByLabel(selectors.productPage.quantityFieldLabel).inputValue(); - await productPage.addSimpleProductToCart(); + await productPage.addSimpleProductToCart(selectors.productPage.simpleProductTitle, slugs.productpage.simpleProductSlug, '2'); }); diff --git a/tests/base/config/selectors/selectors.json b/tests/base/config/selectors/selectors.json index 42b5cd5..67d306b 100644 --- a/tests/base/config/selectors/selectors.json +++ b/tests/base/config/selectors/selectors.json @@ -81,7 +81,11 @@ "discountInputFieldLabel": "Enter discount code", "continueShoppingLabel": "Continue Shopping", "applyDiscountCodeLabel": "Apply Discount Code", - "remove": "Remove" + "remove": "Remove", + "openCartButtonLabel": "Cart", + "openCartButtonLabelCont": "item", + "openCartButtonLabelContMultiple": "items", + "cartDetailsLocator": "#checkout-cart-details div" }, "miniCart": { "checkOutButtonLabel": "Checkout", @@ -92,12 +96,6 @@ "minicartPriceFieldClass": ".price-excluding-tax .minicart-price .price", "minicartAmountBubbleLocator": "#menu-cart-icon > span" }, - "checkout": { - "openCartButtonLabel": "Cart", - "openCartButtonLabelCont": "item", - "openCartButtonLabelContMultiple": "items", - "cartDetailsLocator": "#checkout-cart-details div" - }, "contactPage": { "messageFieldLabel": "What’s on your mind?" }, diff --git a/tests/base/fixtures/product.page.ts b/tests/base/fixtures/product.page.ts index 753bb66..4985fb8 100644 --- a/tests/base/fixtures/product.page.ts +++ b/tests/base/fixtures/product.page.ts @@ -13,12 +13,17 @@ export class ProductPage { this.simpleProductAddToCartButon = page.getByRole('button', { name: 'shopping-cart Add to Cart' }); } - async addSimpleProductToCart(product: string, url: string){ + async addSimpleProductToCart(product: string, url: string, quantity?: string) { await this.page.goto(url); this.simpleProductTitle = this.page.getByRole('heading', {name: product, exact:true}); let productAddedNotification = `${verify.productPage.simpleProductAddedNotification} ${product}`; await expect(this.simpleProductTitle.locator('span')).toBeVisible(); + + if(quantity){ + // set quantity + await this.page.getByLabel(selectors.productPage.quantityFieldLabel).fill('2'); + } await this.simpleProductAddToCartButon.click(); await expect(this.page.getByText(productAddedNotification)).toBeVisible();