Skip to content

Commit

Permalink
Rewritten implementation to window handles directly (avoids name-to-h…
Browse files Browse the repository at this point in the history
…andle conversion code)
  • Loading branch information
aik099 committed Apr 8, 2024
1 parent 7d71e14 commit 3270459
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/WebdriverClassicDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 3270459

Please sign in to comment.