microsoft / microsoft/playwright
[Feature] Access Electron context menu in test
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 96.3k
- Forks
- 6.5k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 180
Description
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:
```javascript
"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](https://playwright.dev/docs/api/class-playwright) nor [Electron's](https://www.electronjs.org/docs/latest/api/menu) 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](https://github.com/c3er/electron-contextmenu) with this context menu approach.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the renderer JavaScript shown in the issue and the linked Electron context-menu demo, then compare the available Playwright Electron and Electron Menu APIs. Define how an end-to-end test should access a context menu created in the renderer process, and verify that the menu can be observed or interacted with.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- electron, javascript, playwright
- Domain
- desktop, testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100