-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string>} | ||
* @fulfil {string} resolves with the attribute value | ||
*/ | ||
export default function clickMenuItemById( | ||
electronApp: ElectronApplication, | ||
id: string | ||
): Promise<unknown> { | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters