question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Can we have a good example showing how to work with the Electron menu.

See original GitHub issue

Hi. I’m giving a try to PlayWright to drive my Electron application in my E2E tests. I’m trying hard to find a way to handle the menu of my Electron application to open what should be a configuration popup window. But actually I can’t manage to access and click the menu item to eventually access the configuration dialog window this menu is opening.

I’ve try something like this…

    it('should have access to the menu', async () => {
      await appElectron.evaluate( async ({Menu}) => {
        const menu = Menu.getApplicationMenu();
        console.log('menu items count:', menu.items.length);
        const configMenu = menu.items[6].click();
        configMenu.click();
        const userConfigMenu = configMenu.getMenuItemById('User Config');
        userConfigMenu.click();
      });

      const popup = await appElectron.evaluateHandle((async ({BrowserWindow}) => {
        return BrowserWindow.getFocusedWindow();
      }));

      const title = await popup.evaluateHandle((configPopup) => {
        return configPopup.getTitle();
      });
      console.log('Popup title:', title);
      expect(title).toBeTruthy();
    });

… but this doesn’t work.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
atalicommented, Jan 29, 2021

I was able to click on a sub menu item by doing the following :

            id: 'File',
            label: 'File',
            submenu: [
                {
                    id: 'Save',
                    label: 'Save',
                    click: () => {
                        this.Save();
                    }
                },

The test file:

        await app.evaluate(async ({app, Menu}) => {
            const fileMenuItem = app.applicationMenu.getMenuItemById('File');
            const saveMenuItem = fileMenuItem.submenu.getMenuItemById('Save');

            saveMenuItem.click()
        });
4reactions
pavelfeldmancommented, Jun 18, 2020

Let me actually bake it into Playwright - it looks useful…

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Complete Electron JS Menu Tutorial (Top Menus, Context ...
Nearly every desktop application you make will need menus. In this detailed tutorial I will show you how to design your menus properly...
Read more >
Building desktop applications with Electron - Menu - Medium
There are two kinds of menus in Electron applications, the first one is an application menu and second one is a context menu...
Read more >
Chapter 7. Building application and context menus - Electron ...
This chapter covers. Creating menus using Electron's Menu and MenuItem modules; Building menus from a template; Defining custom menus for target operating ...
Read more >
Electron - Menus - Tutorialspoint
Electron - Menus, The desktop apps come with two types of menus – the application menu(on the top bar) and a context menu(right-click...
Read more >
Menu | Electron
Also on Windows and Linux, you can use a & in the top-level item name to indicate which letter should get a generated...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found