Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/debug header autotests #31

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cms/tests/bruno-cms-collection/collection.bru
Original file line number Diff line number Diff line change
@@ -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 <strapi.io>");
Expand Down
46 changes: 46 additions & 0 deletions cms/tests/playwright/baseTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { test as base, expect, Page } from '@playwright/test';

type CustomFixtures = {
page: Page;
consoleErrors: string[];
};

export const test = base.extend<CustomFixtures>({
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);
});
};
5 changes: 4 additions & 1 deletion cms/tests/playwright/strapi-admin-ui-tests.spec.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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');
});
Expand Down
4 changes: 4 additions & 0 deletions frontend/tests/bruno-frontend-collection/collection.bru
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
headers {
Debug-Header: [0_o] Hello from bruno autotests
}

docs {
API Client - https://github.com/usebruno/bruno
}
9 changes: 9 additions & 0 deletions frontend/tests/playwright/baseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export const test = base.extend<CustomFixtures>({
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);
}
});
Expand Down