electron-playwright-helpers
Version:
Helper functions for Electron end-to-end testing using Playwright
143 lines • 7.08 kB
TypeScript
import type { ElectronApplication } from 'playwright-core';
/**
* Execute the `.click()` method on the element with the given id.
* **NOTE:** All menu testing functions will only work with items in the
* [application menu](https://www.electronjs.org/docs/latest/api/menu#menusetapplicationmenumenu).
*
* @category Menu
*
* @param electronApp {ElectronApplication} - the Electron application object (from Playwright)
* @param id {string} - the id of the MenuItem to click
* @returns {Promise<void>}
* @fulfil {void} resolves with the result of the `click()` method - probably `undefined`
*/
export declare function clickMenuItemById(electronApp: ElectronApplication, id: string): Promise<unknown>;
/**
* Click the first matching menu item by any of its properties. This is
* useful for menu items that don't have an id. HOWEVER, this is not as fast
* or reliable as using `clickMenuItemById()` if the menu item has an id.
*
* **NOTE:** All menu testing functions will only work with items in the
* [application menu](https://www.electronjs.org/docs/latest/api/menu#menusetapplicationmenumenu).
*
* @category Menu
*
* @param electronApp {ElectronApplication} - the Electron application object (from Playwright)
* @param property {String} - a property of the MenuItem to search for
* @param value {String | Number | Boolean} - the value of the property to search for
* @returns {Promise<void>}
* @fulfil {void} resolves with the result of the `click()` method - probably `undefined`
*/
export declare function clickMenuItem<P extends keyof MenuItemPartial>(electronApp: ElectronApplication, property: P, value: MenuItemPartial[P]): Promise<unknown>;
/**
* 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<string>}
* @fulfil {string} resolves with the attribute value
*/
export declare function getMenuItemAttribute<T extends keyof Electron.MenuItem>(electronApp: ElectronApplication, menuId: string, attribute: T): Promise<Electron.MenuItem[T]>;
/** Serializable value types that can be safely transferred via Playwright */
type SerializableValue = string | number | boolean | null | undefined | object | SerializableValue[] | {
[key: string]: SerializableValue;
};
/** Serialized representation of an Electron.NativeImage converted successfully */
export type SerializedNativeImageSuccess = {
type: 'NativeImage';
dataURL: string;
size: {
width: number;
height: number;
};
isEmpty: boolean;
};
/** Serialized representation of an Electron.NativeImage converted with an error */
export type SerializedNativeImageError = {
type: 'NativeImage';
error: string;
};
/** Serialized representation of an Electron.NativeImage */
export type SerializedNativeImage = SerializedNativeImageSuccess | SerializedNativeImageError;
/** Type guard to check if a SerializedNativeImage is a success case */
export declare function isSerializedNativeImageSuccess(image: SerializedNativeImage): image is SerializedNativeImageSuccess;
/** Type guard to check if a SerializedNativeImage is an error case */
export declare function isSerializedNativeImageError(image: SerializedNativeImage): image is SerializedNativeImageError;
/**
* A MenuItemConstructorOptions-like Electron MenuItem
* containing serializable values (primitives, objects, arrays) but no circular references
*/
export type MenuItemPartial = {
-readonly [K in keyof Electron.MenuItem]?: K extends 'icon' ? SerializedNativeImage | undefined : Electron.MenuItem[K] extends SerializableValue ? Electron.MenuItem[K] : SerializableValue;
} & {
submenu?: MenuItemPartial[];
};
/**
* Get information about the MenuItem with the given id. Returns serializable values including
* primitives, objects, arrays, and other non-recursive data structures.
*
* @category Menu
*
* @param electronApp {ElectronApplication} - the Electron application object (from Playwright)
* @param menuId {string} - the id of the MenuItem to retrieve
* @returns {Promise<MenuItemPartial>}
* @fulfil {MenuItemPartial} the MenuItem with the given id
*/
export declare function getMenuItemById(electronApp: ElectronApplication, menuId: string): Promise<MenuItemPartial>;
/**
* Get the current state of the application menu. Contains serializable values including
* primitives, objects, arrays, and other non-recursive data structures.
* Very similar to menu
* [construction template structure](https://www.electronjs.org/docs/latest/api/menu#examples)
* in Electron.
*
* @category Menu
*
* @param electronApp {ElectronApplication} - the Electron application object (from Playwright)
* @returns {Promise<MenuItemPartial[]>}
* @fulfil {MenuItemPartial[]} an array of MenuItem-like objects
*/
export declare function getApplicationMenu(electronApp: ElectronApplication): Promise<MenuItemPartial[]>;
/**
* Find a MenuItem by any of its properties
*
* @category Menu
*
* @param electronApp {ElectronApplication} - the Electron application object (from Playwright)
* @param property {string} - the property to search for
* @param value {string} - the value to search for
* @param menuItems {MenuItemPartial | MenuItemPartial[]} optional - single MenuItem or array - if not provided, will be retrieved from the application menu
* @returns {Promise<MenuItemPartial>}
* @fulfil {MenuItemPartial} the first MenuItem with the given property and value
*/
export declare function findMenuItem<P extends keyof MenuItemPartial>(electronApp: ElectronApplication, property: P, value: MenuItemPartial[P], menuItems?: MenuItemPartial | MenuItemPartial[]): Promise<MenuItemPartial | undefined>;
/**
* Wait for a MenuItem to exist
*
* @category Menu
*
* @param electronApp {ElectronApplication} - the Electron application object (from Playwright)
* @param id {string} - the id of the MenuItem to wait for
* @returns {Promise<void>}
* @fulfil {void} resolves when the MenuItem is found
*/
export declare function waitForMenuItem(electronApp: ElectronApplication, id: string): Promise<void>;
/**
* Wait for a MenuItem to have a specific attribute value.
* For example, wait for a MenuItem to be enabled... or be visible.. etc
*
* @category Menu
*
* @param electronApp {ElectronApplication} - the Electron application object (from Playwright)
* @param id {string} - the id of the MenuItem to wait for
* @param property {string} - the property to search for
* @param value {string | number | boolean} - the value to search for
* @returns {Promise<void>}
* @fulfil {void} resolves when the MenuItem with correct status is found
*/
export declare function waitForMenuItemStatus<P extends keyof Electron.MenuItem>(electronApp: ElectronApplication, id: string, property: P, value: Electron.MenuItem[P]): Promise<void>;
export {};
//# sourceMappingURL=menu_helpers.d.ts.map