diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 0000000..68a09a6 --- /dev/null +++ b/.github/workflows/playwright.yml @@ -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 diff --git a/components/products/productListPage.js b/components/products/productListPage.js deleted file mode 100644 index e69de29..0000000 diff --git a/components/products/productsTable.js b/components/products/productsTable.js deleted file mode 100644 index e69de29..0000000 diff --git a/pages/productsPage.js b/pages/productsPage.js index f771b97..828e511 100644 --- a/pages/productsPage.js +++ b/pages/productsPage.js @@ -1,5 +1,3 @@ -import {expect} from "@playwright/test"; - export default class ProductsPage { constructor(page) { this.page = page; @@ -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}`), @@ -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"); @@ -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}); } @@ -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});