From 2a85993ce574a05d391373307add63c2aaa10e43 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 10 Apr 2024 10:43:55 +0300 Subject: [PATCH] Repair of the "$name" parameter for "resizeWindow" and "maximizeWindow" methods --- src/Selenium2Driver.php | 43 +++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index 36a9353c..b1ae858b 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -992,11 +992,13 @@ public function wait(int $timeout, string $condition) public function resizeWindow(int $width, int $height, ?string $name = null) { - $window = $this->getWebDriverSession()->window($name ?: 'current'); - \assert($window instanceof Window); - $window->postSize( - array('width' => $width, 'height' => $height) - ); + $this->withWindow($name, function () use ($width, $height) { + $window = $this->getWebDriverSession()->window('current'); + \assert($window instanceof Window); + $window->postSize( + array('width' => $width, 'height' => $height) + ); + }); } public function submitForm(string $xpath) @@ -1006,9 +1008,34 @@ public function submitForm(string $xpath) public function maximizeWindow(?string $name = null) { - $window = $this->getWebDriverSession()->window($name ?: 'current'); - \assert($window instanceof Window); - $window->maximize(); + $this->withWindow($name, function () { + $window = $this->getWebDriverSession()->window('current'); + \assert($window instanceof Window); + $window->maximize(); + }); + } + + private function withWindow(?string $name, callable $callback): void + { + if ($name === null) { + $callback(); + + return; + } + + $origName = $this->getWindowName(); + + try { + if ($origName !== $name) { + $this->switchToWindow($name); + } + + $callback(); + } finally { + if ($origName !== $name) { + $this->switchToWindow($origName); + } + } } /**