mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 01:40:15 +01:00
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
|
|
import {Page, FullConfig, chromium} from '@playwright/test';
|
||
|
|
|
||
|
|
type User = {username: string; password: string};
|
||
|
|
|
||
|
|
async function login(page: Page, user: User) {
|
||
|
|
await page.locator('input[name="email"]').fill(user.username);
|
||
|
|
await page.locator('input[name="password"]').fill(user.password);
|
||
|
|
await page.locator('button[type="submit"]').click();
|
||
|
|
}
|
||
|
|
|
||
|
|
async function authenticate(config: FullConfig, user: User) {
|
||
|
|
console.log('🤖: global setup has been started');
|
||
|
|
const {baseURL, storageState} = config.projects[0].use;
|
||
|
|
console.log('🤖: using baseURL', baseURL);
|
||
|
|
const browser = await chromium.launch();
|
||
|
|
const page = await browser.newPage();
|
||
|
|
console.log('🤖: 🗝 authenticating user:', user.username);
|
||
|
|
await page.goto(baseURL);
|
||
|
|
await login(page, user);
|
||
|
|
await page.locator('h1:has-text("LibreChat")').waitFor();
|
||
|
|
console.log('🤖: ✔️ user successfully authenticated');
|
||
|
|
await page.context().storageState({path: storageState as string});
|
||
|
|
console.log('🤖: ✔️ authentication state successfully saved in', storageState);
|
||
|
|
await browser.close();
|
||
|
|
console.log('🤖: global setup has been finished');
|
||
|
|
}
|
||
|
|
|
||
|
|
export default authenticate;
|