Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap WebDriver exception about failed to load page into DriverException #39

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/WebdriverClassicDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Behat\Mink\Exception\DriverException;
use Facebook\WebDriver\Exception\NoSuchCookieException;
use Facebook\WebDriver\Exception\NoSuchElementException;
use Facebook\WebDriver\Exception\ScriptTimeoutException;
use Facebook\WebDriver\Exception\TimeoutException;
use Facebook\WebDriver\Exception\UnsupportedOperationException;
use Facebook\WebDriver\Exception\WebDriverException;
use Facebook\WebDriver\Remote\DesiredCapabilities;
Expand Down Expand Up @@ -155,7 +157,11 @@ public function reset(): void

public function visit(string $url): void
{
$this->getWebDriver()->navigate()->to($url);
try {
$this->getWebDriver()->navigate()->to($url);
} catch (TimeoutException|ScriptTimeoutException $e) {
throw new DriverException('Page failed to load: ' . $e->getMessage(), 0, $e);
}
}

public function getCurrentUrl(): string
Expand Down
14 changes: 14 additions & 0 deletions tests/Custom/TimeoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function testInvalidTimeoutSettingThrowsException(): void
assert($driver instanceof WebdriverClassicDriver);

$this->expectException(DriverException::class);
$this->expectExceptionMessage('Invalid timeout type: invalid');

$driver->setTimeouts(['invalid' => 0]);
}
Expand Down Expand Up @@ -64,4 +65,17 @@ public function testLongTimeoutWaitsForElementToAppear(): void

$this->assertNotNull($element);
}

public function testShortPageLoadTimeoutThrowsException(): void
{
$session = $this->getSession();
$driver = $session->getDriver();
\assert($driver instanceof WebdriverClassicDriver);

$driver->setTimeouts(['page' => 500]);

$this->expectException(DriverException::class);
$this->expectExceptionMessage('Page failed to load: ');
$session->visit($this->pathTo('/page_load.php?sleep=2'));
}
}
Loading