From acc2aac772394d60bf89fb8235d9a5707b1ea070 Mon Sep 17 00:00:00 2001 From: Mx Corey Frang Date: Wed, 15 Nov 2023 14:30:14 -0500 Subject: [PATCH] Force browser window focus with a minimize/restore (#26) * Force browser window focus with a minimize/restore * add comment --- src/agent/driver-test-runner.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/agent/driver-test-runner.js b/src/agent/driver-test-runner.js index 3526a7e..c30a114 100644 --- a/src/agent/driver-test-runner.js +++ b/src/agent/driver-test-runner.js @@ -48,6 +48,13 @@ export class DriverTestRunner { async openPage({ url, referencePage }) { await this.log(AgentMessage.OPEN_PAGE, { url }); await this.webDriver.switchTo().defaultContent(); + // Minimizing then restoring the window is recommended to trick the window + // manager on the OS to put focus in the browser. This is needed to + // steal focus away from a terminal/powershell tab if you launch the tests + // locally. + await this.webDriver.manage().window().minimize(); + await this.webDriver.manage().window().setRect({ x: 0, y: 0 }); + await this.webDriver.switchTo().defaultContent(); await this.webDriver.navigate().to(url.toString()); try {