node.jsautomated-testselectronspectron

Spectron: how to test Electron `shell.openExternal('some url')`


I'm writing and E2E test for an application written in Electron. I need to test a button which calls in effect shell.openExternal('link') where link is an external website. I've been looking in the webdriver docs for something which allows the test intercept this call, but it doesn't look like anything like that exists in the API at all.

1) if something like this does exist an I missed it in the docs, please enlighten me in ways of the light side of the force,

2) if not, then does anyone out there in stackoverflow land have a fancy work-around?

Thanks so much!


Solution

  • I came up with an answer. Instead of trying to intercept the click, I added an env var in the main app such that when set, the click will put an entry into the log instead of actually opening the external link in a browser. Then I use the API in spectron to slurp up the render process logs: https://github.com/electron-userland/spectron#clientgetrenderprocesslogs Then I can just look for a custom string in the logs and I can judge the proper text is present.