Skip to content

[Feature] Access Electron context menu in test #11100

Open
@c3er

Description

@c3er

I didn't found any way to access a context menu that is generated in the renderer process via the Remote module.

The renderer JS under test looks like this:

"use strict"

const remote = require("@electron/remote")

function handleContextMenuEvent() {
    const menu = new remote.Menu()
    if (window.getSelection().toString()) {
        menu.append(
            new remote.MenuItem({
                label: "Copy selection",
                role: "copy",
            })
        )
        menu.popup({
            window: remote.getCurrentWindow(),
        })
    }
}

document.addEventListener("DOMContentLoaded", () => {
    document.getElementById("text-area").innerText = "This is a test"
})

window.addEventListener("contextmenu", handleContextMenuEvent)

Neither Playwright's nor Electron's documentation seems to show any way to access a menu that is not the application main menu.

I assume after my unsuccessful research that this feature is missing. Maybe such a feature is in the responsibility of the Electron team but I only need this for E2E testing.

I made a demo project with this context menu approach.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions