From 3f40f32f261ef3aa069fd48486d1ed7d7bd7e018 Mon Sep 17 00:00:00 2001 From: jessica Date: Sun, 12 May 2024 14:21:26 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Cria=C3=A7=C3=A3o=20PageObject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/perfil-page | 27 +++++++++++++++++++++++++++ tests/perfil.spec.js | 14 +++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 pages/perfil-page diff --git a/pages/perfil-page b/pages/perfil-page new file mode 100644 index 0000000..44433ed --- /dev/null +++ b/pages/perfil-page @@ -0,0 +1,27 @@ +const { expect } = require('@playwright/test'); + +exports.PerfilPage = class PerfilPage { + + constructor(page) { + this.page = page; + this.extenderBio = "//button[contains(.,'Ver mais')]"; + this.reduzirBio = "//button[contains(.,'Ver menos')]"; + this.estilosPreferidos = "(//h1[contains(.,'Estilos preferidos')])[1]"; + this.conquistas = "(//h1[contains(.,'Conquistas')])[1]"; + } + + async goto(){ + await this.page.goto('https://frontend-nnf7bytugq-uc.a.run.app/user/profile?show=profile'); + } + + async conferirElementosTela(){ + await expect(this.page).toHaveTitle(/Tem Vaga Mestre/); + + await this.page.click(this.extenderBio); + await this.page.click(this.reduzirBio); + + await expect(this.page.locator(this.estilosPreferidos)).toBeVisible(); + await expect(this.page.locator(this.conquistas)).toBeVisible(); + } +}; + diff --git a/tests/perfil.spec.js b/tests/perfil.spec.js index 778728a..e2e414d 100644 --- a/tests/perfil.spec.js +++ b/tests/perfil.spec.js @@ -1,13 +1,9 @@ const { test, expect } = require('@playwright/test'); +import { PerfilPage } from '../pages/perfil-page'; -test('acessar perfil', async ({ page }) => { - await page.goto('https://frontend-nnf7bytugq-uc.a.run.app/user/profile?show=profile'); - - await expect(page).toHaveTitle(/Tem Vaga Mestre/); - - await expect(page.getByRole('heading', { name: 'Estilos preferidos' })).toBeVisible(); - await expect(page.getByRole('heading', { name: 'Conquistas' })).toBeVisible(); - - await page.getByRole('button', { name: 'Ver mais'}).click(); +test('Acessar perfil', async ({ page }) => { + const perfilPage = new PerfilPage(page); + await perfilPage.goto(); + await perfilPage.conferirElementosTela(); }); From 06db80c2df75dd0cd452b38ee8a7fdc4d173254c Mon Sep 17 00:00:00 2001 From: brunomachadors Date: Tue, 14 May 2024 16:02:35 +0100 Subject: [PATCH 2/2] Modificamos o arquivo de perfil e o modo de captura de objetos --- pages/perfil-page | 27 --------------------------- pages/perfil.js | 36 ++++++++++++++++++++++++++++++++++++ tests/perfil.spec.js | 9 ++++++--- 3 files changed, 42 insertions(+), 30 deletions(-) delete mode 100644 pages/perfil-page create mode 100644 pages/perfil.js diff --git a/pages/perfil-page b/pages/perfil-page deleted file mode 100644 index 44433ed..0000000 --- a/pages/perfil-page +++ /dev/null @@ -1,27 +0,0 @@ -const { expect } = require('@playwright/test'); - -exports.PerfilPage = class PerfilPage { - - constructor(page) { - this.page = page; - this.extenderBio = "//button[contains(.,'Ver mais')]"; - this.reduzirBio = "//button[contains(.,'Ver menos')]"; - this.estilosPreferidos = "(//h1[contains(.,'Estilos preferidos')])[1]"; - this.conquistas = "(//h1[contains(.,'Conquistas')])[1]"; - } - - async goto(){ - await this.page.goto('https://frontend-nnf7bytugq-uc.a.run.app/user/profile?show=profile'); - } - - async conferirElementosTela(){ - await expect(this.page).toHaveTitle(/Tem Vaga Mestre/); - - await this.page.click(this.extenderBio); - await this.page.click(this.reduzirBio); - - await expect(this.page.locator(this.estilosPreferidos)).toBeVisible(); - await expect(this.page.locator(this.conquistas)).toBeVisible(); - } -}; - diff --git a/pages/perfil.js b/pages/perfil.js new file mode 100644 index 0000000..fb80b1d --- /dev/null +++ b/pages/perfil.js @@ -0,0 +1,36 @@ +const { expect } = require('@playwright/test'); + +exports.PerfilPage = class PerfilPage { + constructor(page) { + this.page = page; + } + + async goto() { + await this.page.goto( + 'https://frontend-nnf7bytugq-uc.a.run.app/user/profile?show=profile' + ); + } + + async clicarExtenderBio() { + const extenderBioButton = "//button[contains(.,'Ver mais')]"; + await this.page.click(extenderBioButton); + } + + async clicarReduzirBio() { + const reduzirBioButton = "//button[contains(.,'Ver menos')]"; + await this.page.click(reduzirBioButton); + } + + async validarTitulo() { + await expect(this.page).toHaveTitle(/Tem Vaga Mestre/); + } + + async validarEstilosPreferidos() { + const estilosPreferidos = "(//h1[contains(.,'Estilos preferidos')])[1]"; + await expect(this.page.locator(estilosPreferidos)).toBeVisible(); + } + async validarConquistas() { + const conquistas = "(//h1[contains(.,'Conquistas')])[1]"; + await expect(this.page.locator(conquistas)).toBeVisible(); + } +}; diff --git a/tests/perfil.spec.js b/tests/perfil.spec.js index e2e414d..60e0279 100644 --- a/tests/perfil.spec.js +++ b/tests/perfil.spec.js @@ -1,9 +1,12 @@ const { test, expect } = require('@playwright/test'); -import { PerfilPage } from '../pages/perfil-page'; +import { PerfilPage } from '../pages/perfil.js'; test('Acessar perfil', async ({ page }) => { const perfilPage = new PerfilPage(page); await perfilPage.goto(); - await perfilPage.conferirElementosTela(); + await perfilPage.validarTitulo(); + await perfilPage.clicarExtenderBio(); + await perfilPage.clicarReduzirBio(); + await perfilPage.validarEstilosPreferidos(); + await perfilPage.validarConquistas(); }); -