From 32704591f1036e5cf3664c6a161d7933c97e93f0 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 8 Apr 2024 21:20:18 +0300 Subject: [PATCH] Rewritten implementation to window handles directly (avoids name-to-handle conversion code) --- src/WebdriverClassicDriver.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/WebdriverClassicDriver.php b/src/WebdriverClassicDriver.php index d1d66ff..31357bd 100644 --- a/src/WebdriverClassicDriver.php +++ b/src/WebdriverClassicDriver.php @@ -136,17 +136,18 @@ public function stop(): void */ public function reset(): void { - // switch to default window.. - $this->switchToWindow(); - $actualInitialWindowName = $this->getWindowName(); // Account for initial window rename. $webDriver = $this->getWebDriver(); + // switch to default window.. + $initialWindow = substr((string)$this->initialWindowName, strlen(self::W3C_WINDOW_HANDLE_PREFIX)); + $webDriver->switchTo()->window($initialWindow); + // ..and close all other windows - foreach ($this->getWindowNames() as $name) { - if ($name !== $actualInitialWindowName) { - $this->switchToWindow($name); + foreach ($webDriver->getWindowHandles() as $tempWindow) { + if ($tempWindow !== $initialWindow) { + $webDriver->switchTo()->window($tempWindow); $webDriver->close(); - $this->switchToWindow(); + $webDriver->switchTo()->window($initialWindow); } }