Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added sort.spec test #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
12 changes: 8 additions & 4 deletions po/pages/ProductsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import { ProductCard } from "../fragments/ProductCard";
import { BurgerMenuFragment } from "../fragments/BurgerMenuFragment";

export class ProductsPage extends BasePage {
get burgerMenu() {return new BurgerMenuFragment(this.page.locator('#react-burger-menu-btn'))}
// Fragments
get burgerMenu() { return new BurgerMenuFragment(this.page.locator('#react-burger-menu-btn')) };
get dropdown() { return this.page.locator('.product_sort_container') };

productCard(index: number): ProductCard {
return new ProductCard(this.page.locator(`[data-test="inventory-item"]:nth-child(${index})`));
}

// Methods
pageUrl(): string {
return "/inventory.html";
}

async get_prices(): Promise<number[]> {
const priceElements: any = await this.page.locator('.inventory_item_price');
const pricesText = await priceElements.allInnerTexts();
return pricesText.map((price: string) => parseFloat(price.slice(1)));
}
}
18 changes: 13 additions & 5 deletions tests/sort.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { test, expect } from '@playwright/test';

test('Verify user able to sort products from low price to high', async ({ page }) => {
});

import { users } from '../data/testData';
import { test, expect } from '../po/fixtures';

test.describe('Product Card Feature', () => {
test.beforeEach(async ({ loginPage }) => {
await loginPage.open();
await loginPage.login(users.standardUser);
});
test('Verify user able to sort products from low price to high', async ({ productsPage }) => {
const sorted_prices = (await productsPage.get_prices()).sort((a, b) => (a - b))
await productsPage.dropdown.selectOption('Price (low to high)');
await expect(await productsPage.get_prices()).toEqual(sorted_prices);
});
})
Loading