From 7bb6aa3abce3e7ddacbfce7f112c3361a8367caa Mon Sep 17 00:00:00 2001 From: Renata Valois Date: Thu, 8 Aug 2024 15:51:46 -0300 Subject: [PATCH 1/9] =?UTF-8?q?modifica=C3=A7=C3=B5es=20gerais=20no=20c?= =?UTF-8?q?=C3=B3digo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 9 ++++--- README.md | 61 ++++++++++++++++++++++++++++++++------------ package-lock.json | 19 ++++++++++++++ package.json | 24 +++++++++++++---- playwright.config.js | 4 +-- 5 files changed, 89 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 07919b8..279dbd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ node_modules/ -/test-results/ -/playwright-report/ -/blob-report/ -/playwright/.cache/ +test-results/ +playwright-report/ +blob-report/ +playwright/.cache/ .env +tests-examples \ No newline at end of file diff --git a/README.md b/README.md index 49797f4..caf2afb 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,60 @@ -# TEM VAGA, MESTRE? +![Logo Tem Vaga Mestre?](https://imgur.com/HisaR2D.png) + +A plataforma que conecta a comunidade RPG, valorizando a simplicidade, a diversidade e a paixão pelo jogo. + ## Descrição -Este projeto será uma framework de automação de teste para o projeto 'Tem Vaga, Mestre?' com o objetivo de validar testes de front-end e back-end +Este projeto será uma framework de automação de teste para o projeto 'Tem Vaga Mestre?' com o objetivo de validar testes de front-end e back-end -### Tecnologias +### Tecnologias utilizadas -- Playwrite -- Node +[![JavaScript Badge](https://img.shields.io/badge/JavaScript-F7DF1E?style=flat-square&logo=javascript&logoColor=black)](https://developer.mozilla.org/pt-BR/docs/Web/JavaScript) +[![Node.js Badge](https://img.shields.io/badge/Node.js-43853D?style=flat-square&logo=node.js&logoColor=white)](https://nodejs.org/pt) +[![Playwright Badge](https://img.shields.io/badge/Playwright-45ba4b?style=flat-sqare&logo=Playwright&logoColor=white)](https://playwright.dev/) ### Tarefas + - [x] Instalação e configuração -- [ ] Abrir browser e acessar a tela de perfil +- [x] Abrir browser e acessar a tela de perfil +- [x] Fazer o rastreio e validação de conteúdo de objetos da tela de perfil +- [ ] Acessar a tela de cadastro de jogador +- [ ] Validar os campos do cadastro de jogador +- [ ] Realizar os testes de back-end +### Como executar os testes -### Colaboradores: -- Bruno -- Jéssica -- Renata +Execute esse comando para rodar os testes + +`npx playwright test` + +Execute esse comando para rodar os testes de forma visual + +`npx playwright test --ui` ### Links úteis + [Documentação Playwrigth](https://playwright.dev/) [Ambiente de testes](https://frontend-nnf7bytugq-uc.a.run.app/) -### Como executar os testes -Execute esse comando para rodar os testes - -```npx playwright test``` - -Execute esse comando para rodar os testes de forma visual +### Colaboradores: -```npx playwright test --ui``` \ No newline at end of file +- Bruno Machado: + [![Github](https://img.shields.io/badge/brunomachadors-100000?style=flat-square&logo=github&logoColor=white&link=https://github.com/brunomachadors)](https://github.com/brunomachadors) + [![Gmail](https://img.shields.io/badge/-brunomachadors@gmail.com-c14438?style=flat-square&logo=Gmail&logoColor=white&link=mailto:brunomachadors@gmail.com)](mailto:brunomachadors@gmail.com) + [![Linkedin](https://img.shields.io/badge/-brunomrs-blue?style=flat-square&logo=Linkedin&logoColor=white&link=https://www.linkedin.com/in/brunomrs/)](https://www.linkedin.com/in/brunomrs/) + +- Jéssica Ferraz: + [![Github](https://img.shields.io/badge/JessieFerraz-100000?style=flat-square&logo=github&logoColor=white&link=https://github.com/JessieFerraz)](https://github.com/JessieFerraz) + [![Gmail](https://img.shields.io/badge/-jessieferraz@gmail.com-c14438?style=flat-square&logo=Gmail&logoColor=white&link=mailto:jessieferraz@gmail.com)](mailto:jessieferraz@gmail.com) + [![Linkedin](https://img.shields.io/badge/-jessieferraz-blue?style=flat-square&logo=Linkedin&logoColor=white&link=https://www.linkedin.com/in/jessieferraz/)](https://www.linkedin.com/in/jessieferraz/) + +- Raquel Gomes: + [![Github](https://img.shields.io/badge/RaquelGomes25-100000?style=flat-square&logo=github&logoColor=white&link=https://github.com/RaquelGomes25)](https://github.com/RaquelGomes25) + [![Gmail](https://img.shields.io/badge/-kelmaria25@gmail.com-c14438?style=flat-square&logo=Gmail&logoColor=white&link=mailto:kelmaria25@gmail.com)](mailto:kelmaria25@gmail.com) + [![Linkedin](https://img.shields.io/badge/-rakelmaria-blue?style=flat-square&logo=Linkedin&logoColor=white&link=https://www.linkedin.com/in/rakelmaria/)](https://www.linkedin.com/in/rakelmaria/) + +- Renata Valois: + [![Github](https://img.shields.io/badge/revalois-100000?style=flat-square&logo=github&logoColor=white&https://github.com/revalois)](https://github.com/revalois) + [![Gmail](https://img.shields.io/badge/-renata.rsv9@gmail.com-c14438?style=flat-square&logo=Gmail&logoColor=white&link=mailto:renata.rsv9@gmail.com)](mailto:renata.rsv9@gmail.com) + [![Linkedin](https://img.shields.io/badge/-renatavalois-blue?style=flat-square&logo=Linkedin&logoColor=white&link=https://www.linkedin.com/in//renata-valois-42043357/)](https://www.linkedin.com/in//renata-valois-42043357/) diff --git a/package-lock.json b/package-lock.json index d96c5e9..23fbb28 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "temvagamestre.teste", "version": "1.0.0", "license": "ISC", + "dependencies": { + "dotenv": "^16.4.5" + }, "devDependencies": { "@playwright/test": "^1.43.1", "@types/node": "^20.12.7" @@ -37,6 +40,17 @@ "undici-types": "~5.26.4" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/fsevents": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", @@ -107,6 +121,11 @@ "undici-types": "~5.26.4" } }, + "dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==" + }, "fsevents": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", diff --git a/package.json b/package.json index 4daee57..9f99ff4 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,29 @@ { "name": "temvagamestre.teste", "version": "1.0.0", - "description": "Este projeto será uma framework de automação de teste para o projeto 'Tem Vaga, Mestre?' com o objetivo de validar testes de front-end e back-end", + "description": "Este projeto será uma framework de automação de teste para o projeto 'Tem Vaga Mestre?' com o objetivo de validar testes de front-end e back-end", "main": "index.js", - "scripts": {}, + "scripts": { + "test": "npx playwright test" + }, "repository": { "type": "git", "url": "git+https://github.com/Quest-Finder/temvagamestre.teste.git" }, "keywords": [], "authors": [ - {"name": "Bruno Machado"}, - {"name": "Jéssica Ferraz"}, - {"name": "Renata Valois"} + { + "name": "Bruno Machado" + }, + { + "name": "Jéssica Ferraz" + }, + { + "name": "Raquel Gomes" + }, + { + "name": "Renata Valois" + } ], "license": "ISC", "bugs": { @@ -22,5 +33,8 @@ "devDependencies": { "@playwright/test": "^1.43.1", "@types/node": "^20.12.7" + }, + "dependencies": { + "dotenv": "^16.4.5" } } diff --git a/playwright.config.js b/playwright.config.js index 0137e5e..c9cd016 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -1,5 +1,6 @@ // @ts-check const { defineConfig, devices } = require('@playwright/test'); +require('dotenv').config(); /** * Read environment variables from file. @@ -25,7 +26,7 @@ module.exports = defineConfig({ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: 'https://frontend-nnf7bytugq-uc.a.run.app/', + baseURL: process.env.URL, /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', @@ -76,4 +77,3 @@ module.exports = defineConfig({ // reuseExistingServer: !process.env.CI, // }, }); - From ddb55584dec30f205a8af40a0fa10622ecf435eb Mon Sep 17 00:00:00 2001 From: Renata Valois Date: Thu, 8 Aug 2024 16:33:35 -0300 Subject: [PATCH 2/9] =?UTF-8?q?add=20keywords,=20exclus=C3=A3o=20tests-exa?= =?UTF-8?q?mples,=20refatora=C3=A7=C3=A3o=20arquivos=20de=20teste=20e=20ob?= =?UTF-8?q?jetos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- package.json | 6 +- pages/perfil.js | 72 +++-- tests-examples/demo-todo-app.spec.js | 449 --------------------------- tests/perfil.spec.js | 20 +- 5 files changed, 70 insertions(+), 480 deletions(-) delete mode 100644 tests-examples/demo-todo-app.spec.js diff --git a/.gitignore b/.gitignore index 279dbd5..cfd4cc1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ test-results/ playwright-report/ blob-report/ playwright/.cache/ -.env -tests-examples \ No newline at end of file +.env \ No newline at end of file diff --git a/package.json b/package.json index 9f99ff4..238be5f 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,11 @@ "type": "git", "url": "git+https://github.com/Quest-Finder/temvagamestre.teste.git" }, - "keywords": [], + "keywords": [ + "temvagamestre", + "playwright", + "javascript" + ], "authors": [ { "name": "Bruno Machado" diff --git a/pages/perfil.js b/pages/perfil.js index 141e7bf..02dd283 100644 --- a/pages/perfil.js +++ b/pages/perfil.js @@ -9,6 +9,9 @@ exports.PerfilPage = class PerfilPage { async goto() { await this.page.goto(PATH.perfil); } + async validateTitle() { + await expect(this.page).toHaveTitle(/Tem Vaga Mestre/); + } async clicarExtenderBio() { const extenderBioButton = { role: 'button', name: 'Ver mais' }; @@ -29,15 +32,28 @@ exports.PerfilPage = class PerfilPage { await expect(this.page.getByText(bio)).toHaveText(bio); } - async validarTitulo() { - await expect(this.page).toHaveTitle(/Tem Vaga Mestre/); + async validateTitleEstilosPreferidos() { + const tituloEstilosPreferidos = { + role: 'heading', + name: 'Estilos preferidos', + }; + await expect( + this.page.getByRole(tituloEstilosPreferidos.role, { + name: tituloEstilosPreferidos.name, + }) + ).toBeVisible(); } - async validarEstilosPreferidos() { - const estilosPreferidos = "(//h1[contains(.,'Estilos preferidos')])[1]"; - await expect(this.page.locator(estilosPreferidos)).toBeVisible(); + async validarEstilosDeJogoEscolhidos(estilos) { + estilos.forEach(async (estilo) => { + const localizador = "//span[@title='" + estilo + "']"; + await expect(this.page.locator(localizador)).toBeVisible(); + + await expect(this.page.locator(localizador)).toHaveText(estilo); + }); } - async validarTituloConquistas() { + + async validateTitleConquistas() { const conquistas = { role: 'heading', name: 'Conquistas' }; await expect( this.page.getByRole(conquistas.role, { name: conquistas.name }) @@ -54,25 +70,43 @@ exports.PerfilPage = class PerfilPage { } async validarNome(nome) { - const nomeUsuario = "//h2[contains(.,'Lucas Marcelo')]"; - await expect(this.page.locator(nomeUsuario)).toBeVisible(); - await expect(this.page.locator(nomeUsuario)).toHaveText(nome); + const nomeUsuario = { role: 'heading', name: nome }; + await expect( + this.page.getByRole(nomeUsuario.role, { name: nomeUsuario.name }) + ).toBeVisible(); + await expect( + this.page.getByRole(nomeUsuario.role, { name: nomeUsuario.name }) + ).toHaveText(nome); } - async validarPronome() { - const pronomeUsuario = "//h2[contains(.,'(Ele - Dele)')]"; - await expect(this.page.locator(pronomeUsuario)).toBeVisible(); + async validarPronome(pronome) { + const pronomeUsuario = { role: 'heading', name: `(${pronome})` }; + await expect( + this.page.getByRole(pronomeUsuario.role, { name: pronomeUsuario.name }) + ).toBeVisible(); + await expect( + this.page.getByRole(pronomeUsuario.role, { name: pronomeUsuario.name }) + ).toHaveText(pronomeUsuario.name); } - async validarUsername() { - const username = "//h2[contains(.,'@mestremarcelo')]"; - await expect(this.page.locator(username)).toBeVisible(); + async validarUsername(username) { + const usernamePerfil = { role: 'heading', name: username }; + await expect( + this.page.getByRole(usernamePerfil.role, { name: usernamePerfil.name }) + ).toBeVisible(); + await expect( + this.page.getByRole(usernamePerfil.role, { name: usernamePerfil.name }) + ).toHaveText(username); } - async validarUserTitle() { - const userTitle = - "//h2[contains(.,'Mestre D&D com 15 anos de experiência')]"; - await expect(this.page.locator(userTitle)).toBeVisible(); + async validarUserTitle(titulo) { + const userTitle = { role: 'heading', name: titulo }; + await expect( + this.page.getByRole(userTitle.role, { name: userTitle.name }) + ).toBeVisible(); + await expect( + this.page.getByRole(userTitle.role, { name: userTitle.name }) + ).toHaveText(titulo); } async validarLocalResidencia(cidade, pais) { diff --git a/tests-examples/demo-todo-app.spec.js b/tests-examples/demo-todo-app.spec.js deleted file mode 100644 index e2eb87c..0000000 --- a/tests-examples/demo-todo-app.spec.js +++ /dev/null @@ -1,449 +0,0 @@ -// @ts-check -const { test, expect } = require('@playwright/test'); - -test.beforeEach(async ({ page }) => { - await page.goto('https://demo.playwright.dev/todomvc'); -}); - -const TODO_ITEMS = [ - 'buy some cheese', - 'feed the cat', - 'book a doctors appointment' -]; - -test.describe('New Todo', () => { - test('should allow me to add todo items', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // Create 1st todo. - await newTodo.fill(TODO_ITEMS[0]); - await newTodo.press('Enter'); - - // Make sure the list only has one todo item. - await expect(page.getByTestId('todo-title')).toHaveText([ - TODO_ITEMS[0] - ]); - - // Create 2nd todo. - await newTodo.fill(TODO_ITEMS[1]); - await newTodo.press('Enter'); - - // Make sure the list now has two todo items. - await expect(page.getByTestId('todo-title')).toHaveText([ - TODO_ITEMS[0], - TODO_ITEMS[1] - ]); - - await checkNumberOfTodosInLocalStorage(page, 2); - }); - - test('should clear text input field when an item is added', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // Create one todo item. - await newTodo.fill(TODO_ITEMS[0]); - await newTodo.press('Enter'); - - // Check that input is empty. - await expect(newTodo).toBeEmpty(); - await checkNumberOfTodosInLocalStorage(page, 1); - }); - - test('should append new items to the bottom of the list', async ({ page }) => { - // Create 3 items. - await createDefaultTodos(page); - - // create a todo count locator - const todoCount = page.getByTestId('todo-count') - - // Check test using different methods. - await expect(page.getByText('3 items left')).toBeVisible(); - await expect(todoCount).toHaveText('3 items left'); - await expect(todoCount).toContainText('3'); - await expect(todoCount).toHaveText(/3/); - - // Check all items in one call. - await expect(page.getByTestId('todo-title')).toHaveText(TODO_ITEMS); - await checkNumberOfTodosInLocalStorage(page, 3); - }); -}); - -test.describe('Mark all as completed', () => { - test.beforeEach(async ({ page }) => { - await createDefaultTodos(page); - await checkNumberOfTodosInLocalStorage(page, 3); - }); - - test.afterEach(async ({ page }) => { - await checkNumberOfTodosInLocalStorage(page, 3); - }); - - test('should allow me to mark all items as completed', async ({ page }) => { - // Complete all todos. - await page.getByLabel('Mark all as complete').check(); - - // Ensure all todos have 'completed' class. - await expect(page.getByTestId('todo-item')).toHaveClass(['completed', 'completed', 'completed']); - await checkNumberOfCompletedTodosInLocalStorage(page, 3); - }); - - test('should allow me to clear the complete state of all items', async ({ page }) => { - const toggleAll = page.getByLabel('Mark all as complete'); - // Check and then immediately uncheck. - await toggleAll.check(); - await toggleAll.uncheck(); - - // Should be no completed classes. - await expect(page.getByTestId('todo-item')).toHaveClass(['', '', '']); - }); - - test('complete all checkbox should update state when items are completed / cleared', async ({ page }) => { - const toggleAll = page.getByLabel('Mark all as complete'); - await toggleAll.check(); - await expect(toggleAll).toBeChecked(); - await checkNumberOfCompletedTodosInLocalStorage(page, 3); - - // Uncheck first todo. - const firstTodo = page.getByTestId('todo-item').nth(0); - await firstTodo.getByRole('checkbox').uncheck(); - - // Reuse toggleAll locator and make sure its not checked. - await expect(toggleAll).not.toBeChecked(); - - await firstTodo.getByRole('checkbox').check(); - await checkNumberOfCompletedTodosInLocalStorage(page, 3); - - // Assert the toggle all is checked again. - await expect(toggleAll).toBeChecked(); - }); -}); - -test.describe('Item', () => { - - test('should allow me to mark items as complete', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // Create two items. - for (const item of TODO_ITEMS.slice(0, 2)) { - await newTodo.fill(item); - await newTodo.press('Enter'); - } - - // Check first item. - const firstTodo = page.getByTestId('todo-item').nth(0); - await firstTodo.getByRole('checkbox').check(); - await expect(firstTodo).toHaveClass('completed'); - - // Check second item. - const secondTodo = page.getByTestId('todo-item').nth(1); - await expect(secondTodo).not.toHaveClass('completed'); - await secondTodo.getByRole('checkbox').check(); - - // Assert completed class. - await expect(firstTodo).toHaveClass('completed'); - await expect(secondTodo).toHaveClass('completed'); - }); - - test('should allow me to un-mark items as complete', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // Create two items. - for (const item of TODO_ITEMS.slice(0, 2)) { - await newTodo.fill(item); - await newTodo.press('Enter'); - } - - const firstTodo = page.getByTestId('todo-item').nth(0); - const secondTodo = page.getByTestId('todo-item').nth(1); - const firstTodoCheckbox = firstTodo.getByRole('checkbox'); - - await firstTodoCheckbox.check(); - await expect(firstTodo).toHaveClass('completed'); - await expect(secondTodo).not.toHaveClass('completed'); - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - - await firstTodoCheckbox.uncheck(); - await expect(firstTodo).not.toHaveClass('completed'); - await expect(secondTodo).not.toHaveClass('completed'); - await checkNumberOfCompletedTodosInLocalStorage(page, 0); - }); - - test('should allow me to edit an item', async ({ page }) => { - await createDefaultTodos(page); - - const todoItems = page.getByTestId('todo-item'); - const secondTodo = todoItems.nth(1); - await secondTodo.dblclick(); - await expect(secondTodo.getByRole('textbox', { name: 'Edit' })).toHaveValue(TODO_ITEMS[1]); - await secondTodo.getByRole('textbox', { name: 'Edit' }).fill('buy some sausages'); - await secondTodo.getByRole('textbox', { name: 'Edit' }).press('Enter'); - - // Explicitly assert the new text value. - await expect(todoItems).toHaveText([ - TODO_ITEMS[0], - 'buy some sausages', - TODO_ITEMS[2] - ]); - await checkTodosInLocalStorage(page, 'buy some sausages'); - }); -}); - -test.describe('Editing', () => { - test.beforeEach(async ({ page }) => { - await createDefaultTodos(page); - await checkNumberOfTodosInLocalStorage(page, 3); - }); - - test('should hide other controls when editing', async ({ page }) => { - const todoItem = page.getByTestId('todo-item').nth(1); - await todoItem.dblclick(); - await expect(todoItem.getByRole('checkbox')).not.toBeVisible(); - await expect(todoItem.locator('label', { - hasText: TODO_ITEMS[1], - })).not.toBeVisible(); - await checkNumberOfTodosInLocalStorage(page, 3); - }); - - test('should save edits on blur', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).dblclick(); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill('buy some sausages'); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).dispatchEvent('blur'); - - await expect(todoItems).toHaveText([ - TODO_ITEMS[0], - 'buy some sausages', - TODO_ITEMS[2], - ]); - await checkTodosInLocalStorage(page, 'buy some sausages'); - }); - - test('should trim entered text', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).dblclick(); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill(' buy some sausages '); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).press('Enter'); - - await expect(todoItems).toHaveText([ - TODO_ITEMS[0], - 'buy some sausages', - TODO_ITEMS[2], - ]); - await checkTodosInLocalStorage(page, 'buy some sausages'); - }); - - test('should remove the item if an empty text string was entered', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).dblclick(); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill(''); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).press('Enter'); - - await expect(todoItems).toHaveText([ - TODO_ITEMS[0], - TODO_ITEMS[2], - ]); - }); - - test('should cancel edits on escape', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).dblclick(); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill('buy some sausages'); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).press('Escape'); - await expect(todoItems).toHaveText(TODO_ITEMS); - }); -}); - -test.describe('Counter', () => { - test('should display the current number of todo items', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // create a todo count locator - const todoCount = page.getByTestId('todo-count') - - await newTodo.fill(TODO_ITEMS[0]); - await newTodo.press('Enter'); - await expect(todoCount).toContainText('1'); - - await newTodo.fill(TODO_ITEMS[1]); - await newTodo.press('Enter'); - await expect(todoCount).toContainText('2'); - - await checkNumberOfTodosInLocalStorage(page, 2); - }); -}); - -test.describe('Clear completed button', () => { - test.beforeEach(async ({ page }) => { - await createDefaultTodos(page); - }); - - test('should display the correct text', async ({ page }) => { - await page.locator('.todo-list li .toggle').first().check(); - await expect(page.getByRole('button', { name: 'Clear completed' })).toBeVisible(); - }); - - test('should remove completed items when clicked', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).getByRole('checkbox').check(); - await page.getByRole('button', { name: 'Clear completed' }).click(); - await expect(todoItems).toHaveCount(2); - await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[2]]); - }); - - test('should be hidden when there are no items that are completed', async ({ page }) => { - await page.locator('.todo-list li .toggle').first().check(); - await page.getByRole('button', { name: 'Clear completed' }).click(); - await expect(page.getByRole('button', { name: 'Clear completed' })).toBeHidden(); - }); -}); - -test.describe('Persistence', () => { - test('should persist its data', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - for (const item of TODO_ITEMS.slice(0, 2)) { - await newTodo.fill(item); - await newTodo.press('Enter'); - } - - const todoItems = page.getByTestId('todo-item'); - const firstTodoCheck = todoItems.nth(0).getByRole('checkbox'); - await firstTodoCheck.check(); - await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[1]]); - await expect(firstTodoCheck).toBeChecked(); - await expect(todoItems).toHaveClass(['completed', '']); - - // Ensure there is 1 completed item. - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - - // Now reload. - await page.reload(); - await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[1]]); - await expect(firstTodoCheck).toBeChecked(); - await expect(todoItems).toHaveClass(['completed', '']); - }); -}); - -test.describe('Routing', () => { - test.beforeEach(async ({ page }) => { - await createDefaultTodos(page); - // make sure the app had a chance to save updated todos in storage - // before navigating to a new view, otherwise the items can get lost :( - // in some frameworks like Durandal - await checkTodosInLocalStorage(page, TODO_ITEMS[0]); - }); - - test('should allow me to display active items', async ({ page }) => { - const todoItem = page.getByTestId('todo-item'); - await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); - - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - await page.getByRole('link', { name: 'Active' }).click(); - await expect(todoItem).toHaveCount(2); - await expect(todoItem).toHaveText([TODO_ITEMS[0], TODO_ITEMS[2]]); - }); - - test('should respect the back button', async ({ page }) => { - const todoItem = page.getByTestId('todo-item'); - await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); - - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - - await test.step('Showing all items', async () => { - await page.getByRole('link', { name: 'All' }).click(); - await expect(todoItem).toHaveCount(3); - }); - - await test.step('Showing active items', async () => { - await page.getByRole('link', { name: 'Active' }).click(); - }); - - await test.step('Showing completed items', async () => { - await page.getByRole('link', { name: 'Completed' }).click(); - }); - - await expect(todoItem).toHaveCount(1); - await page.goBack(); - await expect(todoItem).toHaveCount(2); - await page.goBack(); - await expect(todoItem).toHaveCount(3); - }); - - test('should allow me to display completed items', async ({ page }) => { - await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - await page.getByRole('link', { name: 'Completed' }).click(); - await expect(page.getByTestId('todo-item')).toHaveCount(1); - }); - - test('should allow me to display all items', async ({ page }) => { - await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - await page.getByRole('link', { name: 'Active' }).click(); - await page.getByRole('link', { name: 'Completed' }).click(); - await page.getByRole('link', { name: 'All' }).click(); - await expect(page.getByTestId('todo-item')).toHaveCount(3); - }); - - test('should highlight the currently applied filter', async ({ page }) => { - await expect(page.getByRole('link', { name: 'All' })).toHaveClass('selected'); - - //create locators for active and completed links - const activeLink = page.getByRole('link', { name: 'Active' }); - const completedLink = page.getByRole('link', { name: 'Completed' }); - await activeLink.click(); - - // Page change - active items. - await expect(activeLink).toHaveClass('selected'); - await completedLink.click(); - - // Page change - completed items. - await expect(completedLink).toHaveClass('selected'); - }); -}); - -async function createDefaultTodos(page) { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - for (const item of TODO_ITEMS) { - await newTodo.fill(item); - await newTodo.press('Enter'); - } -} - -/** - * @param {import('@playwright/test').Page} page - * @param {number} expected - */ - async function checkNumberOfTodosInLocalStorage(page, expected) { - return await page.waitForFunction(e => { - return JSON.parse(localStorage['react-todos']).length === e; - }, expected); -} - -/** - * @param {import('@playwright/test').Page} page - * @param {number} expected - */ - async function checkNumberOfCompletedTodosInLocalStorage(page, expected) { - return await page.waitForFunction(e => { - return JSON.parse(localStorage['react-todos']).filter(i => i.completed).length === e; - }, expected); -} - -/** - * @param {import('@playwright/test').Page} page - * @param {string} title - */ -async function checkTodosInLocalStorage(page, title) { - return await page.waitForFunction(t => { - return JSON.parse(localStorage['react-todos']).map(i => i.title).includes(t); - }, title); -} diff --git a/tests/perfil.spec.js b/tests/perfil.spec.js index f9314d5..1fa70f4 100644 --- a/tests/perfil.spec.js +++ b/tests/perfil.spec.js @@ -1,20 +1,20 @@ const { test } = require('@playwright/test'); import { PerfilPage } from '../pages/perfil.js'; -import { CONQUISTAS, PERFIL } from '../utils/constants.js'; +import { PERFIL } from '../utils/constants.js'; test('Acessar perfil', async ({ page }) => { const perfilPage = new PerfilPage(page); await perfilPage.goto(); - await perfilPage.validarTitulo(); + await perfilPage.validateTitle(); }); test('Validar dados do usuário', async ({ page }) => { const perfilPage = new PerfilPage(page); await perfilPage.goto(); await perfilPage.validarNome(PERFIL.jogador.nome); - await perfilPage.validarPronome(); - await perfilPage.validarUsername(); - await perfilPage.validarUserTitle(); + await perfilPage.validarPronome(PERFIL.jogador.pronome); + await perfilPage.validarUsername(PERFIL.jogador.username); + await perfilPage.validarUserTitle(PERFIL.jogador.titulo); await perfilPage.validarLocalResidencia( PERFIL.jogador.cidade, PERFIL.jogador.pais @@ -24,11 +24,13 @@ test('Validar dados do usuário', async ({ page }) => { test('Validar Estilos de jogo e Conquistas', async ({ page }) => { const perfilPage = new PerfilPage(page); - const conquistas = [CONQUISTAS.reiDasRolagens, CONQUISTAS.mestreRaiz]; await perfilPage.goto(); - await perfilPage.validarEstilosPreferidos(); - await perfilPage.validarTituloConquistas(); - await perfilPage.validarInsigniasRecebidas(conquistas); + await perfilPage.validarEstilosDeJogoEscolhidos( + PERFIL.jogador.estilosPreferidos + ); + await perfilPage.validateTitleEstilosPreferidos(); + await perfilPage.validateTitleConquistas(); + await perfilPage.validarInsigniasRecebidas(PERFIL.jogador.conquistas); }); test('Validar Bio', async ({ page }) => { From 8d8b76cc257d61dd5d9022f428f785c02cb50673 Mon Sep 17 00:00:00 2001 From: Renata Valois Date: Thu, 8 Aug 2024 16:35:51 -0300 Subject: [PATCH 3/9] =?UTF-8?q?altera=C3=A7=C3=A3o=20de=20texto=20de=20pro?= =?UTF-8?q?nome?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/constants.js b/utils/constants.js index 39f0a97..173d941 100644 --- a/utils/constants.js +++ b/utils/constants.js @@ -23,7 +23,7 @@ export const CONQUISTAS = { export const PERFIL = { jogador: { nome: 'Lucas Marcelo', - pronome: 'Ele-Dele', + pronome: 'Ele - Dele', username: '@mestremarcelo', titulo: 'Mestre D&D com 15 anos de experiência', cidade: 'São Paulo', From f49abf0548cd7e5df5a8a4c79c669f3b9dc55de3 Mon Sep 17 00:00:00 2001 From: Renata Valois Date: Fri, 9 Aug 2024 13:51:13 -0300 Subject: [PATCH 4/9] =?UTF-8?q?fix=20vari=C3=A1vel=20de=20ambiente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/playwright.yml | 38 +++++++++++++++++--------------- playwright.config.js | 3 +-- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 467190b..30eaa51 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -1,27 +1,29 @@ name: Playwright Tests on: push: - branches: [ main, master ] + branches: [main, master] pull_request: - branches: [ main, master ] + branches: [main, master] jobs: test: timeout-minutes: 60 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: lts/* - - name: Install dependencies - run: npm ci - - name: Install Playwright Browsers - run: npx playwright install --with-deps - - name: Run Playwright tests - run: npx playwright test - - uses: actions/upload-artifact@v4 - if: always() - with: - name: playwright-report - path: playwright-report/ - retention-days: 30 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - name: Install dependencies + run: npm ci + - name: Install Playwright Browsers + run: npx playwright install --with-deps + - name: Run Playwright tests + run: npx playwright test + env: + BASEURL: ${{ env.BASEURL }} + - uses: actions/upload-artifact@v4 + if: always() + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/playwright.config.js b/playwright.config.js index c9cd016..fc54977 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -26,8 +26,7 @@ module.exports = defineConfig({ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: process.env.URL, - + baseURL: process.env.BASEURL || 'https://homolog.temvagamestre.com/', /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', }, From f2b196a6f3f6dda5ea08a801e29c06988fb0ba88 Mon Sep 17 00:00:00 2001 From: Renata Valois Date: Fri, 9 Aug 2024 13:57:11 -0300 Subject: [PATCH 5/9] =?UTF-8?q?remo=C3=A7=C3=A3o=20de=20url=20de=20ambient?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playwright.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playwright.config.js b/playwright.config.js index fc54977..9766866 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -26,7 +26,7 @@ module.exports = defineConfig({ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: process.env.BASEURL || 'https://homolog.temvagamestre.com/', + baseURL: process.env.BASEURL, /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', }, From 2c240b34ef4c7bfce373f7d12e16e3614162148e Mon Sep 17 00:00:00 2001 From: Renata Valois Date: Fri, 9 Aug 2024 13:57:39 -0300 Subject: [PATCH 6/9] =?UTF-8?q?remo=C3=A7=C3=A3o=20de=20url=20de=20ambient?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/perfil.js | 1 - 1 file changed, 1 deletion(-) diff --git a/pages/perfil.js b/pages/perfil.js index 02dd283..6fde29e 100644 --- a/pages/perfil.js +++ b/pages/perfil.js @@ -65,7 +65,6 @@ exports.PerfilPage = class PerfilPage { const localizador = "//p[contains(.,'" + insignia + "')]"; await expect(this.page.locator(localizador)).toBeVisible(); await expect(this.page.locator(localizador)).toHaveText(insignia); - console.log(insignia); }); } From 930f679c4fb4133ddf7998c46f1e6fbc26e71c43 Mon Sep 17 00:00:00 2001 From: brunomachadors Date: Fri, 9 Aug 2024 18:08:36 +0100 Subject: [PATCH 7/9] Updating env variables --- .github/workflows/playwright.yml | 2 +- package.json | 33 +++++++++++--------------------- playwright.config.js | 3 +-- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 30eaa51..ef3eb8e 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -20,7 +20,7 @@ jobs: - name: Run Playwright tests run: npx playwright test env: - BASEURL: ${{ env.BASEURL }} + BASE_URL: ${{ env.BASE_URL }} - uses: actions/upload-artifact@v4 if: always() with: diff --git a/package.json b/package.json index 238be5f..edb745a 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,7 @@ { "name": "temvagamestre.teste", "version": "1.0.0", - "description": "Este projeto será uma framework de automação de teste para o projeto 'Tem Vaga Mestre?' com o objetivo de validar testes de front-end e back-end", - "main": "index.js", + "description": "Framework de automação de testes para o projeto 'Tem Vaga Mestre?', com o objetivo de validar testes de front-end e back-end.", "scripts": { "test": "npx playwright test" }, @@ -11,34 +10,24 @@ "url": "git+https://github.com/Quest-Finder/temvagamestre.teste.git" }, "keywords": [ - "temvagamestre", - "playwright", - "javascript" + "automação", + "teste", + "playwright" ], - "authors": [ - { - "name": "Bruno Machado" - }, - { - "name": "Jéssica Ferraz" - }, - { - "name": "Raquel Gomes" - }, - { - "name": "Renata Valois" - } + "contributors": [ + "Bruno Machado", + "Jéssica Ferraz", + "Raquel Gomes", + "Renata Valois" ], - "license": "ISC", + "license": "none", "bugs": { "url": "https://github.com/Quest-Finder/temvagamestre.teste/issues" }, "homepage": "https://github.com/Quest-Finder/temvagamestre.teste#readme", "devDependencies": { "@playwright/test": "^1.43.1", - "@types/node": "^20.12.7" - }, - "dependencies": { + "@types/node": "^20.12.7", "dotenv": "^16.4.5" } } diff --git a/playwright.config.js b/playwright.config.js index 9766866..1790022 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -6,7 +6,6 @@ require('dotenv').config(); * Read environment variables from file. * https://github.com/motdotla/dotenv */ -// require('dotenv').config(); /** * @see https://playwright.dev/docs/test-configuration @@ -26,7 +25,7 @@ module.exports = defineConfig({ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: process.env.BASEURL, + baseURL: process.env.BASE_URL, /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', }, From dc1ac7c1352fcbc3aec24789af6a5beaa519a4b1 Mon Sep 17 00:00:00 2001 From: brunomachadors Date: Fri, 9 Aug 2024 18:12:41 +0100 Subject: [PATCH 8/9] using github secrets --- .github/workflows/playwright.yml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index ef3eb8e..ded7c0f 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -1,28 +1,39 @@ name: Playwright Tests + on: push: branches: [main, master] pull_request: branches: [main, master] + jobs: test: timeout-minutes: 60 runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 with: - node-version: lts/* + node-version: 'lts/*' + - name: Install dependencies run: npm ci + - name: Install Playwright Browsers run: npx playwright install --with-deps + - name: Run Playwright tests run: npx playwright test env: - BASE_URL: ${{ env.BASE_URL }} - - uses: actions/upload-artifact@v4 + BASE_URL: ${{ secrets.BASE_URL }} # Atualiza para BASE_URL + + - name: Upload Playwright Report if: always() + uses: actions/upload-artifact@v4 with: name: playwright-report path: playwright-report/ From da7bb27b78482d786ee122677e41e81b73c71ec8 Mon Sep 17 00:00:00 2001 From: brunomachadors Date: Fri, 9 Aug 2024 18:19:08 +0100 Subject: [PATCH 9/9] Update timeout --- playwright.config.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/playwright.config.js b/playwright.config.js index 1790022..17445a1 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -30,6 +30,11 @@ module.exports = defineConfig({ trace: 'on-first-retry', }, + timeout: 10000, + expect: { + timeout: 10000, + }, + /* Configure projects for major browsers */ projects: [ {