forked from intechstudio/grid-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.js
40 lines (33 loc) · 931 Bytes
/
utility.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { chromium } from "@playwright/test";
export const PAGE_PATH = "http://localhost:5173";
export async function initializeBrowserContext() {
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.addInitScript(() => {
Object.defineProperty(navigator, "serial", {
set: () => undefined,
get: () => undefined,
});
});
return { browser, context, page };
}
export async function closeBrowserContext({ browser, context }) {
if (context) {
await context.close();
}
if (browser) {
await browser.close();
}
}
export async function mockNavigatorSerial(page) {
await page.addInitScript(() => {
Object.defineProperty(navigator, "serial", {
set: () => undefined,
get: () => undefined,
});
});
}
export async function getRandomInt(max) {
return Math.floor(Math.random() * max);
}