-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
helpers.ts
47 lines (42 loc) · 1.42 KB
/
helpers.ts
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
41
42
43
44
45
46
47
import type { Frame, Page } from '@playwright/test';
export const getLoadedApp = async (page: Page) => {
await page.waitForSelector('iframe[name="app"]');
const app = page.frame('app')!;
await app.waitForLoadState();
let result = getResultFrame(app);
return {
app,
getResult: () => {
result = getResultFrame(app);
return result;
},
waitForResultUpdate: async (options: { delay?: number; timeout?: number } = {}) => {
result = await getUpdatedResultFrame(app, options);
},
};
};
const getResultFrame = (app: Frame) => app.page().frame('result')!;
const getUpdatedResultFrame = async (
app: Frame,
{ delay = 1000, timeout = 20000 }: { delay?: number; timeout?: number },
) => {
const loaded = new Promise<void>(async (resolve) => {
await app.waitForFunction(
`document.querySelector('#tools-pane-loading').style.display !== 'none'`,
);
await app.waitForFunction(
`document.querySelector('#tools-pane-loading').style.display === 'none'`,
);
await app.waitForTimeout(delay);
resolve();
});
await Promise.race([
Promise.all([loaded, app.click(runButtonSelector)]),
app.waitForTimeout(timeout),
]);
return getResultFrame(app);
};
export const waitForEditorFocus = async (app: Frame, selector = '#editors') => {
await app.waitForFunction(`document.activeElement.closest("${selector}") != null`);
};
export const runButtonSelector = '[alt="Run"]';