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
6 changes: 3 additions & 3 deletions features/login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Feature: Login Feature
Given I open the "https://www.saucedemo.com/" page

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
Then I should see the login error message "Epic sadface: Sorry, this user has been locked out."

20 changes: 11 additions & 9 deletions features/product.feature
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Feature: Product Feature

Background:
Background:
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 <sort>
Then I will login as 'standard_user'
# TODO: Sort the items by <sort>
# TODO: Validate all 6 items are sorted correctly by price
Examples:
# TODO: extend the datatable to paramterize this test
| sort |
Scenario Outline: Validate product sort by price <sort>

Then I will login as 'standard_user'
Then I sort products by "<sort>"
Then I validate products are sorted correctly by "<sort>"

Examples:
| sort |
| Price (low to high) |
| Price (high to low) |
12 changes: 6 additions & 6 deletions features/purchase.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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!'
Then I select the cart
Then I select checkout
Then I fill checkout information
Then I select continue
Then I select finish
Then I should see purchase success message "Thank you for your order!"
2 changes: 1 addition & 1 deletion package-lock.json

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

9 changes: 8 additions & 1 deletion pages/login.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ export class Login {
await this.page.locator(this.passwordField).fill(this.password)
await this.page.locator(this.loginButton).click()
}
}
public async validateErrorMessage(expectedMessage: string) {
const errorMessage = await this.page.locator('[data-test="error"]').textContent();

if (errorMessage !== expectedMessage) {
throw new Error(`Expected error message to be ${expectedMessage} but found ${errorMessage}`);
}
}
}
93 changes: 91 additions & 2 deletions pages/product.page.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,103 @@
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 addToCart: string =
'button[id="add-to-cart-sauce-labs-backpack"]'

private readonly cart: string =
'.shopping_cart_link'

private readonly checkout: string =
'#checkout'

private readonly firstName: string =
'#first-name'

private readonly lastName: string =
'#last-name'

private readonly zipCode: string =
'#postal-code'

private readonly continueBtn: string =
'#continue'

private readonly finishBtn: string =
'#finish'

private readonly successText: string =
'.complete-header'

constructor(page: Page) {
this.page = page;
this.page = page
}

public async addBackPackToCart() {
await this.page.locator(this.addToCart).click()
}

public async selectCart() {
await this.page.locator(this.cart).click()
}

public async selectCheckout() {
await this.page.locator(this.checkout).click()
}

public async fillCheckoutInformation() {
const firstName = 'Siva'
const lastName = 'Test'
const zip = '12345'

await this.page.locator(this.firstName).fill(firstName)
await this.page.locator(this.lastName).fill(lastName)
await this.page.locator(this.zipCode).fill(zip)
}

public async selectContinue() {
await this.page.locator(this.continueBtn).click()
}

public async selectFinish() {
await this.page.locator(this.finishBtn).click()
}

public async validateSuccessMessage(expected: string) {
const actual = await this.page.locator(this.successText).textContent()

if (actual !== expected) {
throw new Error(`Expected ${expected} but found ${actual}`)
}
}

public async sortProductsBy(sort: string) {
await this.page
.locator('.product_sort_container')
.selectOption({ label: sort })
}

public async validateProductsSortedByPrice(sort: string) {
const prices = await this.page
.locator('.inventory_item_price')
.allTextContents()

const values = prices.map(price =>
Number(price.replace('$', ''))
)

const expected = [...values]

if (sort === 'Price (low to high)') {
expected.sort((a, b) => a - b)
} else {
expected.sort((a, b) => b - a)
}

if (JSON.stringify(values) !== JSON.stringify(expected)) {
throw new Error(`Products not sorted correctly for ${sort}`)
}
}
}
4 changes: 3 additions & 1 deletion playwrightUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const DEFAULT_TIMEOUT = 30000;

export const initializeBrowser = async () => {
if (!browser) {
browser = await chromium.launch({ headless: false });
browser = await chromium.launch({
channel: "chrome"
});
}
};

Expand Down
3 changes: 3 additions & 0 deletions steps/login.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ Then('I should see the title {string}', async (expectedTitle) => {

Then('I will login as {string}', async (userName) => {
await new Login(getPage()).loginAsUser(userName);
});
Then('I should see the login error message {string}', async function (message) {
await new Login(getPage()).validateErrorMessage(message);
});
48 changes: 46 additions & 2 deletions steps/product.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,49 @@ import { getPage } from '../playwrightUtilities';
import { Product } from '../pages/product.page';

Then('I will add the backpack to the cart', async () => {
await new Product(getPage()).addBackPackToCart();
});
await new Product(getPage()).addBackPackToCart();
});

Then('I select the cart', async () => {
await new Product(getPage()).selectCart();
});

Then('I select checkout', async () => {
await new Product(getPage()).selectCheckout();
});

Then('I fill checkout information', async () => {
await new Product(getPage()).fillCheckoutInformation();
});

Then('I select continue', async () => {
await new Product(getPage()).selectContinue();
});

Then('I select finish', async () => {
await new Product(getPage()).selectFinish();
});

Then(
'I should see purchase success message {string}',
async (message) => {
await new Product(getPage())
.validateSuccessMessage(message);
}
);

Then(
'I sort products by {string}',
async (sort) => {
await new Product(getPage())
.sortProductsBy(sort);
}
);

Then(
'I validate products are sorted correctly by {string}',
async (sort) => {
await new Product(getPage())
.validateProductsSortedByPrice(sort);
}
);
Loading