diff --git a/cms/tests/bruno-cms-collection/collection.bru b/cms/tests/bruno-cms-collection/collection.bru index 280f8ba..7d44e57 100644 --- a/cms/tests/bruno-cms-collection/collection.bru +++ b/cms/tests/bruno-cms-collection/collection.bru @@ -1,3 +1,7 @@ +headers { + Debug-Header: [0_o] Hello from bruno autotests +} + tests { test("check header x-powered-by Strapi", function() { expect(res.headers['x-powered-by']).to.equal("Strapi "); diff --git a/cms/tests/playwright/baseTest.ts b/cms/tests/playwright/baseTest.ts new file mode 100644 index 0000000..19ced6b --- /dev/null +++ b/cms/tests/playwright/baseTest.ts @@ -0,0 +1,46 @@ +import { test as base, expect, Page } from '@playwright/test'; + +type CustomFixtures = { + page: Page; + consoleErrors: string[]; +}; + +export const test = base.extend({ + consoleErrors: async ({}, use) => { + const errors: string[] = []; + await use(errors); + }, + + page: async ({ page, consoleErrors }, use) => { + // Catch errors in console + page.on('console', msg => { + if (msg.type() === 'error') { + consoleErrors.push(msg.text()); + } + }); + + // Catch unhandled exceptions on page + page.on('pageerror', error => { + consoleErrors.push(error.message); + }); + + // Add custom header to all requests + page.route('**', route => { + const headers = { + ...route.request().headers(), + 'Debug-Header': '[0_o] Hello from playwright autotests' + }; + route.continue({ headers }); + }); + + await use(page); + } +}); + +// Existing console errors check +export const checkConsoleErrors = () => { + test('check console errors', async ({ consoleErrors, page }) => { + await page.waitForLoadState('networkidle'); + expect(consoleErrors, 'Found errors on the page').toHaveLength(0); + }); +}; \ No newline at end of file diff --git a/cms/tests/playwright/strapi-admin-ui-tests.spec.ts b/cms/tests/playwright/strapi-admin-ui-tests.spec.ts index 83d8f2a..890470a 100644 --- a/cms/tests/playwright/strapi-admin-ui-tests.spec.ts +++ b/cms/tests/playwright/strapi-admin-ui-tests.spec.ts @@ -1,4 +1,5 @@ -import { test, expect } from '@playwright/test'; +import { test, checkConsoleErrors } from './baseTest'; +import { expect } from '@playwright/test'; export const TEST_USERS = { adminUser: { @@ -11,6 +12,8 @@ test.beforeEach(async ({ page }) => { await page.goto('/'); }); +checkConsoleErrors(); + test('unauthorized redirect from localhost:1337 to /admin/auth/login', async ({ page }) => { await expect(page).toHaveURL('http://localhost:1337/admin/auth/login'); }); diff --git a/frontend/tests/bruno-frontend-collection/collection.bru b/frontend/tests/bruno-frontend-collection/collection.bru index f810415..0a36686 100644 --- a/frontend/tests/bruno-frontend-collection/collection.bru +++ b/frontend/tests/bruno-frontend-collection/collection.bru @@ -1,3 +1,7 @@ +headers { + Debug-Header: [0_o] Hello from bruno autotests +} + docs { API Client - https://github.com/usebruno/bruno } diff --git a/frontend/tests/playwright/baseTest.ts b/frontend/tests/playwright/baseTest.ts index 0421550..4be3ab3 100644 --- a/frontend/tests/playwright/baseTest.ts +++ b/frontend/tests/playwright/baseTest.ts @@ -29,6 +29,15 @@ export const test = base.extend({ consoleErrors.push(error.message); }); + // Add custom header to all requests + page.route('**', route => { + const headers = { + ...route.request().headers(), + 'Debug-Header': '[0_o] Hello from playwright autotests' + }; + route.continue({ headers }); + }); + await use(page); } });