Playwright basic utils (#7930)

Related to #6641
This commit is contained in:
BOHEUS 2024-11-07 14:34:53 +00:00 committed by GitHub
parent 4f2b055ee0
commit c3343d3600
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 145 additions and 0 deletions

View File

@ -0,0 +1,22 @@
import * as fs from 'fs';
import path from 'path';
export const envVariables = (variables: string) => {
let payload = `
PG_DATABASE_URL=postgres://twenty:twenty@localhost:5432/default
FRONT_BASE_URL=http://localhost:3001
ACCESS_TOKEN_SECRET=replace_me_with_a_random_string_access
LOGIN_TOKEN_SECRET=replace_me_with_a_random_string_login
REFRESH_TOKEN_SECRET=replace_me_with_a_random_string_refresh
FILE_TOKEN_SECRET=replace_me_with_a_random_string_refresh
REDIS_URL=redis://localhost:6379
`;
payload = payload.concat(variables);
fs.writeFile(
path.join(__dirname, '..', '..', 'twenty-server', '.env'),
payload,
(err) => {
throw err;
},
);
};

View File

@ -0,0 +1,94 @@
import { Page } from '@playwright/test';
const MAC = process.platform === 'darwin';
async function keyDownCtrlOrMeta(page: Page) {
if (MAC) {
await page.keyboard.down('Meta');
} else {
await page.keyboard.down('Control');
}
}
async function keyUpCtrlOrMeta(page: Page) {
if (MAC) {
await page.keyboard.up('Meta');
} else {
await page.keyboard.up('Control');
}
}
export async function withCtrlOrMeta(page: Page, key: () => Promise<void>) {
await keyDownCtrlOrMeta(page);
await key();
await keyUpCtrlOrMeta(page);
}
export async function selectAllByKeyboard(page: Page) {
await keyDownCtrlOrMeta(page);
await page.keyboard.press('a', { delay: 50 });
await keyUpCtrlOrMeta(page);
}
export async function copyByKeyboard(page: Page) {
await keyDownCtrlOrMeta(page);
await page.keyboard.press('c', { delay: 50 });
await keyUpCtrlOrMeta(page);
}
export async function cutByKeyboard(page: Page) {
await keyDownCtrlOrMeta(page);
await page.keyboard.press('x', { delay: 50 });
await keyUpCtrlOrMeta(page);
}
export async function pasteByKeyboard(page: Page) {
await keyDownCtrlOrMeta(page);
await page.keyboard.press('v', { delay: 50 });
await keyUpCtrlOrMeta(page);
}
export async function companiesShortcut(page: Page) {
await page.keyboard.press('g', { delay: 50 });
await page.keyboard.press('c');
}
export async function notesShortcut(page: Page) {
await page.keyboard.press('g', { delay: 50 });
await page.keyboard.press('n');
}
export async function opportunitiesShortcut(page: Page) {
await page.keyboard.press('g', { delay: 50 });
await page.keyboard.press('o');
}
export async function peopleShortcut(page: Page) {
await page.keyboard.press('g', { delay: 50 });
await page.keyboard.press('p');
}
export async function rocketsShortcut(page: Page) {
await page.keyboard.press('g', { delay: 50 });
await page.keyboard.press('r');
}
export async function tasksShortcut(page: Page) {
await page.keyboard.press('g', { delay: 50 });
await page.keyboard.press('t');
}
export async function workflowsShortcut(page: Page) {
await page.keyboard.press('g', { delay: 50 });
await page.keyboard.press('w');
}
export async function settingsShortcut(page: Page) {
await page.keyboard.press('g', { delay: 50 });
await page.keyboard.press('s');
}
export async function customShortcut(page: Page, shortcut: string) {
await page.keyboard.press('g', { delay: 50 });
await page.keyboard.press(shortcut);
}

View File

@ -0,0 +1,14 @@
import { Locator, Page } from '@playwright/test';
import { selectAllByKeyboard } from './keyboardShortcuts';
// https://github.com/microsoft/playwright/issues/14126
// code must have \n at the end of lines otherwise everything will be in one line
export const pasteCodeToCodeEditor = async (
page: Page,
locator: Locator,
code: string,
) => {
await locator.click();
await selectAllByKeyboard(page);
await page.keyboard.type(code);
};

View File

@ -0,0 +1,15 @@
import { Page } from '@playwright/test';
import path from 'path';
export const fileUploader = async (
page: Page,
trigger: () => Promise<void>,
filename: string,
) => {
const fileChooserPromise = page.waitForEvent('filechooser');
await trigger();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(
path.join(__dirname, '..', 'test_files', filename),
);
};