2023-07-07 14:34:54 +00:00
|
|
|
import { Page } from "@playwright/test";
|
2024-03-04 12:38:28 +00:00
|
|
|
import { DEFAULT_REALM } from "../src/constants";
|
|
|
|
import { getRootPath } from "../src/utils/getRootPath";
|
2023-07-07 14:34:54 +00:00
|
|
|
|
2023-08-18 12:18:28 +00:00
|
|
|
export const login = async (
|
|
|
|
page: Page,
|
|
|
|
username: string,
|
|
|
|
password: string,
|
2024-03-04 12:38:28 +00:00
|
|
|
realm = DEFAULT_REALM,
|
2024-03-22 13:02:50 +00:00
|
|
|
queryParams?: Record<string, string>,
|
2023-08-18 12:18:28 +00:00
|
|
|
) => {
|
2024-03-22 13:02:50 +00:00
|
|
|
const rootPath =
|
|
|
|
getRootPath(realm) +
|
|
|
|
(queryParams ? "?" + new URLSearchParams(queryParams) : "");
|
2024-03-04 12:38:28 +00:00
|
|
|
|
|
|
|
await page.goto(rootPath);
|
2023-08-14 14:41:58 +00:00
|
|
|
await page.getByLabel("Username").fill(username);
|
2023-09-19 12:29:05 +00:00
|
|
|
await page.getByLabel("Password", { exact: true }).fill(password);
|
2023-07-07 14:34:54 +00:00
|
|
|
await page.getByRole("button", { name: "Sign In" }).click();
|
|
|
|
};
|