From dc1d18fe56eecf5174485ea2eb5968c73272c2aa Mon Sep 17 00:00:00 2001 From: bharathkorsi Date: Tue, 24 Mar 2026 17:57:00 -0700 Subject: [PATCH] complete cucumber scenarios and improve test coverage --- cucumber_report.html | 2324 +++++++++++++++++++++++++++++++++++++ features/login.feature | 6 +- features/product.feature | 27 +- features/purchase.feature | 12 +- fixes.md | 104 ++ pages/product.page.ts | 85 +- report.json | 627 ++++++++++ steps/login.steps.ts | 12 +- steps/product.steps.ts | 43 + 9 files changed, 3220 insertions(+), 20 deletions(-) create mode 100644 cucumber_report.html create mode 100644 fixes.md create mode 100644 report.json diff --git a/cucumber_report.html b/cucumber_report.html new file mode 100644 index 0000000..ce14f98 --- /dev/null +++ b/cucumber_report.html @@ -0,0 +1,2324 @@ + + + + + Cucumber Feature Report + + + + + + + + + + +
+ +
+
+
+

All Scenarios

+
+
+
+ 7 +
+
+
+
+
+

Passed Scenarios

+
+
+
+ 7 +
+
+
+
+
+

Failed Scenarios

+
+
+
+ 0 +
+
+
+ + + + + +
+
+
+
+
+ +
+

+ Execution Time: 5s 804ms +

+

+ Expand All + | + Collapse All +

+
+ + +
+ +
+
+
+ + +
+
+
+
+ + + + + +
+ + +
+ +
+
+ +
+
+ + + +
+ +
+
+
+ + + + + +

+

+ + + + + + + Given + I open the "https://www.saucedemo.com/" page + + + + 744ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I should see the title "Swag Labs" + + + + 15ms + + + + + + + + + + + + + + + + + + +
+

+ + + + +
+
+
+ + +
+ +
+
+
+ + + + + +

+

+ + + + + + + Given + I open the "https://www.saucedemo.com/" page + + + + 614ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + When + I will login as 'locked_out_user' + + + + 150ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I should see error message as 'Sorry, this user has been locked out.' + + + + 10ms + + + + + + + + + + + + + + + + + + +
+

+ + + + +
+
+
+ +
+
+
+
+ +
+ + + + +
+ +
+
+ +
+
+ + + +
+ +
+
+
+ + + + + +

+

+ + + + + + + Given + I open the "https://www.saucedemo.com/" page + + + + 671ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I will login as 'standard_user' + + + + 157ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I sort the products by "Price (high to low)" + + + + 7ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + the product prices should be sorted "desc" + + + + 13ms + + + + + + + + + + + + + + + + + + +
+

+ + + + +
+
+
+ + +
+ +
+
+
+ + + + + +

+

+ + + + + + + Given + I open the "https://www.saucedemo.com/" page + + + + 665ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I will login as 'standard_user' + + + + 160ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I sort the products by "Price (low to high)" + + + + 12ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + the product prices should be sorted "asc" + + + + 11ms + + + + + + + + + + + + + + + + + + +
+

+ + + + +
+
+
+ + +
+ +
+
+
+ + + + + +

+

+ + + + + + + Given + I open the "https://www.saucedemo.com/" page + + + + 516ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I will login as 'standard_user' + + + + 157ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I will add the backpack to the cart + + + + 35ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + the cart badge count should be "1" + + + + 7ms + + + + + + + + + + + + + + + + + + +
+

+ + + + +
+
+
+ + +
+ +
+
+
+ + + + + +

+

+ + + + + + + Given + I open the "https://www.saucedemo.com/" page + + + + 545ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I will login as 'standard_user' + + + + 174ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I will add the backpack to the cart + + + + 49ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I remove the backpack from the cart + + + + 47ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + the cart badge should not be visible + + + + 2ms + + + + + + + + + + + + + + + + + + +
+

+ + + + +
+
+
+ +
+
+
+
+ +
+ +
+ + + +
+ + +
+ +
+
+ +
+
+ + + +
+ +
+
+
+ + + + + +

+

+ + + + + + + Given + I open the "https://www.saucedemo.com/" page + + + + 509ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I will login as 'standard_user' + + + + 176ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I will add the backpack to the cart + + + + 22ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I click on the cart + + + + 85ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I Select Checkout + + + + 66ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I Fill in the "Jon", "Doe", and "53356" + + + + 22ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I Select Continue + + + + 77ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I Select Finish + + + + 63ms + + + + + + + + + + + + + + + + + + +
+

+ + + +

+

+ + + + + + + Then + I Validate the text 'Thank you for your order!' + + + + 8ms + + + + + + + + + + + + + + + + + + +
+

+ + + + +
+
+
+ +
+
+
+
+ +
+ +
+ + + + +
+ + + + + + + + + + + + diff --git a/features/login.feature b/features/login.feature index fb9f1fa..198cb1e 100644 --- a/features/login.feature +++ b/features/login.feature @@ -5,8 +5,8 @@ Feature: Login Feature Scenario: Validate the login page title # TODO: Fix this failing scenario - Then I should see the title "Labs Swag" + Then I should see the title "Swag Labs" Scenario: Validate login error message - Then I will login as 'locked_out_user' - # TODO: Add a step to validate the error message received \ No newline at end of file + When I will login as 'locked_out_user' + Then I should see error message as 'Sorry, this user has been locked out.' \ No newline at end of file diff --git a/features/product.feature b/features/product.feature index 8a7ceab..9fa8c78 100644 --- a/features/product.feature +++ b/features/product.feature @@ -4,10 +4,23 @@ Feature: Product Feature Given I open the "https://www.saucedemo.com/" page # Create a datatable to validate the Price (high to low) and Price (low to high) sort options (top-right) using a Scenario Outline - Scenario Outline: Validate product sort by price - Then I will login as 'standard_user' - # TODO: Sort the items by - # TODO: Validate all 6 items are sorted correctly by price - Examples: - # TODO: extend the datatable to paramterize this test - | sort | \ No newline at end of file + Scenario Outline: Validate product sort by price + Then I will login as 'standard_user' + Then I sort the products by "" + Then the product prices should be sorted "" + + Examples: + | sort | order | + | Price (high to low) | desc | + | Price (low to high) | asc | + + Scenario: Validate cart badge count after adding backpack + Then I will login as 'standard_user' + Then I will add the backpack to the cart + Then the cart badge count should be "1" + + Scenario: Validate removing backpack from cart + Then I will login as 'standard_user' + Then I will add the backpack to the cart + Then I remove the backpack from the cart + Then the cart badge should not be visible \ No newline at end of file diff --git a/features/purchase.feature b/features/purchase.feature index 2863478..08ee2d6 100644 --- a/features/purchase.feature +++ b/features/purchase.feature @@ -6,9 +6,9 @@ Feature: Purchase Feature Scenario: Validate successful purchase text Then I will login as 'standard_user' Then I will add the backpack to the cart - # TODO: Select the cart (top-right) - # TODO: Select Checkout - # TODO: Fill in the First Name, Last Name, and Zip/Postal Code - # TODO: Select Continue - # TODO: Select Finish - # TODO: Validate the text 'Thank you for your order!' \ No newline at end of file + Then I click on the cart + Then I Select Checkout + Then I Fill in the "Jon", "Doe", and "53356" + Then I Select Continue + Then I Select Finish + Then I Validate the text 'Thank you for your order!' \ No newline at end of file diff --git a/fixes.md b/fixes.md new file mode 100644 index 0000000..836f7c4 --- /dev/null +++ b/fixes.md @@ -0,0 +1,104 @@ + +# ✅ Task Implementation + +## ✔ 1. Fix Login Page Title Scenario + +* **Task:** Modify the scenario *"Validate the login page title"* from [`login.feature`](features/login.feature#8), which was running but failing. + +* **Root Cause:** + The expected page title was incorrect: + + * ❌ Expected: `Labs Swag` + * ✅ Actual: `Swag Labs` + +* **Fix Implemented:** + Updated the Cucumber scenario to validate the correct page title: + + ``` + Swag Labs + ``` + +--- + +## ✔ 2. Extend Login Error Message Scenario + +* **Task:** Extend the scenario *"Validate login error message"* from [`login.feature`](features/login.feature#10), which was missing validation. + +* **Enhancement Implemented:** + Added validation for the error message when logging in with a locked user. + +* **Expected Behavior:** + When logging in with `locked_out_user`, the system should display: + + ``` + Sorry, this user has been locked out. + ``` + +* **Outcome:** + Scenario now validates both: + + * Error visibility + * Correct error message text + +--- + +## ✔ 3. Implement Successful Purchase Flow + +* **Task:** Modify and extend *"Validate successful purchase text"* from [`purchase.feature`](features/purchase.feature#6). + +* **Implementation Details:** + + * Implemented complete end-to-end purchase flow: + + * Login + * Add product to cart + * Open cart + * Checkout + * Enter user details + * Continue + * Finish purchase + * Created: + + * `purchase.steps.ts` + * Updated `product.page.ts` + +* **Validation Added:** + + ``` + Thank you for your order! + ``` + +--- + +## ✔ 4. Implement Product Sorting Validation + +* **Task:** Modify and extend *"Validate product sort by price"* from [`product.feature`](features/product.feature#6). + +* **Implementation Details:** + + * Used **Scenario Outline** with **Examples table** + * Parameterized sorting options: + + * `Price (low to high)` + * `Price (high to low)` + +* **Validation Added:** + + * Verified product prices are correctly sorted: + + * Ascending order + * Descending order + +--- + +## ✔ 5. Extend Test Coverage + +### 🔹 Added Additional Scenarios: + +* **Cart Badge Validation (Add Item)** + + * Verified cart badge count after adding an item + +* **Cart Badge Validation (Remove Item)** + + * Verified cart badge is removed after deleting the item from cart diff --git a/pages/product.page.ts b/pages/product.page.ts index 14bedb1..6ee71c0 100644 --- a/pages/product.page.ts +++ b/pages/product.page.ts @@ -1,8 +1,25 @@ -import { Page } from "@playwright/test" +import { Page, expect } from "@playwright/test" export class Product { private readonly page: Page private readonly addToCart: string = 'button[id="add-to-cart-sauce-labs-backpack"]' + private readonly cartLink = '.shopping_cart_link'; + private readonly checkoutButton = '#checkout'; + + private readonly firstNameField = '#first-name'; + private readonly lastNameField = '#last-name'; + private readonly postalCodeField = '#postal-code'; + private readonly continueButton = '#continue'; + + private readonly finishButton = '#finish'; + private readonly completeHeader = '[data-test="complete-header"]'; + + private readonly sortDropdown = '[data-test="product-sort-container"]'; + private readonly productPrices = '.inventory_item_price'; + + private readonly cartBadge = '.shopping_cart_badge'; + + private readonly removeFromCart = '#remove-sauce-labs-backpack'; constructor(page: Page) { this.page = page; @@ -11,4 +28,68 @@ export class Product { public async addBackPackToCart() { await this.page.locator(this.addToCart).click() } -} \ No newline at end of file + + public async openCart() { + await this.page.locator(this.cartLink).click(); + } + + public async clickCheckout(){ + await this.page.locator(this.checkoutButton).click(); + } + + public async fillPersonalInfo( + firstName: string, + lastName: string, + zipCode: string) { + + await this.page.locator(this.firstNameField).fill(firstName); + await this.page.locator(this.lastNameField).fill(lastName); + await this.page.locator(this.postalCodeField).fill(zipCode); + + } + public async clickContinue(){ + await this.page.locator(this.continueButton).click(); + } + + public async clickFinish() { + await this.page.locator(this.finishButton).click(); + } + + public async validatePurchaseConfirmationText(expectedText: string) { + await expect(this.page.locator(this.completeHeader)).toBeVisible(); + await expect(this.page.locator(this.completeHeader)).toHaveText(expectedText); + } + + public async sortProductsBy(sortOption: string) { + await this.page.locator(this.sortDropdown).selectOption({ label: sortOption }); + } + + public async validatePricesSorted(order: string) { + const priceTexts = await this.page.locator(this.productPrices).allTextContents(); + + const actualPrices = priceTexts.map((text) => + Number(text.replace('$', '').trim()) + ); + + expect(actualPrices).toHaveLength(6); + + const expectedPrices = [...actualPrices].sort((a, b) => + order.toLowerCase() === 'desc' ? b - a : a - b + ); + + expect(actualPrices).toEqual(expectedPrices); + } + + public async validateCartBadgeCount(expectedCount: string) { + await expect(this.page.locator(this.cartBadge)).toBeVisible(); + await expect(this.page.locator(this.cartBadge)).toHaveText(expectedCount); + } + + public async removeBackPackFromCart() { + await this.page.locator(this.removeFromCart).click(); + } + + public async validateCartBadgeNotVisible() { + await expect(this.page.locator(this.cartBadge)).toHaveCount(0); + } +} diff --git a/report.json b/report.json new file mode 100644 index 0000000..492ecde --- /dev/null +++ b/report.json @@ -0,0 +1,627 @@ +[ + { + "description": "", + "elements": [ + { + "description": "", + "id": "login-feature;validate-the-login-page-title", + "keyword": "Scenario", + "line": 6, + "name": "Validate the login page title", + "steps": [ + { + "keyword": "Before", + "hidden": true, + "result": { + "status": "passed", + "duration": 4937120500 + } + }, + { + "arguments": [], + "keyword": "Given ", + "line": 4, + "name": "I open the \"https://www.saucedemo.com/\" page", + "match": { + "location": "steps/common.steps.ts:4" + }, + "result": { + "status": "passed", + "duration": 744628791 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 8, + "name": "I should see the title \"Swag Labs\"", + "match": { + "location": "steps/login.steps.ts:6" + }, + "result": { + "status": "passed", + "duration": 15446541 + } + }, + { + "keyword": "After", + "hidden": true, + "result": { + "status": "passed", + "duration": 198767125 + } + } + ], + "tags": [], + "type": "scenario" + }, + { + "description": "", + "id": "login-feature;validate-login-error-message", + "keyword": "Scenario", + "line": 10, + "name": "Validate login error message", + "steps": [ + { + "keyword": "Before", + "hidden": true, + "result": { + "status": "passed", + "duration": 777205417 + } + }, + { + "arguments": [], + "keyword": "Given ", + "line": 4, + "name": "I open the \"https://www.saucedemo.com/\" page", + "match": { + "location": "steps/common.steps.ts:4" + }, + "result": { + "status": "passed", + "duration": 614181499 + } + }, + { + "arguments": [], + "keyword": "When ", + "line": 11, + "name": "I will login as 'locked_out_user'", + "match": { + "location": "steps/login.steps.ts:10" + }, + "result": { + "status": "passed", + "duration": 150023917 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 12, + "name": "I should see error message as 'Sorry, this user has been locked out.'", + "match": { + "location": "steps/login.steps.ts:14" + }, + "result": { + "status": "passed", + "duration": 10398584 + } + }, + { + "keyword": "After", + "hidden": true, + "result": { + "status": "passed", + "duration": 97095874 + } + } + ], + "tags": [], + "type": "scenario" + } + ], + "id": "login-feature", + "line": 1, + "keyword": "Feature", + "name": "Login Feature", + "tags": [], + "uri": "features/login.feature" + }, + { + "description": "", + "elements": [ + { + "description": "", + "id": "product-feature;validate-product-sort-by-price", + "keyword": "Scenario Outline", + "line": 14, + "name": "Validate product sort by price", + "steps": [ + { + "keyword": "Before", + "hidden": true, + "result": { + "status": "passed", + "duration": 770620832 + } + }, + { + "arguments": [], + "keyword": "Given ", + "line": 4, + "name": "I open the \"https://www.saucedemo.com/\" page", + "match": { + "location": "steps/common.steps.ts:4" + }, + "result": { + "status": "passed", + "duration": 671680333 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 8, + "name": "I will login as 'standard_user'", + "match": { + "location": "steps/login.steps.ts:10" + }, + "result": { + "status": "passed", + "duration": 157319999 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 9, + "name": "I sort the products by \"Price (high to low)\"", + "match": { + "location": "steps/product.steps.ts:32" + }, + "result": { + "status": "passed", + "duration": 7277915 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 10, + "name": "the product prices should be sorted \"desc\"", + "match": { + "location": "steps/product.steps.ts:36" + }, + "result": { + "status": "passed", + "duration": 13003249 + } + }, + { + "keyword": "After", + "hidden": true, + "result": { + "status": "passed", + "duration": 103269250 + } + } + ], + "tags": [], + "type": "scenario" + }, + { + "description": "", + "id": "product-feature;validate-product-sort-by-price", + "keyword": "Scenario Outline", + "line": 15, + "name": "Validate product sort by price", + "steps": [ + { + "keyword": "Before", + "hidden": true, + "result": { + "status": "passed", + "duration": 552708000 + } + }, + { + "arguments": [], + "keyword": "Given ", + "line": 4, + "name": "I open the \"https://www.saucedemo.com/\" page", + "match": { + "location": "steps/common.steps.ts:4" + }, + "result": { + "status": "passed", + "duration": 665872333 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 8, + "name": "I will login as 'standard_user'", + "match": { + "location": "steps/login.steps.ts:10" + }, + "result": { + "status": "passed", + "duration": 160544249 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 9, + "name": "I sort the products by \"Price (low to high)\"", + "match": { + "location": "steps/product.steps.ts:32" + }, + "result": { + "status": "passed", + "duration": 12458875 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 10, + "name": "the product prices should be sorted \"asc\"", + "match": { + "location": "steps/product.steps.ts:36" + }, + "result": { + "status": "passed", + "duration": 11362499 + } + }, + { + "keyword": "After", + "hidden": true, + "result": { + "status": "passed", + "duration": 98737333 + } + } + ], + "tags": [], + "type": "scenario" + }, + { + "description": "", + "id": "product-feature;validate-cart-badge-count-after-adding-backpack", + "keyword": "Scenario", + "line": 17, + "name": "Validate cart badge count after adding backpack", + "steps": [ + { + "keyword": "Before", + "hidden": true, + "result": { + "status": "passed", + "duration": 534571542 + } + }, + { + "arguments": [], + "keyword": "Given ", + "line": 4, + "name": "I open the \"https://www.saucedemo.com/\" page", + "match": { + "location": "steps/common.steps.ts:4" + }, + "result": { + "status": "passed", + "duration": 516216416 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 18, + "name": "I will login as 'standard_user'", + "match": { + "location": "steps/login.steps.ts:10" + }, + "result": { + "status": "passed", + "duration": 157816000 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 19, + "name": "I will add the backpack to the cart", + "match": { + "location": "steps/product.steps.ts:5" + }, + "result": { + "status": "passed", + "duration": 35830249 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 20, + "name": "the cart badge count should be \"1\"", + "match": { + "location": "steps/product.steps.ts:40" + }, + "result": { + "status": "passed", + "duration": 7861750 + } + }, + { + "keyword": "After", + "hidden": true, + "result": { + "status": "passed", + "duration": 75453958 + } + } + ], + "tags": [], + "type": "scenario" + }, + { + "description": "", + "id": "product-feature;validate-removing-backpack-from-cart", + "keyword": "Scenario", + "line": 22, + "name": "Validate removing backpack from cart", + "steps": [ + { + "keyword": "Before", + "hidden": true, + "result": { + "status": "passed", + "duration": 681799208 + } + }, + { + "arguments": [], + "keyword": "Given ", + "line": 4, + "name": "I open the \"https://www.saucedemo.com/\" page", + "match": { + "location": "steps/common.steps.ts:4" + }, + "result": { + "status": "passed", + "duration": 545025000 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 23, + "name": "I will login as 'standard_user'", + "match": { + "location": "steps/login.steps.ts:10" + }, + "result": { + "status": "passed", + "duration": 174691875 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 24, + "name": "I will add the backpack to the cart", + "match": { + "location": "steps/product.steps.ts:5" + }, + "result": { + "status": "passed", + "duration": 49391374 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 25, + "name": "I remove the backpack from the cart", + "match": { + "location": "steps/product.steps.ts:44" + }, + "result": { + "status": "passed", + "duration": 47454750 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 26, + "name": "the cart badge should not be visible", + "match": { + "location": "steps/product.steps.ts:48" + }, + "result": { + "status": "passed", + "duration": 2491667 + } + }, + { + "keyword": "After", + "hidden": true, + "result": { + "status": "passed", + "duration": 108877707 + } + } + ], + "tags": [], + "type": "scenario" + } + ], + "id": "product-feature", + "line": 1, + "keyword": "Feature", + "name": "Product Feature", + "tags": [], + "uri": "features/product.feature" + }, + { + "description": "", + "elements": [ + { + "description": "", + "id": "purchase-feature;validate-successful-purchase-text", + "keyword": "Scenario", + "line": 6, + "name": "Validate successful purchase text", + "steps": [ + { + "keyword": "Before", + "hidden": true, + "result": { + "status": "passed", + "duration": 594350042 + } + }, + { + "arguments": [], + "keyword": "Given ", + "line": 4, + "name": "I open the \"https://www.saucedemo.com/\" page", + "match": { + "location": "steps/common.steps.ts:4" + }, + "result": { + "status": "passed", + "duration": 509194916 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 7, + "name": "I will login as 'standard_user'", + "match": { + "location": "steps/login.steps.ts:10" + }, + "result": { + "status": "passed", + "duration": 176544084 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 8, + "name": "I will add the backpack to the cart", + "match": { + "location": "steps/product.steps.ts:5" + }, + "result": { + "status": "passed", + "duration": 22686832 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 9, + "name": "I click on the cart", + "match": { + "location": "steps/product.steps.ts:9" + }, + "result": { + "status": "passed", + "duration": 85944416 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 10, + "name": "I Select Checkout", + "match": { + "location": "steps/product.steps.ts:13" + }, + "result": { + "status": "passed", + "duration": 66433207 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 11, + "name": "I Fill in the \"Jon\", \"Doe\", and \"53356\"", + "match": { + "location": "steps/product.steps.ts:17" + }, + "result": { + "status": "passed", + "duration": 22386249 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 12, + "name": "I Select Continue", + "match": { + "location": "steps/product.steps.ts:20" + }, + "result": { + "status": "passed", + "duration": 77824500 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 13, + "name": "I Select Finish", + "match": { + "location": "steps/product.steps.ts:24" + }, + "result": { + "status": "passed", + "duration": 63894709 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 14, + "name": "I Validate the text 'Thank you for your order!'", + "match": { + "location": "steps/product.steps.ts:28" + }, + "result": { + "status": "passed", + "duration": 8614084 + } + }, + { + "keyword": "After", + "hidden": true, + "result": { + "status": "passed", + "duration": 91070875 + } + } + ], + "tags": [], + "type": "scenario" + } + ], + "id": "purchase-feature", + "line": 1, + "keyword": "Feature", + "name": "Purchase Feature", + "tags": [], + "uri": "features/purchase.feature" + } +] \ No newline at end of file diff --git a/steps/login.steps.ts b/steps/login.steps.ts index c2aa0d8..6947e01 100644 --- a/steps/login.steps.ts +++ b/steps/login.steps.ts @@ -1,11 +1,19 @@ -import { Then } from '@cucumber/cucumber'; +import { Then, When } from '@cucumber/cucumber'; import { getPage } from '../playwrightUtilities'; import { Login } from '../pages/login.page'; +import { expect } from '@playwright/test'; Then('I should see the title {string}', async (expectedTitle) => { await new Login(getPage()).validateTitle(expectedTitle); }); -Then('I will login as {string}', async (userName) => { +When('I will login as {string}', async (userName) => { await new Login(getPage()).loginAsUser(userName); +}); + +Then('I should see error message as {string}', async (errorMessage) => { + const error = getPage().locator('[data-test="error"]'); + + await expect(error).toBeVisible(); + await expect(error).toContainText(errorMessage); }); \ No newline at end of file diff --git a/steps/product.steps.ts b/steps/product.steps.ts index bb52fb9..c294fdf 100644 --- a/steps/product.steps.ts +++ b/steps/product.steps.ts @@ -4,4 +4,47 @@ import { Product } from '../pages/product.page'; Then('I will add the backpack to the cart', async () => { await new Product(getPage()).addBackPackToCart(); +}); + +Then('I click on the cart',async () => { + await new Product(getPage()).openCart(); +}) + +Then('I Select Checkout',async () => { + await new Product(getPage()).clickCheckout(); +}) + +Then('I Fill in the {string}, {string}, and {string}',async (firstName,lastName, zipCode) => { + await new Product(getPage()).fillPersonalInfo(firstName, lastName, zipCode); +}) +Then('I Select Continue',async () => { + await new Product(getPage()).clickContinue(); +}) + +Then('I Select Finish',async () => { + await new Product(getPage()).clickFinish(); +}) + +Then('I Validate the text {string}',async(expectedConfimationMessage) => { + await new Product(getPage()).validatePurchaseConfirmationText(expectedConfimationMessage); +}); + +Then('I sort the products by {string}', async (sortOption: string) => { + await new Product(getPage()).sortProductsBy(sortOption); +}); + +Then('the product prices should be sorted {string}', async (order: string) => { + await new Product(getPage()).validatePricesSorted(order); +}); + +Then('the cart badge count should be {string}', async (count: string) => { + await new Product(getPage()).validateCartBadgeCount(count); +}); + +Then('I remove the backpack from the cart', async () => { + await new Product(getPage()).removeBackPackFromCart(); +}); + +Then('the cart badge should not be visible', async () => { + await new Product(getPage()).validateCartBadgeNotVisible(); }); \ No newline at end of file