Keycloak
91 строка · 2.8 Кб
1import { expect, test } from "@playwright/test";
2import { getRootPath } from "../src/utils/getRootPath";
3import { login } from "./login";
4import { getAccountUrl, getAdminUrl } from "./utils";
5
6test.describe("Applications test", () => {
7test.beforeEach(async ({ page }) => {
8// Sign out all devices before each test
9await login(page, "admin", "admin");
10await page.getByTestId("accountSecurity").click();
11await page.getByTestId("account-security/device-activity").click();
12
13await page
14.getByRole("button", { name: "Sign out all devices", exact: true })
15.click();
16await page.getByRole("button", { name: "Confirm" }).click();
17
18await expect(
19page.getByRole("heading", { name: "Sign in to your account" }),
20).toBeVisible();
21});
22
23test("Single application", async ({ page }) => {
24await login(page, "admin", "admin");
25
26await page.getByTestId("applications").click();
27
28await expect(page.getByTestId("applications-list-item")).toHaveCount(1);
29await expect(page.getByTestId("applications-list-item")).toContainText(
30process.env.CI ? "Account Console" : "security-admin-console-v2",
31);
32});
33
34test("Single application twice", async ({ browser }) => {
35const context1 = await browser.newContext({
36userAgent:
37"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)",
38});
39const context2 = await browser.newContext();
40try {
41const page1 = await context1.newPage();
42const page2 = await context2.newPage();
43
44await login(page1, "admin", "admin");
45await login(page2, "admin", "admin");
46
47await page1.getByTestId("applications").click();
48
49await expect(page1.getByTestId("applications-list-item")).toHaveCount(1);
50await expect(
51page1.getByTestId("applications-list-item").nth(0),
52).toContainText(
53process.env.CI ? "Account Console" : "security-admin-console-v2",
54);
55} finally {
56await context1.close();
57await context2.close();
58}
59});
60
61test("Two applications", async ({ page }) => {
62test.skip(
63!process.env.CI,
64"Skip this test if not running with regular Keycloak",
65);
66
67await login(page, "admin", "admin");
68
69// go to admin console
70await page.goto("/");
71await expect(page).toHaveURL(getAdminUrl());
72await page.waitForURL(getAdminUrl());
73
74await page.goto(getRootPath());
75await page.waitForURL(getAccountUrl());
76
77await page.getByTestId("applications").click();
78
79await expect(page.getByTestId("applications-list-item")).toHaveCount(2);
80await expect(
81page
82.getByTestId("applications-list-item")
83.filter({ hasText: "Account Console" }),
84).toBeVisible();
85await expect(
86page
87.getByTestId("applications-list-item")
88.filter({ hasText: "security-admin-console" }),
89).toBeVisible();
90});
91});
92