Skip to content
Merged
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
33 changes: 33 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Playwright Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps chromium
- name: Run Playwright tests
run: npx playwright test
env:
USER_EMAIL: ${{ secrets.USER_EMAIL }}
USER_PASSWORD: ${{ secrets.USER_PASSWORD }}
BASE_URL: ${{ secrets.BASE_URL }}

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
Empty file.
Empty file.
89 changes: 0 additions & 89 deletions pages/productsPage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {expect} from "@playwright/test";

export default class ProductsPage {
constructor(page) {
this.page = page;
Expand All @@ -8,21 +6,7 @@ export default class ProductsPage {
this.productSearchInput = page.getByTestId("product-search-input");
this.categoryFilterSelect = page.getByTestId("category-filter-select");
this.supplierFilterSelect = page.getByTestId("supplier-filter-select");
this.clearFiltersButton = page.getByTestId("clear-filters-button");
this.productsCount = page.getByTestId("products-count");
this.currentPage = page.getByTestId("current-page");
this.nextPageButton = page.getByTestId("next-page-button");

this.columnHeaders = {
id: page.getByRole("columnheader", {name: "ID"}),
name: page.getByRole("columnheader", {name: "Nome"}),
price: page.getByRole("columnheader", {name: "Preço"}),
category: page.getByRole("columnheader", {name: "Categoria"}),
supplier: page.getByRole("columnheader", {name: "Fornecedor"}),
actions: page.getByRole("columnheader", {name: "Ações"}),
};

this.productRow = (id) => page.getByTestId(`product-row-${id}`);
this.productCell = {
id: (id) => page.getByTestId(`product-id-${id}`),
name: (id) => page.getByTestId(`product-name-${id}`),
Expand All @@ -40,54 +24,13 @@ export default class ProductsPage {
this.firstEditButton = page.locator('[data-testid^="edit-product-"]').first();
this.firstDeleteButton = page.locator('[data-testid^="delete-product-"]').first();
this.firstViewDetailsButton = page.locator('[data-testid^="view-details-product-"]').first();
this.editButton = page.getByRole("button", {name: "Edit"});
}

async searchProduct(value) {
await this.productSearchInput.fill(value);
}

async filterByCategory(value) {
await this.categoryFilterSelect.waitFor({state: "visible", timeout: 10000});
await expect(this.categoryFilterSelect.locator("option")).not.toHaveCount(0);
await this.categoryFilterSelect.selectOption(value);
}

async filterBySupplier(value) {
await this.supplierFilterSelect.waitFor({state: "visible", timeout: 10000});
await expect(this.supplierFilterSelect.locator("option")).not.toHaveCount(0);
await this.supplierFilterSelect.selectOption(value);
}

async waitForSupplierOptions() {
await this.supplierFilterSelect.waitFor({state: "visible", timeout: 10000});
await expect(this.supplierFilterSelect.locator("option")).not.toHaveCount(0);
}

async clearFilters() {
await this.clearFiltersButton.click();
}

async sortBy(column) {
await this.columnHeaders[column].click();
}

async clickProductCell(id, field) {
await this.productCell[field](id).click();
}

async openProductDetails(id) {
await this.productAction.viewDetails(id).click();
}

async openFirstProductDetails() {
await this.firstViewDetailsButton.click();
}

// AÇÕES DE EDITAR
async editProduct(id) {
await this.productAction.edit(id).click();
}

async editFirstProduct() {
const rows = this.page.locator("table tbody tr");
Expand Down Expand Up @@ -115,34 +58,10 @@ export default class ProductsPage {
await row.getByRole("button", {name: "Edit"}).click();
}

async openEditProduct() {
await this.editButton.click();
}

async deleteProduct(id) {
await this.productAction.delete(id).click();
}

async deleteFirstProduct() {
await this.firstDeleteButton.click();
}

async clickProductsCount() {
await this.productsCount.click();
}

async clickCurrentPage() {
await this.currentPage.click();
}

async goToNextPage() {
await this.nextPageButton.click();
}

getProductRow(id) {
return this.productRow(id);
}

getProductRowByName(productName) {
return this.page.locator("table tbody tr").filter({hasText: productName});
}
Expand All @@ -167,14 +86,6 @@ export default class ProductsPage {
return this.page.locator('[data-testid^="view-details-product-"]').last();
}

getProductCell(id, field) {
return this.productCell[field](id);
}

getProductAction(id, action) {
return this.productAction[action](id);
}

async getLastProductName() {
const rows = this.page.locator('[data-testid^="product-row-"]');
await rows.first().waitFor({state: "visible", timeout: 3000});
Expand Down
Loading