From f2350d4042c748cbce38165a073c4d1beba07fb8 Mon Sep 17 00:00:00 2001 From: webrooster Date: Wed, 24 May 2023 18:17:56 +0200 Subject: [PATCH 1/4] fix(Playwright): cleanup code, change order --- __e2e__/authenticated.test.tsx | 18 +++++++++--------- __e2e__/non-authenticated.test.tsx | 4 ---- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/__e2e__/authenticated.test.tsx b/__e2e__/authenticated.test.tsx index db52a2ac..240d99e7 100644 --- a/__e2e__/authenticated.test.tsx +++ b/__e2e__/authenticated.test.tsx @@ -21,15 +21,7 @@ test.describe('01.authenticated tests', () => { expect(page.getByRole('article').filter({ hasText: `${testMessage}` })); }); - test('03.timeline - post without text', async ({ page }) => { - await page.goto('/'); - await page.waitForLoadState('networkidle'); - await page.waitForSelector('[data-testid="testTextarea"]'); - await page.getByRole('button', { name: 'Absenden' }).click(); - await expect(page.locator('p').filter({ hasText: 'Das Textfeld darf nicht leer sein.' })).toBeInViewport(); - }); - - test('03.timeline - click on hashtag', async ({ page }) => { + test('02.timeline - click on hashtag', async ({ page }) => { await expect(async () => { let hasArticleToBeDelete: boolean = false; hasArticleToBeDelete = await page.isVisible(`text=${testMessage}`); @@ -54,6 +46,14 @@ test.describe('01.authenticated tests', () => { }).toPass(); }); + test('03.timeline - post without text', async ({ page }) => { + await page.goto('/'); + await page.waitForLoadState('networkidle'); + await page.waitForSelector('[data-testid="testTextarea"]'); + await page.getByRole('button', { name: 'Absenden' }).click(); + await expect(page.locator('p').filter({ hasText: 'Das Textfeld darf nicht leer sein.' })).toBeInViewport(); + }); + test('04.timeline - delete message', async ({ page }) => { await page.waitForSelector('body, footer'); await expect(async () => { diff --git a/__e2e__/non-authenticated.test.tsx b/__e2e__/non-authenticated.test.tsx index e82095cf..6e031bd0 100644 --- a/__e2e__/non-authenticated.test.tsx +++ b/__e2e__/non-authenticated.test.tsx @@ -14,8 +14,6 @@ test.beforeEach(async ({ page, context }) => { test.describe('01.non-authenticated', () => { test('01.timeline - should have at least one article', async ({ page }) => { - await page.goto('/'); - await page.waitForLoadState('networkidle'); await page.waitForSelector('body'); const articles = page.getByRole('article'); @@ -24,8 +22,6 @@ test.describe('01.non-authenticated', () => { }); test('02.timeline - should redirect to landingpage', async ({ page }) => { - await page.goto('/'); - await page.waitForLoadState('domcontentloaded'); await page.waitForSelector('body'); const article = page.getByRole('article').filter({ hasText: 'username' }).first(); const articles = page.getByRole('article'); From 651dafb5d61c5715ca9bdb13dbae490d731cf3bb Mon Sep 17 00:00:00 2001 From: webrooster Date: Sat, 27 May 2023 12:07:27 +0200 Subject: [PATCH 2/4] fix(Playwright): non auth json --- __e2e__/globalSetup.ts | 1 - __e2e__/noAuth.json | 4 ++++ __e2e__/non-authenticated.test.tsx | 5 +++-- noAuth.json | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 __e2e__/noAuth.json create mode 100644 noAuth.json diff --git a/__e2e__/globalSetup.ts b/__e2e__/globalSetup.ts index 646d7146..adc34867 100644 --- a/__e2e__/globalSetup.ts +++ b/__e2e__/globalSetup.ts @@ -18,7 +18,6 @@ const globalSetup = async (config: FullConfig) => { await page.getByRole('button', { name: 'Login' }).click(); await expect(page).toHaveURL(new RegExp(`${url}`)); await page.waitForSelector('body'); - await page.getByPlaceholder('username@domain').click(); await page.getByPlaceholder('username@domain').fill(user); await page.locator('#submit-button').click(); await page.getByLabel('Password').fill(pw); diff --git a/__e2e__/noAuth.json b/__e2e__/noAuth.json new file mode 100644 index 00000000..914e9266 --- /dev/null +++ b/__e2e__/noAuth.json @@ -0,0 +1,4 @@ +{ + "cookies": [], + "origins": [] +} diff --git a/__e2e__/non-authenticated.test.tsx b/__e2e__/non-authenticated.test.tsx index 6e031bd0..11dee293 100644 --- a/__e2e__/non-authenticated.test.tsx +++ b/__e2e__/non-authenticated.test.tsx @@ -1,15 +1,16 @@ import { test, expect } from '@playwright/test'; test.describe.configure({ mode: 'serial' }); +test.use({ storageState: './noAuth.json' }); test.beforeEach(async ({ page, context }) => { - await context.clearCookies(); + // await context.clearCookies(); await page.goto('/'); await page.waitForLoadState('domcontentloaded'); await page.waitForSelector('body'); await expect(page.getByLabel('Login')).toBeInViewport(); await expect(page.getByLabel('Logout')).not.toBeInViewport(); - // console.log(await context.storageState()); + console.log(await context.storageState()); }); test.describe('01.non-authenticated', () => { diff --git a/noAuth.json b/noAuth.json new file mode 100644 index 00000000..0322be32 --- /dev/null +++ b/noAuth.json @@ -0,0 +1,14 @@ +{ + "cookies": [], + "origins": [ + { + "origin": "http://localhost:3000", + "localStorage": [ + { + "name": "nextauth.message", + "value": "{\"event\":\"session\",\"data\":{\"trigger\":\"getSession\"},\"timestamp\":1684998429}" + } + ] + } + ] +} From fa6c6c108376577163b9d6cfd4595bde4becdfd0 Mon Sep 17 00:00:00 2001 From: webrooster Date: Tue, 30 May 2023 16:21:35 +0200 Subject: [PATCH 3/4] feat(Playwright): tbd like test --- __e2e__/authenticated.test.tsx | 35 +++++++++++++++++++++++++++--- __e2e__/non-authenticated.test.tsx | 2 +- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/__e2e__/authenticated.test.tsx b/__e2e__/authenticated.test.tsx index 240d99e7..8271f9a1 100644 --- a/__e2e__/authenticated.test.tsx +++ b/__e2e__/authenticated.test.tsx @@ -21,7 +21,36 @@ test.describe('01.authenticated tests', () => { expect(page.getByRole('article').filter({ hasText: `${testMessage}` })); }); - test('02.timeline - click on hashtag', async ({ page }) => { + test('02.timeline - should like an article', async ({ page }) => { + await expect(async () => { + let hasArticleToBeLiked: boolean = false; + hasArticleToBeLiked = await page.isVisible(`text=${testMessage}`); + + if (hasArticleToBeLiked === true) { + await page.getByRole('article').first().getByRole('button', { name: 'Like' }).click(); + expect(page.getByRole('button', { name: 'Liked' })); + } + }).toPass(); + }); + + test('03.timeline - should list liked article', async ({ page }) => { + await page.getByRole('link', { name: 'Profile' }).click(); + await expect(page).toHaveURL(/profile/); + + await expect(async () => { + let hasArticleToBeLiked: boolean = false; + hasArticleToBeLiked = await page.isVisible(`text=${testMessage}`); + + if (hasArticleToBeLiked === true) { + page.getByRole('article').first().getByRole('button', { name: 'Liked' }); + expect(page.getByRole('button', { name: 'Liked' })); + // page.getByRole('article').first().getByRole('button', { name: 'Liked' }).click(); + // expect(page.getByRole('button', { name: 'Like' })); + } + }).toPass(); + }); + + test('04.timeline - click on hashtag', async ({ page }) => { await expect(async () => { let hasArticleToBeDelete: boolean = false; hasArticleToBeDelete = await page.isVisible(`text=${testMessage}`); @@ -46,7 +75,7 @@ test.describe('01.authenticated tests', () => { }).toPass(); }); - test('03.timeline - post without text', async ({ page }) => { + test('05.timeline - post without text', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); await page.waitForSelector('[data-testid="testTextarea"]'); @@ -54,7 +83,7 @@ test.describe('01.authenticated tests', () => { await expect(page.locator('p').filter({ hasText: 'Das Textfeld darf nicht leer sein.' })).toBeInViewport(); }); - test('04.timeline - delete message', async ({ page }) => { + test('06.timeline - delete message', async ({ page }) => { await page.waitForSelector('body, footer'); await expect(async () => { let hasArticleToBeDelete: boolean = false; diff --git a/__e2e__/non-authenticated.test.tsx b/__e2e__/non-authenticated.test.tsx index 11dee293..23458463 100644 --- a/__e2e__/non-authenticated.test.tsx +++ b/__e2e__/non-authenticated.test.tsx @@ -10,7 +10,7 @@ test.beforeEach(async ({ page, context }) => { await page.waitForSelector('body'); await expect(page.getByLabel('Login')).toBeInViewport(); await expect(page.getByLabel('Logout')).not.toBeInViewport(); - console.log(await context.storageState()); + // console.log(await context.storageState()); }); test.describe('01.non-authenticated', () => { From 77fc59eccf48b60dfb72eb36389ee9b9cdf7708c Mon Sep 17 00:00:00 2001 From: webrooster Date: Tue, 6 Jun 2023 14:15:19 +0200 Subject: [PATCH 4/4] feat(Playwright): add liked article --- __e2e__/authenticated.test.tsx | 51 +++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/__e2e__/authenticated.test.tsx b/__e2e__/authenticated.test.tsx index 8271f9a1..1845c290 100644 --- a/__e2e__/authenticated.test.tsx +++ b/__e2e__/authenticated.test.tsx @@ -13,7 +13,7 @@ test.describe('01.authenticated tests', () => { await page.waitForLoadState('domcontentloaded'); }); - test('01.timeline - post message', async ({ page }) => { + test('01.timeline - should post a message', async ({ page }) => { await page.waitForSelector('[data-testid="testTextarea"]'); await page.getByTestId('testTextarea').fill(`${testMessage} #${hashTag}`); await page.waitForSelector('body'); @@ -27,30 +27,18 @@ test.describe('01.authenticated tests', () => { hasArticleToBeLiked = await page.isVisible(`text=${testMessage}`); if (hasArticleToBeLiked === true) { - await page.getByRole('article').first().getByRole('button', { name: 'Like' }).click(); - expect(page.getByRole('button', { name: 'Liked' })); - } - }).toPass(); - }); - - test('03.timeline - should list liked article', async ({ page }) => { - await page.getByRole('link', { name: 'Profile' }).click(); - await expect(page).toHaveURL(/profile/); - - await expect(async () => { - let hasArticleToBeLiked: boolean = false; - hasArticleToBeLiked = await page.isVisible(`text=${testMessage}`); - - if (hasArticleToBeLiked === true) { - page.getByRole('article').first().getByRole('button', { name: 'Liked' }); - expect(page.getByRole('button', { name: 'Liked' })); - // page.getByRole('article').first().getByRole('button', { name: 'Liked' }).click(); - // expect(page.getByRole('button', { name: 'Like' })); + await page + .getByRole('article') + .filter({ hasText: `${testMessage}` }) + .first() + .getByRole('button', { name: 'Like' }) + .click(); } }).toPass(); + expect(page.getByRole('button', { name: 'Liked' })); }); - test('04.timeline - click on hashtag', async ({ page }) => { + test('03.timeline - should click on hashtag', async ({ page }) => { await expect(async () => { let hasArticleToBeDelete: boolean = false; hasArticleToBeDelete = await page.isVisible(`text=${testMessage}`); @@ -75,7 +63,7 @@ test.describe('01.authenticated tests', () => { }).toPass(); }); - test('05.timeline - post without text', async ({ page }) => { + test('04.timeline - should post no message', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); await page.waitForSelector('[data-testid="testTextarea"]'); @@ -83,7 +71,22 @@ test.describe('01.authenticated tests', () => { await expect(page.locator('p').filter({ hasText: 'Das Textfeld darf nicht leer sein.' })).toBeInViewport(); }); - test('06.timeline - delete message', async ({ page }) => { + test('05.timeline - should list liked article', async ({ page }) => { + await page.getByRole('link', { name: 'Profile' }).click(); + await expect(page).toHaveURL(/profile/); + + await expect(async () => { + let hasLikedArticle: boolean = false; + hasLikedArticle = await page.isVisible(`text=${testMessage}`); + + if (hasLikedArticle === true) { + expect(page.getByRole('article').filter({ hasText: `${testMessage}` })); + expect(page.getByRole('button', { name: 'Liked' })); + } + }).toPass(); + }); + + test('06.timeline - should delete test message', async ({ page }) => { await page.waitForSelector('body, footer'); await expect(async () => { let hasArticleToBeDelete: boolean = false; @@ -97,6 +100,8 @@ test.describe('01.authenticated tests', () => { const article_id = await articleToBeDeleted.getAttribute('id'); expect(article_id, `👉 should have an article id ${article_id}`); + expect(articleToBeDeleted.locator('svg').last()); + await articleToBeDeleted.locator('svg').last().click(); console.log(`👉 deleting article with id ${article_id}`);