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 Mar 21, 2024
1 parent 0ed565f commit cd48a03
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 @@ -995,11 +995,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 @@ -1009,9 +1011,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');

Check warning on line 1015 in src/Selenium2Driver.php

View check run for this annotation

Codecov / codecov/patch

src/Selenium2Driver.php#L1014-L1015

Added lines #L1014 - L1015 were not covered by tests
\assert($window instanceof Window);
$window->maximize();
});
}

Check warning on line 1019 in src/Selenium2Driver.php

View check run for this annotation

Codecov / codecov/patch

src/Selenium2Driver.php#L1017-L1019

Added lines #L1017 - L1019 were not covered by tests

private function withWindow(?string $name, callable $callback)

Check failure on line 1021 in src/Selenium2Driver.php

View workflow job for this annotation

GitHub Actions / Static analysis

Method Behat\Mink\Driver\Selenium2Driver::withWindow() has no return type specified.
{
if ($name === null) {
$callback();

return;
}

$origName = $this->getWindowName();

Check warning on line 1029 in src/Selenium2Driver.php

View check run for this annotation

Codecov / codecov/patch

src/Selenium2Driver.php#L1029

Added line #L1029 was not covered by tests

try {
if ($origName !== $name) {
$this->switchToWindow($name);

Check warning on line 1033 in src/Selenium2Driver.php

View check run for this annotation

Codecov / codecov/patch

src/Selenium2Driver.php#L1032-L1033

Added lines #L1032 - L1033 were not covered by tests
}

$callback();
} finally {
if ($origName !== $name) {
$this->switchToWindow($origName);

Check warning on line 1039 in src/Selenium2Driver.php

View check run for this annotation

Codecov / codecov/patch

src/Selenium2Driver.php#L1036-L1039

Added lines #L1036 - L1039 were not covered by tests
}
}
}

/**
Expand Down

0 comments on commit cd48a03

Please sign in to comment.