From 4c2cc0210947467bc3705befe5cbea02d2efc7a8 Mon Sep 17 00:00:00 2001 From: kallelongjuhani Date: Wed, 25 Sep 2024 10:07:39 +0300 Subject: [PATCH] =?UTF-8?q?chore:=20save=20trace=20from=20Playwright?= =?UTF-8?q?=E2=80=99s=20global=20setup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Saves the trace from the global setup part of Playwright tests, during which errors often emerge. --- .github/workflows/main.yaml | 8 ++++++++ .gitignore | 3 ++- tests/global-setup.ts | 41 ++++++++++++++++++++++++++----------- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 6235c4b98..aa5529416 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -174,6 +174,14 @@ jobs: - name: "Run E2E tests" run: yarn test + - name: "Upload playwright setup report" + uses: actions/upload-artifact@v4 + if: always() + with: + name: playwright-setup-report + path: playwright-setup-report/ + retention-days: 30 + - name: "Upload playwright report" uses: actions/upload-artifact@v4 if: always() diff --git a/.gitignore b/.gitignore index 453207cae..5225f4a11 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,6 @@ node_modules /test-results/ /playwright-report/ +/playwright-setup-report/ /blob-report/ -/playwright/ +/playwright/ \ No newline at end of file diff --git a/tests/global-setup.ts b/tests/global-setup.ts index 160990274..40aea122c 100644 --- a/tests/global-setup.ts +++ b/tests/global-setup.ts @@ -6,25 +6,42 @@ import mockUsers from '../backend/vaa-strapi/src/functions/mockData/mockUser.jso import { STORAGE_STATE } from '../playwright.config'; const mockUser = mockUsers[1]; +/** The setup report must be stored in a separate directory from `playwright-report` because the latter will be overwritten after the setup */ +const SETUP_REPORT_DIR = './playwright-setup-report'; async function globalSetup(config: FullConfig) { const { baseURL } = config.projects[0].use; const browser = await chromium.launch(); - const page = await browser.newPage(); + const context = await browser.newContext(); + const page = await context.newPage(); - await page.goto(`${baseURL!}/${Route.CandAppHome}`); - await page.getByLabel(T.en['candidateApp.common.email'], {exact: true}).fill(mockUser.email); - await page.getByLabel(T.en['components.passwordInput.password'], {exact: true}).fill(mockUser.password); - await page.getByText(T.en['common.login'], {exact: true}).click(); + try { - // Wait until the page actually signs in. - await expect( - page.getByText(T.en['candidateApp.home.ready'], - {exact: true}), - 'The start page for a logged-in candidate should be visible. If this fails, make sure that the database actually contains the user with the email and password used. Also, because we’re checking for a specific intro message, the user should have all their answers filled.' - ).toBeVisible(); + await context.tracing.start({ screenshots: true, snapshots: true }); + await page.goto(`${baseURL!}/${Route.CandAppHome}`); + await page.getByLabel(T.en['candidateApp.common.email'], { exact: true }).fill(mockUser.email); + await page.getByLabel(T.en['components.passwordInput.password'], { exact: true }).fill(mockUser.password); + await page.getByText(T.en['common.login'], { exact: true }).click(); + // Wait until the page actually signs in. + await expect( + page.getByText(T.en['candidateApp.home.ready'], + {exact: true}), + 'The start page for a logged-in candidate should be visible. If this fails, make sure that the database actually contains the user with the email and password used. Also, because we’re checking for a specific intro message, the user should have all their answers filled.' + ).toBeVisible(); + await context.tracing.stop({ + path: `${SETUP_REPORT_DIR}/setup-trace.zip`, + }); + await context.storageState({ path: STORAGE_STATE }); - await page.context().storageState({ path: STORAGE_STATE }); + } catch (error) { + + // The setup report must be stored in a separate directory from `playwright-report` because the latter will be overwritten after the setup + await context.tracing.stop({ + path: `${SETUP_REPORT_DIR}/failed-setup-trace.zip`, + }); + await browser.close(); + throw error; + } } export default globalSetup;