Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions features/login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ 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
# TODO: Add a step to validate the error message received
Then I should see the error message "Epic sadface: Sorry, this user has been locked out."
6 changes: 5 additions & 1 deletion features/product.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Feature: Product Feature
Then I will login as 'standard_user'
# TODO: Sort the items by <sort>
# TODO: Validate all 6 items are sorted correctly by price
And I sort the products by "<sort>"
Then products should be sorted correctly by "<sort>"
Examples:
# TODO: extend the datatable to paramterize this test
| sort |
| sort |
|Price (low to high) |
|Price (high to low) |
9 changes: 9 additions & 0 deletions features/purchase.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ Feature: Purchase Feature
Scenario: Validate successful purchase text
Then I will login as 'standard_user'
Then I will add the backpack to the cart
Then I select the cart
Then I select the checkout
Then I fill the checkout details
Then I select continue
Then I select finish
Then I should see the text "Thank you for your order!"



# TODO: Select the cart (top-right)
# TODO: Select Checkout
# TODO: Fill in the First Name, Last Name, and Zip/Postal Code
Expand Down
11 changes: 6 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@cucumber/pretty-formatter": "^1.0.0",
"@playwright/test": "^1.40.1",
"@types/node": "^20.10.3",
"cucumber-html-reporter": "^7.1.1",
"cucumber-html-reporter": "^7.2.0",
"ts-node": "^10.9.1",
"typescript": "^5.3.2"
}
Expand Down
7 changes: 6 additions & 1 deletion pages/login.page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Page } from "@playwright/test"

export class Login {
private readonly page: Page
private readonly password: string = 'secret_sauce'
private readonly passwordField: string = 'input[id="password"]'
private readonly userNameField: string = 'input[id="user-name"]'
private readonly loginButton: string = 'input[id="login-button"]'
private readonly errorMessage: string ='[data-test="error"]'

constructor(page: Page) {
this.page = page;
Expand All @@ -23,4 +23,9 @@ export class Login {
await this.page.locator(this.passwordField).fill(this.password)
await this.page.locator(this.loginButton).click()
}
public async getErrorMessage(){
return await this.page
.locator(this.errorMessage)
.textContent();
}
}
13 changes: 13 additions & 0 deletions pages/product.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Page } from "@playwright/test"
export class Product {
private readonly page: Page
private readonly addToCart: string = 'button[id="add-to-cart-sauce-labs-backpack"]'
private readonly sortDropdown : string ='.product_sort_container'
private readonly productPrices : string = '.inventory_item_price'

constructor(page: Page) {
this.page = page;
Expand All @@ -11,4 +13,15 @@ export class Product {
public async addBackPackToCart() {
await this.page.locator(this.addToCart).click()
}
public async sortProducts(sortOption: string){
await this.page.selectOption(this.sortDropdown,
{label: sortOption})
}
public async getAllProductPrices(){
const prices = await this.page
.locator(this.productPrices)
.allTextContents();
return prices.map(price =>
parseFloat(price.replace('$',''))
)}
}
38 changes: 38 additions & 0 deletions pages/purchase.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {Page} from "@playwright/test";

export class Purchase {
private readonly page: Page
private readonly cartButton: string ='.shopping_cart_link'
private readonly checkoutButton: string ='#checkout'
private readonly firstName: string ='#first-name'
private readonly lastName: string ='#last-name'
private readonly postalCode: string ='#postal-code'
private readonly continueButton: string ='#continue'
private readonly finishButton: string = '#finish'
private readonly successMessage: string = '.complete-header'

constructor(page: Page){
this.page = page;
}
public async openCart(){
await this.page.locator(this.cartButton).click();
}
public async clickCheckout(){
await this.page.locator(this.checkoutButton).click();
}
public async fillCheckoutDetails(){
await this.page.locator(this.firstName).fill('Praveen');
await this.page.locator(this.lastName).fill('Kumar');
await this.page.locator(this.postalCode).fill('600001');
}
public async clickContinue(){
await this.page.locator(this.continueButton).click();
}
public async clickFinish(){
await this.page.locator(this.finishButton).click();
}
public async getSuccessMessage(){
return await this.page.locator(this.successMessage)
.textContent();
}
}
Loading
Loading