From 8943bcd0be21a527d74bcba3fbacff73d46d3017 Mon Sep 17 00:00:00 2001 From: Rortan Date: Sun, 4 Sep 2022 17:21:58 +0200 Subject: [PATCH] feat: test helpers --- e2e/helpers.ts | 29 +++++++++++++++++++++++++++++ playwright.config.ts | 4 ++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 e2e/helpers.ts diff --git a/e2e/helpers.ts b/e2e/helpers.ts new file mode 100644 index 0000000..d23b722 --- /dev/null +++ b/e2e/helpers.ts @@ -0,0 +1,29 @@ +import { ElectronApplication } from '@playwright/test'; + +/** + * Get a given attribute the MenuItem with the given id. + * + * @category Menu + * + * @param electronApp {ElectronApplication} - the Electron application object (from Playwright) + * @param menuId {string} - the id of the MenuItem to retrieve the attribute from + * @param attribute {string} - the attribute to retrieve + * @returns {Promise} + * @fulfil {string} resolves with the attribute value + */ +export default function clickMenuItemById( + electronApp: ElectronApplication, + id: string +): Promise { + return electronApp.evaluate(({ Menu }, menuId) => { + const menu = Menu.getApplicationMenu(); + if (!menu) { + throw new Error('No application menu found'); + } + const menuItem = menu.getMenuItemById(menuId); + if (menuItem) { + return menuItem.click(); + } + throw new Error(`Menu item with id ${menuId} not found`); + }, id); +} diff --git a/playwright.config.ts b/playwright.config.ts index f1dab8d..475d70d 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -12,13 +12,13 @@ import type { PlaywrightTestConfig } from '@playwright/test'; const config: PlaywrightTestConfig = { testDir: './e2e', /* Maximum time one test can run for. */ - timeout: 30 * 3000, + timeout: 10 * 14400, expect: { /** * Maximum time expect() should wait for the condition to be met. * For example in `await expect(locator).toHaveText();` */ - timeout: 5000, + timeout: 3000, }, /* Run tests in files in parallel */ fullyParallel: true,