Closed SimonDanisch closed 4 years ago
I think that needs to be run in the Main process, not in the browser process, right?
So you would send the javascript to the app, not the window. And then use something like this to get access to the window and webcontents.
I see... Yeah I'm still not sure how things are layered... Trying to figure out how to best do web ui testing! Maybe integrating https://github.com/electron-userland/spectron would be a good idea!
Ok, nevermind... I can just trigger events with pure JS, without any deeper browser integration:
function trigger_keyboard_press(key){
var down = new KeyboardEvent('keydown', {key: key, code: key});
var up = new KeyboardEvent('keyup', {key: key, code: key});
document.dispatchEvent(down);
document.dispatchEvent(up)
}
I thought something like this doesn't work, since nothing happened when I first tried it, but that was just due to all sorts of subtleties in how to trigger the events ;)
Btw, I incorperated this function in ElectronTests.jl and plan to add more functionality like this ;)
I found the following snippet
window.webContents.sendInputEvent({type: 'mouseMove', x: 10, y: 10})
, but I'm not sure how I can run this code in an electron window.. It seems like the eval context for the JS that gets sent to Electron doesn't have the references to e.g. the window...