Skip to content

Commit

Permalink
Repair of the "$name" parameter for "resizeWindow" and "maximizeWindo…
Browse files Browse the repository at this point in the history
…w" methods
  • Loading branch information
aik099 committed Apr 10, 2024
1 parent e510284 commit 2a85993
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
}
}

/**
Expand Down

0 comments on commit 2a85993

Please sign in to comment.