Skip to content

Commit 2b7e6f0

Browse files
committed
✅(e2e) e2e instances compatibility
We want to be able to run our e2e tests on any instance of Docs, to do so we need to make some adjustments to our tests and configuration. We will use environment variables to configure the tests.
1 parent cd882c8 commit 2b7e6f0

30 files changed

Lines changed: 967 additions & 787 deletions

src/frontend/apps/e2e/.env

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
PORT=3000
2+
BASE_URL=http://localhost:3000
3+
BASE_API_URL=http://localhost:8071/api/v1.0
4+
COLLABORATION_WS_URL=ws://localhost:4444/collaboration/ws/
5+
COLLABORATION_WS_NOT_CONNECTED_READY_ONLY=true
6+
MEDIA_BASE_URL=http://localhost:8083
7+
CUSTOM_SIGN_IN=false
8+
IS_INSTANCE=false
9+
SIGN_IN_EL_LOGIN_PAGE='.login-pf #kc-header-wrapper'
10+
SIGN_IN_EL_TRIGGER=Start Writing
11+
FIRST_NAME=E2E
12+
SIGN_IN_USERNAME_CHROMIUM=user.test@chromium.test
13+
USERNAME_CHROMIUM=E2E Chromium
14+
SIGN_IN_USERNAME_WEBKIT=user.test@webkit.com
15+
USERNAME_WEBKIT=E2E Webkit
16+
SIGN_IN_USERNAME_FIREFOX=user.test@firefox.com
17+
USERNAME_FIREFOX=E2E Firefox
18+
# To test server to server API calls
19+
SERVER_TO_SERVER_API_TOKENS='server-api-token'
20+
SUB_CHROMIUM=user.test@chromium.test
21+
SUB_WEBKIT=user.test@webkit.com
22+
SUB_FIREFOX=user.test@firefox.com

src/frontend/apps/e2e/.env.example

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
PORT=3000
2+
BASE_URL=http://localhost:3000
3+
BASE_API_URL=http://localhost:8071/api/v1.0
4+
COLLABORATION_WS_URL=ws://localhost:4444/collaboration/ws/
5+
COLLABORATION_WS_NOT_CONNECTED_READY_ONLY=true
6+
MEDIA_BASE_URL=http://localhost:8083
7+
IS_INSTANCE=false
8+
CUSTOM_SIGN_IN=false
9+
SIGN_IN_EL_LOGIN_PAGE='.login-pf #kc-header-wrapper'
10+
SIGN_IN_EL_TRIGGER=Start Writing
11+
FIRST_NAME=E2E
12+
SIGN_IN_USERNAME_CHROMIUM=user.test@chromium.test
13+
USERNAME_CHROMIUM=E2E Chromium
14+
SIGN_IN_USERNAME_WEBKIT=user.test@webkit.com
15+
USERNAME_WEBKIT=E2E Webkit
16+
SIGN_IN_USERNAME_FIREFOX=user.test@firefox.com
17+
USERNAME_FIREFOX=E2E Firefox
18+
# Used only on instance with custom sign in
19+
SIGN_IN_EL_USERNAME_INPUT=
20+
SIGN_IN_EL_USERNAME_VALIDATION=
21+
SIGN_IN_EL_PASSWORD_INPUT=
22+
SIGN_IN_PASSWORD_CHROMIUM=
23+
SIGN_IN_PASSWORD_WEBKIT=
24+
SIGN_IN_PASSWORD_FIREFOX=
25+
# To test server to server API calls
26+
SERVER_TO_SERVER_API_TOKENS='server-api-token'
27+
SUB_CHROMIUM=user.test@chromium.test
28+
SUB_WEBKIT=user.test@webkit.com
29+
SUB_FIREFOX=user.test@firefox.com

src/frontend/apps/e2e/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ blob-report/
55
playwright/.auth/
66
playwright/.cache/
77
screenshots/
8+
.env.local

src/frontend/apps/e2e/__tests__/app-impress/auth.setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FullConfig, FullProject, chromium, expect } from '@playwright/test';
22

3-
import { keyCloakSignIn } from './utils-common';
3+
import { SignIn } from './utils-signin';
44

55
const saveStorageState = async (
66
browserConfig: FullProject<unknown, unknown>,
@@ -22,7 +22,7 @@ const saveStorageState = async (
2222
await page.content();
2323
await expect(page.getByText('Docs').first()).toBeVisible();
2424

25-
await keyCloakSignIn(page, browserName);
25+
await SignIn(page, browserName);
2626

2727
await expect(
2828
page.locator('header').first().getByRole('button', {

src/frontend/apps/e2e/__tests__/app-impress/config.spec.ts

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,33 @@ import path from 'path';
22

33
import { expect, test } from '@playwright/test';
44

5-
import { CONFIG, createDoc, overrideConfig } from './utils-common';
5+
import {
6+
CONFIG,
7+
createDoc,
8+
getCurrentConfig,
9+
overrideConfig,
10+
} from './utils-common';
611

712
test.describe('Config', () => {
8-
test('it checks that sentry is trying to init from config endpoint', async ({
9-
page,
10-
}) => {
11-
await overrideConfig(page, {
12-
SENTRY_DSN: 'https://sentry.io/123',
13+
if (process.env.IS_INSTANCE !== 'true') {
14+
test('it checks that sentry is trying to init from config endpoint', async ({
15+
page,
16+
}) => {
17+
await overrideConfig(page, {
18+
SENTRY_DSN: 'https://sentry.io/123',
19+
});
20+
21+
const invalidMsg = 'Invalid Sentry Dsn: https://sentry.io/123';
22+
const consoleMessage = page.waitForEvent('console', {
23+
timeout: 5000,
24+
predicate: (msg) => msg.text().includes(invalidMsg),
25+
});
26+
27+
await page.goto('/');
28+
29+
expect((await consoleMessage).text()).toContain(invalidMsg);
1330
});
14-
15-
const invalidMsg = 'Invalid Sentry Dsn: https://sentry.io/123';
16-
const consoleMessage = page.waitForEvent('console', {
17-
timeout: 5000,
18-
predicate: (msg) => msg.text().includes(invalidMsg),
19-
});
20-
21-
await page.goto('/');
22-
23-
expect((await consoleMessage).text()).toContain(invalidMsg);
24-
});
31+
}
2532

2633
test('it checks that media server is configured from config endpoint', async ({
2734
page,
@@ -55,7 +62,7 @@ test.describe('Config', () => {
5562

5663
// Check src of image
5764
expect(await image.getAttribute('src')).toMatch(
58-
/http:\/\/localhost:8083\/media\/.*\/attachments\/.*.png/,
65+
new RegExp(`${process.env.MEDIA_BASE_URL}/media/.*?/attachments/.*?.png`),
5966
);
6067
});
6168

@@ -71,23 +78,36 @@ test.describe('Config', () => {
7178
.click();
7279

7380
const webSocket = await page.waitForEvent('websocket', (webSocket) => {
74-
return webSocket.url().includes('ws://localhost:4444/collaboration/ws/');
81+
return webSocket.url().includes(`${process.env.COLLABORATION_WS_URL}`);
7582
});
76-
expect(webSocket.url()).toContain('ws://localhost:4444/collaboration/ws/');
83+
expect(webSocket.url()).toContain(`${process.env.COLLABORATION_WS_URL}`);
7784
});
7885

79-
test('it checks that Crisp is trying to init from config endpoint', async ({
80-
page,
81-
}) => {
82-
await overrideConfig(page, {
83-
CRISP_WEBSITE_ID: '1234',
86+
if (process.env.IS_INSTANCE !== 'true') {
87+
test('it checks that Crisp is trying to init from config endpoint', async ({
88+
page,
89+
}) => {
90+
await overrideConfig(page, {
91+
CRISP_WEBSITE_ID: '1234',
92+
});
93+
94+
await page.goto('/');
95+
96+
await expect(
97+
page.locator('#crisp-chatbox').getByText('Invalid website'),
98+
).toBeVisible();
8499
});
100+
}
85101

86-
await page.goto('/');
102+
test('it checks that Crisp is initialized', async ({ page }) => {
103+
const currentConfig = await getCurrentConfig(page);
87104

88-
await expect(
89-
page.locator('#crisp-chatbox').getByText('Invalid website'),
90-
).toBeVisible();
105+
test.skip(
106+
!currentConfig.CRISP_WEBSITE_ID,
107+
'CRISP_WEBSITE_ID is not set in config, skipping Crisp initialization test',
108+
);
109+
110+
await expect(page.locator('#crisp-chatbox')).toBeVisible();
91111
});
92112

93113
test('it checks FRONTEND_CSS_URL config', async ({ page }) => {
@@ -118,20 +138,22 @@ test.describe('Config', () => {
118138
).toBeAttached();
119139
});
120140

121-
test('it checks the config api is called', async ({ page }) => {
122-
const responsePromise = page.waitForResponse(
123-
(response) =>
124-
response.url().includes('/config/') && response.status() === 200,
125-
);
141+
if (process.env.IS_INSTANCE !== 'true') {
142+
test('it checks the config api is called', async ({ page }) => {
143+
const responsePromise = page.waitForResponse(
144+
(response) =>
145+
response.url().includes('/config/') && response.status() === 200,
146+
);
126147

127-
await page.goto('/');
148+
await page.goto('/');
128149

129-
const response = await responsePromise;
130-
expect(response.ok()).toBeTruthy();
150+
const response = await responsePromise;
151+
expect(response.ok()).toBeTruthy();
131152

132-
const json = (await response.json()) as typeof CONFIG;
133-
expect(json).toStrictEqual(CONFIG);
134-
});
153+
const json = (await response.json()) as typeof CONFIG;
154+
expect(json).toStrictEqual(CONFIG);
155+
});
156+
}
135157
});
136158

137159
test.describe('Config: Not logged', () => {

0 commit comments

Comments
 (0)