Skip to content

Commit e3f04b9

Browse files
authored
Merge pull request #82 from element-hq/rav/new_context
Playwright: add a `createNewInstance` utility function
2 parents 1215925 + 970deaf commit e3f04b9

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

packages/element-web-playwright-common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { test as base } from "./fixtures/index.js";
1212
import { routeConfigJson } from "./utils/config_json.js";
1313

1414
export * from "./utils/config_json.js";
15+
export * from "./utils/context.js";
1516

1617
export { populateLocalStorageWithCredentials } from "./fixtures/user.js";
1718

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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

Comments
 (0)