-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal-setup.ts
40 lines (37 loc) · 1.29 KB
/
global-setup.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
import { FullConfig, firefox } from "@playwright/test";
async function globalSetup(config: FullConfig): Promise<void> {
if (config.projects[0] === undefined) return;
const { baseURL, storageState } = config.projects[0].use;
if (baseURL !== undefined) {
const browser = await firefox.launch({ headless: false });
const context = await browser.newContext({
viewport: {
height: 1080,
width: 1920,
},
recordVideo: {
dir: "playwright-report/",
size: {
height: 1080,
width: 1920,
},
},
});
try {
const page = await context.newPage();
page.video();
await page.goto(baseURL);
await page.getByRole("button", { name: "Se connecter" }).click({ delay: 2000 });
await page.getByRole("button", { name: "Se connecter avec Spotify" }).click({ delay: 1000 });
await page.getByTestId("login-username").fill(process.env.USERNAME);
await page.getByTestId("login-password").fill(process.env.PASSWORD);
await page.getByTestId("login-button").dblclick({ delay: 2000 });
await context.storageState({ path: storageState as string });
await browser.close();
} catch (err: unknown) {
await browser.close();
throw err;
}
}
}
export default globalSetup;