Skip to content

Commit 0f5aa0b

Browse files
committed
test(playwright): ♻️ align login configurations
1 parent ae949a3 commit 0f5aa0b

File tree

9 files changed

+68
-61
lines changed

9 files changed

+68
-61
lines changed

playwright/config/console.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { expect } from '@playwright/test'
2+
3+
// Retrieve frontend URL from environment variables (see playwright.config.ts)
4+
export const clientURL = process.env.KEYCLOAK_REDIRECT_URI || 'http://change-me'
5+
6+
export interface Credentials {
7+
username: string
8+
password: string
9+
email: string
10+
}
11+
12+
// Users referenced in Keycloak dev realm (../keycloak/realms/realm-dev.json)
13+
export const adminUser: Credentials = {
14+
username: 'admin',
15+
password: 'admin',
16+
17+
}
18+
export const testUser: Credentials = {
19+
username: 'test',
20+
password: 'test',
21+
22+
}
23+
export const cnolletUser: Credentials = {
24+
username: 'cnollet',
25+
password: 'test',
26+
27+
}
28+
29+
export async function signInCloudPiNative({
30+
page,
31+
credentials,
32+
}: {
33+
page: Page
34+
credentials: Credentials
35+
}) {
36+
const { username, password } = credentials
37+
await page.getByRole('link', { name: 'Se connecter' }).click()
38+
await page.locator('#username').fill(username)
39+
await page.locator('#password').fill(password)
40+
await page.locator('#kc-login').click()
41+
await expect(page.locator('#top')).toContainText('Cloud π Native')
42+
}

playwright/config/keycloak.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { expect } from '@playwright/test'
2+
13
export interface KeycloakConfig {
24
url: string
35
realm: string
@@ -22,3 +24,14 @@ export function loadKeycloakConfig(): KeycloakConfig {
2224
clientBackend: process.env.KEYCLOAK_CLIENT_BACKEND || 'dso-console-backend',
2325
}
2426
}
27+
28+
export async function signInKeycloak(
29+
page: Page,
30+
) {
31+
const keycloakConfig = loadKeycloakConfig()
32+
await page.goto(keycloakConfig.url)
33+
await page.locator('#username').fill(keycloakConfig.adminUser)
34+
await page.locator('#password').fill(keycloakConfig.adminPass)
35+
await page.locator('#kc-login').click()
36+
await expect(page.getByRole('link', { name: 'Logo' })).toBeVisible()
37+
}

playwright/e2e-tests/admin-stages.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { faker } from '@faker-js/faker'
22
import { expect, test } from '@playwright/test'
3+
import { adminUser, clientURL, signInCloudPiNative, testUser } from '../config/console'
34

45
import {
56
addProject,
6-
adminUser,
7-
clientURL,
87
createStage,
98
deleteStage,
10-
signInCloudPiNative,
11-
testUser,
129
} from './utils'
1310

1411
test.describe('Stages administration page', { tag: '@e2e' }, () => {

playwright/e2e-tests/clusters.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { faker } from '@faker-js/faker'
22
import { expect, test } from '@playwright/test'
3+
import { adminUser, clientURL, signInCloudPiNative } from '../config/console'
34

45
import {
56
addProject,
6-
adminUser,
7-
clientURL,
87
createCluster,
98
deleteCluster,
10-
signInCloudPiNative,
119
} from './utils'
1210

1311
test.describe('Clusters page', () => {

playwright/e2e-tests/environments.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { faker } from '@faker-js/faker'
22
import { expect, test } from '@playwright/test'
3-
43
import {
5-
addEnvToProject,
6-
addProject,
74
adminUser,
85
clientURL,
96
cnolletUser,
107
signInCloudPiNative,
11-
removeEnvFromProject,
128
testUser,
9+
} from '../config/console'
10+
11+
import {
12+
addEnvToProject,
13+
addProject,
14+
removeEnvFromProject,
1315
} from './utils'
1416

1517
test.describe('Environments page', { tag: '@e2e' }, () => {

playwright/e2e-tests/keycloak.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Page } from '@playwright/test'
22
import { test, expect } from '@playwright/test'
33
import { faker } from '@faker-js/faker'
4-
import { loadKeycloakConfig } from '../config/keycloak'
4+
import { loadKeycloakConfig, signInKeycloak } from '../config/keycloak'
55

66
const keycloakConfig = loadKeycloakConfig()
77
const usersToDelete: string[] = []
@@ -34,11 +34,7 @@ export async function createGroup(page: Page, groupsToDelete: string[]) {
3434

3535
test.describe('Keycloak', () => {
3636
test.beforeEach({ tag: ['@e2e', '@integ'] }, async ({ page }) => {
37-
await page.goto(keycloakConfig.url)
38-
await page.locator('#username').fill(keycloakConfig.adminUser)
39-
await page.locator('#password').fill(keycloakConfig.adminPass)
40-
await page.locator('#kc-login').click()
41-
await expect(page.getByRole('link', { name: 'Logo' })).toBeVisible()
37+
await signInKeycloak(page)
4238
})
4339

4440
test('should sign in to master realm', { tag: ['@e2e', '@integ'] }, async ({ page }) => {

playwright/e2e-tests/projects.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { Page } from '@playwright/test'
22
import { expect, test } from '@playwright/test'
33
import { faker } from '@faker-js/faker'
4-
import { addProject, clientURL, cnolletUser, signInCloudPiNative, testUser } from './utils'
4+
import { clientURL, cnolletUser, signInCloudPiNative, testUser } from '../config/console'
5+
import { addProject } from './utils'
56

67
// Assuming we are on a given Project page, add a random repository with given name, or a generated one
78
async function addRandomRepositoryToProject({

playwright/e2e-tests/service-chains.spec.ts

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

3-
import type { Credentials } from './utils'
4-
import { adminUser, clientURL, signInCloudPiNative } from './utils'
3+
import { adminUser, clientURL, signInCloudPiNative } from '../config/console'
54

65
test.describe('Service Chains page', () => {
76
test.describe('Given an Admin-level user', () => {

playwright/e2e-tests/utils.ts

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,12 @@ import { faker } from '@faker-js/faker'
22
import type { Page } from '@playwright/test'
33
import { expect } from '@playwright/test'
44

5-
// Retrieve frontend URL from environment variables (see playwright.config.ts)
6-
export const clientURL = process.env.KEYCLOAK_REDIRECT_URI || 'http://change-me'
7-
8-
export interface Credentials {
9-
username: string
10-
password: string
11-
email: string
12-
}
13-
14-
// Users referenced in Keycloak dev realm (../keycloak/realms/realm-dev.json)
15-
export const adminUser: Credentials = {
16-
username: 'admin',
17-
password: 'admin',
18-
19-
}
20-
export const testUser: Credentials = {
21-
username: 'test',
22-
password: 'test',
23-
24-
}
25-
export const cnolletUser: Credentials = {
26-
username: 'cnollet',
27-
password: 'test',
28-
29-
}
30-
315
interface Resources {
326
cpu: number
337
gpu: number
348
memory: number
359
}
3610

37-
export async function signInCloudPiNative({
38-
page,
39-
credentials,
40-
}: {
41-
page: Page
42-
credentials: Credentials
43-
}) {
44-
const { username, password } = credentials
45-
await page.getByRole('link', { name: 'Se connecter' }).click()
46-
await page.getByRole('textbox', { name: 'Username or email' }).fill(username)
47-
await page.getByRole('textbox', { name: 'Password' }).fill(password)
48-
await page.getByRole('button', { name: 'Sign In' }).click()
49-
await expect(page.locator('#top')).toContainText('Cloud π Native')
50-
}
51-
5211
// Assuming we are on the Home page, create a random project with given name, or a generated one
5312
export async function addProject({
5413
page,

0 commit comments

Comments
 (0)