|
| 1 | +/* |
| 2 | +Copyright 2025 New Vector Ltd. |
| 3 | +
|
| 4 | +SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial |
| 5 | +Please see LICENSE files in the repository root for full details. |
| 6 | +*/ |
| 7 | + |
| 8 | +import { Browser } from "playwright-core"; |
| 9 | +import { Page } from "@playwright/test"; |
| 10 | + |
| 11 | +import { Credentials } from "./api.js"; |
| 12 | +import { Config } from "../index.js"; |
| 13 | +import { routeConfigJson } from "./config_json.js"; |
| 14 | +import { populateLocalStorageWithCredentials } from "../fixtures/user.js"; |
| 15 | + |
| 16 | +/** Create a new instance of the application, in a separate browser context, using the given credentials. |
| 17 | + * |
| 18 | + * @param browser - the browser to use |
| 19 | + * @param credentials - the credentials to use for the new instance |
| 20 | + * @param additionalConfig - additional config for the `config.json` for the new instance |
| 21 | + * @param labsFlags - additional labs flags for the `config.json` for the new instance |
| 22 | + * @param disablePresence - whether to disable presence for the new instance |
| 23 | + */ |
| 24 | +export async function createNewInstance( |
| 25 | + browser: Browser, |
| 26 | + credentials: Credentials, |
| 27 | + additionalConfig: Partial<Config> = {}, |
| 28 | + labsFlags: string[] = [], |
| 29 | + disablePresence: boolean = false, |
| 30 | +): Promise<Page> { |
| 31 | + const context = await browser.newContext(); |
| 32 | + await routeConfigJson(context, credentials.homeserverBaseUrl, additionalConfig, labsFlags, disablePresence); |
| 33 | + const page = await context.newPage(); |
| 34 | + await populateLocalStorageWithCredentials(page, credentials); |
| 35 | + await page.goto("/"); |
| 36 | + await page.waitForSelector(".mx_MatrixChat", { timeout: 30000 }); |
| 37 | + return page; |
| 38 | +} |
0 commit comments