Skip to content

Commit

Permalink
Force browser window focus with a minimize/restore (#26)
Browse files Browse the repository at this point in the history
* Force browser window focus with a minimize/restore

* add comment
  • Loading branch information
gnarf authored Nov 15, 2023
1 parent 93249de commit acc2aac
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/agent/driver-test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit acc2aac

Please sign in to comment.